39 lines
898 B
TypeScript
39 lines
898 B
TypeScript
import { Client, LocalAuth } from "whatsapp-web.js";
|
|
import path from "path";
|
|
import qrcode from 'qrcode-terminal';
|
|
|
|
|
|
const client = new Client({
|
|
authStrategy: new LocalAuth(),
|
|
puppeteer: {
|
|
headless: true,
|
|
args: [
|
|
'--no-sandbox',
|
|
'--disable-setuid-sandbox',
|
|
'--disable-dev-shm-usage',
|
|
'--disable-gpu',
|
|
],
|
|
},
|
|
webVersionCache: {
|
|
path: process.env.WWEBJS_CACHE || path.join(process.cwd(), '.wwebjs_cache'),
|
|
type: 'local',
|
|
}
|
|
});
|
|
|
|
client.on('qr', (qr: string) => {
|
|
// Generate and scan this code with your phone
|
|
console.log('QR RECEIVED', qr);
|
|
qrcode.generate(qr, { small: true });
|
|
});
|
|
|
|
client.on('ready', () => {
|
|
console.log('Client is ready!');
|
|
});
|
|
|
|
client.on('message', (msg: any) => {
|
|
if (msg.body == '!ping') {
|
|
msg.reply('pong');
|
|
}
|
|
});
|
|
|
|
client.initialize(); |