Send text messages with whatsapp-web.js

To send a text message using the whatsapp-web.js library, you can use the sendMessage function provided by the Chat class. Here's an example code snippet:

const {Client} = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
const express = require('express');

const app = express();
const client = new Client();

client.on('qr', qr => {
    qrcode.generate(qr, {small: true});
});

client.on('ready', () => {
    const phone_no = '62123456789@c.us';
    const message = 'send message';

    client.sendMessage(phone_no, message).then(() => {
        console.log('succeed');
    }).catch((err) => {
        console.log('fail');
    });
});

client.initialize();

app.listen(3000, () => {
  console.log('system is running');
});

Komentar

Postingan populer dari blog ini

WhatsApp Web login QR code in an HTML page using whatsapp-web.js

Node.js Telegram Bot API send an image with text

Add these security headers to your website