Can I add custom keyboard buttons to my Telegram bot using api.ai?

I’ve set up a Telegram bot and connected it to api.ai. Now I want to add custom keyboard buttons to my bot responses. But it looks like api.ai is only sending the main text reply to Telegram. I’m not sure how to make the keyboard buttons show up.

Here’s what I’ve tried:

In my webhook, I’m returning a JSON response that includes a reply_markup section with keyboard options. It looks something like this:

{
  "fulfillment": {
    "speech": "Hello!",
    "data": {
      "reply_markup": {
        "keyboard": [
          "Option 1",
          "Option 2"
        ],
        "one_time_keyboard": true,
        "resize_keyboard": true
      }
    }
  }
}

But the buttons aren’t appearing in Telegram. Am I missing something? How can I get these custom keyboard buttons to show up in my bot responses? Any help would be great!

I’ve encountered a similar issue when working with api.ai and Telegram bots.

The problem is that api.ai doesn’t natively support Telegram’s custom keyboard markup. To overcome this, you need to handle the keyboard buttons in your webhook code.

In my experience, intercepting the response from api.ai in your webhook, then adding the custom keyboard markup using the Telegram Bot API directly, is the most effective solution. This way, you have full control over your bot’s responses and can include any custom keyboards as needed.

As someone who’s been working with Telegram bots for a while, I can tell you that api.ai (now Dialogflow) doesn’t directly support Telegram’s custom keyboards. It’s a common stumbling block.

Here’s what worked for me: I created a middleware layer in my webhook. This layer intercepts the response from api.ai, then constructs a new response using the Telegram Bot API. This way, you can include the custom keyboard markup directly in your bot’s response.

It requires a bit more code on your end, but it gives you full control over the bot’s interactions. You’ll need to use a Telegram Bot API library in your preferred language to send messages with custom keyboards. It’s more work initially, but the flexibility is worth it in the long run.

hey man, i had the same problem. api.ai doesn’t handle telegram keyboards directly. you gotta modify your webhook to add the keyboard stuff yourself. intercept the api.ai response, then use telegram’s bot API to send the message with keyboard. it’s a bit more work but it’ll do the trick!