首页 > 解决方案 > Viber Rest Api 无法打开内部浏览器

问题描述

我正在编写一个 Viber“键盘”,我想创建一个在内部浏览器中打开链接的按钮,根据这个 doc文档应该通过将 JSON 帖子发送到https://chatapi.viber.com/pa来完成/send_message。我正在设置按钮的参数“ActionType”:“open-url”和“ActionBody”:“example.com”。参数 "OpenURLType": "internal" 是可选的,默认值为 internal。不管我写什么作为这个参数的值,或者如果我省略它,响应是成功的,但是 url 在外部浏览器中打开。

{
    "receiver":"some hash",
    "keyboard":{
      "Type":"keyboard",
      "DefaultHeight":false,
     "Buttons": [
            {
                "Columns": null,
                "Rows": null,
                "BgColor": "#7eceea",
                "Silent": null,
                "BgMediaType": null,
                "BgMedia": null,
                "BgMediaScaleType": null,
                "ImageScaleType": null,
                "BgLoop": null,
                "ActionType": "open-url",
                "ActionBody": "https://www.wikipedia.org/",
                "Image": null,
                "Text": "open this ",
                "TextVAlign": null,
                "TextHAlign": null,
                "TextPaddings": null,
                "TextOpacity": null,
                "TextSize": "small",
                "OpenURLType": "internal",
                "OpenURLMediaType": "nulll",
                "TextBgGradientColor": null,
                "TextShouldFit": null
            }
        ]
   }
}

和响应 200 OK

{
"status": 0,
"status_message": "ok",
"message_token": 5469236575712199350,
"chat_hostname": "SN-CHAT-01_"

}

当我使用其他可选参数时,我注意到不一致。当您提供一些乱码值(例如将 ActaionType 设置为“operghj”)时,其中一些会产生错误。其他可选参数没有。例如

{
    "status": 3,
    "status_message": "keyboard is not valid. [instance value (\"operghj\") not found in enum (possible values: [\"reply\",\"open-url\",\"\"])]",
    "chat_hostname": "SN-CHAT-01_"
}

有谁知道如何解决这个问题或我做错了什么?

标签: springapirestviberviber-api

解决方案


参数"min_api_version": 7, 必须添加到 json 中,以便在内部打开 url。

{
    "receiver":"some hash",
    "min_api_version": 7,
    "keyboard":{
      "Type":"keyboard",
      "DefaultHeight":false,
     "Buttons": [
            {
                "Columns": null,
                "Rows": null,
                "BgColor": "#7eceea",
                "Silent": null,
                "BgMediaType": null,
                "BgMedia": null,
                "BgMediaScaleType": null,
                "ImageScaleType": null,
                "BgLoop": null,
                "ActionType": "open-url",
                "ActionBody": "https://www.wikipedia.org/",
                "Image": null,
                "Text": "open this ",
                "TextVAlign": null,
                "TextHAlign": null,
                "TextPaddings": null,
                "TextOpacity": null,
                "TextSize": "small",
                "OpenURLType": "internal",
                "OpenURLMediaType": "nulll",
                "TextBgGradientColor": null,
                "TextShouldFit": null
            }
        ]
   }
}

推荐阅读