人中使用按钮选项列表回复消息?"/>
如何在 whatsapp web.js 机器人中使用按钮选项列表回复消息?
const { Client, LocalAuth, MessageMedia, Buttons } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal')
const axios = require('axios');
const images = require('./data')
const fs = require('fs');
const WwebjsSender = require('@deathabyss/wwebjs-sender')
const quotes = {
method: 'GET',
url: '/api/quotes'
};
const client = new Client({
authStrategy: new LocalAuth(),
});
client.on('qr', (qr) => {
qrcode.generate(qr, { small: true })
});
client.on('authenticated', () => {
console.log('Authenticated');
});
let chatId = ""
client.on('message', message => {
console.log(message.body);
chatId = message.from;
console.log(chatId);
});
//buttons
client.on("message", (msg) => {
if (msg.body == "!command") {
const from = chatId
console.log(from);
let embed = new WwebjsSender.MessageEmbed()
.sizeEmbed(28)
.setTitle("✅ | Successful process!")
.setDescription("The process has been successful!")
.addField("✔", "To confirm")
.addField("❌", "To cancel")
.addFields({
name: "Now you have 2 buttons",
value: "✔ or ❌",
})
.setFooter('WwebjsSender')
.setTimestamp();
let button1 = new WwebjsSender.MessageButton()
.setCustomId("confirm")
.setLabel("✔")
let button2 = new WwebjsSender.MessageButton()
.setCustomId("cancel")
.setLabel("❌");
try {
WwebjsSender.send({
client: client,
number: from,
embed: embed,
button: [button1, button2]
});
} catch (error) {
console.log(error);
}
}
});
//Listen for incoming messages
client.on('ready', () => {
console.log("Client is ready");
});
client.initialize();
我正在使用 whatsapp-web.js 构建一个机器人。我想发送发送按钮作为回复。 我确认我已通过身份验证。我尝试了很多方法来获取按钮作为回复,但都没有用。 我正在使用@deathabyss/wwebjs-sender 来获取机器人中的按钮。 但我没有收到任何回复或错误。
告诉我一种在 whatsapp-web.js 中发送按钮作为回复的方法?
回答如下:更多推荐
如何在 whatsapp web.js 机器人中使用按钮选项列表回复消息?
发布评论