我不能用Viber Bot发送信息。
我试过这样的选择:
const TextMessage = require('viber-bot').Message.Text
viber_bot.sendMessage(req.body.viber_user_id, new TextMessage(req.body.message))因此,错误
UnhandledPromiseRejectionWarning: Error: Invalid arguments passed to sendMessage. 'optionalReceiver' and 'chatId' are Missing. 像这样尝试过:
viber_bot.sendMessage({
"receiver": "<my_id>",
"type": "text",
"text": "Hello world!"
}使用这种方法,没有错误,但也没有消息,它不会来!
P.S.
请注意,其余的机器人工作良好。消息被接受,我可以发送回复。
发布于 2021-06-30 09:33:37
sendMessage()需要UserProfile而不是viber_user_id
以下应起作用:
const receiver = "to viber user";
const sampleUserProfile = { id: receiver };
const text = "sample message";
const sampleTrackingData = { value: "sent 1 message" };
const sampleKeyboard = { button: { bgColor: "#FFFFFF" } };
const sampleChatId = "sample chatId";
const sampleMinApiVersion = 2;
const sampleMessage = new TextMessage(text, sampleKeyboard, null, null, null, sampleMinApiVersion);
viber_bot.sendMessage(sampleUserProfile, sampleMessage, sampleTrackingData, sampleChatId);另外,请注意,有两个实现可能会给您带来问题,这取决于您实际使用的是什么:
)
)
https://stackoverflow.com/questions/68160427
复制相似问题