viber - 使用键盘向 Viber bot 发送“欢迎信息”
问题描述
Viber API 允许发送一些关于conversation_started
事件类型的消息以允许用户订阅。从有关 "welcome message" 的文档中,我看到以下代码,它成功发送了文本和图像:
{
"sender": {
"name": "John McClane",
"avatar": "http://avatar.example.com"
},
"tracking_data": "tracking data",
"type": "text",
"text": "Welcome to our bot!",
"media": "http://www.images.com/img.jpg",
"thumbnail": "http://www.images.com/thumb.jpg"
}
但是如何在那里添加一些按钮?
我希望我的用户能够按他们订阅并开始与我的机器人对话。
我尝试在消息中添加以下内容,但没有成功:
"keyboard": {
"Type": "keyboard",
"DefaultHeight": true,
"Buttons": [{
"ActionType": "reply",
"ActionBody": "reply to me",
"Text": "Key text",
"TextSize": "regular"
}]
}
解决方案
经过一些尝试,我发现不能在同一个“欢迎消息”中同时使用media
+thumbnail
和。keyboard
所以我删除了media
和thumbnail
键。现在以下代码有效:
{
"sender": {
"name": "John McClane",
"avatar": "http://avatar.example.com"
},
"tracking_data": "tracking data",
"type": "text",
"text": "Welcome to our bot!",
"keyboard": {
"Type": "keyboard",
"DefaultHeight": true,
"Buttons": [{
"ActionType": "reply",
"ActionBody": "reply to me",
"Text": "Key text",
"TextSize": "regular"
}]
}
}
推荐阅读
- ios - 有没有办法避免使用 GoogleSignIn 和 AppAuth-iOS 作为静态框架发生冲突?
- reactjs - 我在前端使用 React,在后端使用 Spring Boot,但出现错误
- spring - Spring Boot,Hibernate Data 弄乱了我的数据
- postgresql - 如何减少对称 DS 中的迁移时间
- ember.js - 如何离线使用 ember 纸图标?
- javascript - 当数据表中没有数据(初始和搜索后)时如何显示自定义表行()| 数据表 | jQuery
- python - 如何绘制三个相互重叠的正方形?
- javascript - 链接数组方法(filter、map、reduce)而不是使用双循环
- linux - linux中的join命令和排序错误
- java - 如何在几秒钟内重试某些方法,当超时抛出方法的异常而不是 Selenium 中的 TimeoutException?