Created
March 20, 2022 17:04
-
-
Save meyer1994/64fd001cbffa006682e588210c2774ce to your computer and use it in GitHub Desktop.
Simple bot for whatsapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const makeWASocket = require('@adiwajshing/baileys').makeWALegacySocket | |
// Chat id | |
const chadtId = 'numbers-morenumbers@g.us' | |
const sock = makeWASocket({ | |
printQRInTerminal: true | |
}) | |
// start | |
sock.ev.on('connection.update', ({ connection, lastDisconnect }) => { | |
if (connection === 'open') | |
console.log('started') | |
}) | |
// ping | |
sock.ev.on('messages.upsert', async m => { | |
console.log(JSON.stringify(m, undefined, 2)) | |
for (const message of m.messages) | |
if (message?.message?.conversation?.toLowerCase() === 'ping') | |
await sock.sendMessage(message.key.remoteJid, { text: 'pong' }, { quoted: message }) | |
}) | |
// sticker | |
sock.ev.on('messages.update', async m => { | |
console.log(JSON.stringify(m, undefined, 2)) | |
for (const { update } of m) { | |
if (update?.key?.remoteJid !== chatId) | |
continue | |
const info = { | |
sticker: fs.readFileSync('sticker.webp'), | |
mimetype: 'image/webp', | |
height: 64, | |
width: 64, | |
} | |
if (update.message === null) | |
await sock.sendMessage(update.key.remoteJid, info) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment