mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-17 19:26:20 +00:00
32 lines
657 B
JavaScript
32 lines
657 B
JavaScript
const { Client } = require('./src')
|
|
|
|
const client = new Client({puppeteer: {headless: false}});
|
|
|
|
client.initialize();
|
|
|
|
client.on('qr', (qr) => {
|
|
console.log('QR RECEIVED', qr);
|
|
});
|
|
|
|
client.on('authenticated', () => {
|
|
console.log('AUTHENTICATED');
|
|
});
|
|
|
|
client.on('ready', () => {
|
|
console.log('READY');
|
|
});
|
|
|
|
client.on('message', (msg) => {
|
|
console.log('MESSAGE RECEIVED', msg);
|
|
|
|
if (msg.body == 'ping reply') {
|
|
// Send a new message as a reply to the current one
|
|
msg.reply('pong');
|
|
|
|
} else if (msg.body == 'ping') {
|
|
// Send a new message to the same chat
|
|
client.sendMessage(msg.from, 'pong');
|
|
}
|
|
})
|
|
|