首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Viber Bot发送消息

如何使用Viber Bot发送消息
EN

Stack Overflow用户
提问于 2021-06-28 08:58:18
回答 1查看 514关注 0票数 1

我不能用Viber Bot发送信息。

我试过这样的选择:

代码语言:javascript
复制
const TextMessage = require('viber-bot').Message.Text

viber_bot.sendMessage(req.body.viber_user_id, new TextMessage(req.body.message))

因此,错误

代码语言:javascript
复制
UnhandledPromiseRejectionWarning: Error: Invalid arguments passed to sendMessage. 'optionalReceiver' and 'chatId' are Missing.  

像这样尝试过:

代码语言:javascript
复制
viber_bot.sendMessage({
    "receiver": "<my_id>",
    "type": "text",
    "text": "Hello world!"
}

使用这种方法,没有错误,但也没有消息,它不会来!

P.S.

请注意,其余的机器人工作良好。消息被接受,我可以发送回复。

EN

回答 1

Stack Overflow用户

发布于 2021-06-30 09:33:37

sendMessage()需要UserProfile而不是viber_user_id

以下应起作用:

代码语言:javascript
复制
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);

另外,请注意,有两个实现可能会给您带来问题,这取决于您实际使用的是什么:

  1. ViberClient.prototype.sendMessage =函数(optionalReceiver,messageType,messageData,optionalTrackingData,optionalKeyboard,optionalChatId,optionalMinApiVersion)

)

  1. ViberBot.prototype.sendMessage =函数(optionalUserProfile、messages、optionalTrackingData、optionalChatId)

)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68160427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档