【问题标题】:Send "welcome message" with keyboard to Viber bot使用键盘向 Viber bot 发送“欢迎信息”
【发布时间】:2020-09-02 16:45:31
【问题描述】:

Viber API 允许在conversation_started 事件类型上发送一些消息以允许用户订阅。从documentation about "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"
    }]
}

【问题讨论】:

    标签: viber viber-api viber-bot viber-bot-python


    【解决方案1】:

    经过一些尝试,我发现不能同时使用 media + thumbnailkeyboard “欢迎信息”。所以我删除了mediathumbnail 键。现在下面的代码可以工作了:

    {
        "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"
            }]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-31
      • 2019-04-04
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      相关资源
      最近更新 更多