如何在与api.ai集成的Telegram机器人中显示键盘按钮?

时间:2016-07-14 14:03:50

标签: php telegram-bot dialogflow

我有一个示例Telegram Bot,我已将其集成到我的api.ai帐户中。我想显示键盘按钮,就像下面一样,但似乎api.ai只是将主要文本回复发送到电报。任何想法我怎么能实现我刚才描述的内容?请告知方向和/或解决方案。谢谢!

I wanted to display the Keyboard custom buttons for Telegram when I send a reply from api.ai

我有一个Fulfillment webhook网址,在调用我的示例Intent时会返回此json

{
  "id": "af681b42-9ced-4f8f-ab0c-0559b210dc1a",
  "timestamp": "2016-07-15T01:47:30.896Z",
  "result": {
    "source": "agent",
    "resolvedQuery": "Hello",
    "action": "show-main",
    "actionIncomplete": false,
    "parameters": {},
    "contexts": [],
    "metadata": {
      "intentId": "e477976e-2412-4066-b320-48d7dedd5dfe",
      "webhookUsed": "true",
      "intentName": "Adobo"
    },
    "fulfillment": {
      "speech": "Hello world!",
      "source": "index.php",
      "data": {
        "chat_id": 1,
        "text": "hi there",
        "parse_mode": "HTML",
        "reply_markup": {
          "keyboard": [
            "A1",
            "A2"
          ],
          "one_time_keyboard": true,
          "resize_keyboard": true
        }
      }
    },
    "score": 1
  },
  "status": {
    "code": 200,
    "errorType": "success"
  },
  "sessionId": "4cb02864-9925-4d4c-a0f1-14dbab44add7"
}

我已经在json格式中添加了“data”下的回复标记键盘。

1 个答案:

答案 0 :(得分:1)

你之前能否单独发送文字(没有键盘)?

我认为这是一个语法错误。 "keyboard"字段应该是一个数组数组。请尝试使用以下代码段替换该字段。

"reply_markup": {
    "keyboard": [
        ["Day", "Week", "Month"],
        ["Users", "Retention"],
        ["sessions", "Events"],
        ["Back"]
    ],
    "one_time_keyboard": true,
    "resize_keyboard": true
}