wa-minigames
A module that helps you to create minigames with whatsapp-web.js.
Installation
npm install whatsapp-web.js
npm install wa-minigames
Example Usage
const { Client } = require('whatsapp-web.js');
const { Minigames, MiniGame } = require('wa-minigames');
class MyGame extends MiniGame {
constructor(message, client){
super();
this.client = client;
this.chatId = message.getChatId();
this.answer = Math.floor(Math.random() * 100).toString();
this.client.sendMessage(this.chatId, "Game Started! Guess the number!");
}
async procMessage(message){
if (message.body===this.answer){
await this.client.sendMessage(this.chatId, 'You are right!');
this.gameOver();
}else{
await this.client.sendMessage(this.chatId, 'You are wrong.');
}
}
gameOver(){
super.gameOver();
}
}
const client = new Client();
client.on('qr', (qr) => {
console.log('QR RECEIVED', qr);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.on('message', async (msg) => {
if (msg.body == '!start') {
await Minigames.addGameChat(msg.getChatId(), new MyGame(msg, client));
}
Minigames.forwardMessage(msg);
});
client.initialize();