热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在whatsappweb.js中发送whatsapp消息

我正在使用whatsapp-web.js发送和回复消息。我可以使用以下代码连接和回复消息:const{Client}=require(

我正在使用 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);
});

随心所欲地使用它。






推荐阅读
author-avatar
tomorrow
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有