gpt4 book ai didi

javascript - 如何在 whatsapp-web.js 中发送 whatsapp 消息

转载 作者:行者123 更新时间:2023-12-03 23:59:04 34 4
gpt4 key购买 nike

我正在使用 whatsapp-web.js发送和回复消息。 https://github.com/pedroslopez/whatsapp-web.js
我可以使用以下代码连接和回复消息:

const { Client } = require('whatsapp-web.js');
const client = new Client();

client.on('qr', (qr) => {
// Generate and scan this code with your phone
console.log('QR RECEIVED', qr);
});

client.on('ready', () => {
console.log('Client is ready!');
});

client.on('message', msg => {
if (msg.body == '!ping') {
msg.reply('pong');
}
});

client.initialize();
如何在whatsapp中将新消息发送到手机号码?

最佳答案

所以,你想直接使用whatsapp-web.js 向手机号码发送消息
幸运的是,whatsapp-web.js 允许我们这样做。您只需按照说明操作即可。

client.on('ready', () => {
console.log('Client is ready!');

// Number where you want to send the message.
const number = "+911234567890";

// Your message.
const text = "Hey john";

// Getting chatId from the number.
// we have to delete "+" from the beginning and add "@c.us" at the end of the number.
const chatId = number.substring(1) + "@c.us";

// Sending message.
client.sendMessage(chatId, text);
});
随心所欲地使用它。

关于javascript - 如何在 whatsapp-web.js 中发送 whatsapp 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65157125/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com