I’m working on a Telegram bot that uses Dialogflow (formerly api.ai) for natural language processing. I want to show custom keyboard buttons to users, but it seems Dialogflow is only sending the main text reply to Telegram.
Here’s what I’ve tried:
- Set up a webhook that returns a JSON response
- Added reply_markup with keyboard options in the ‘data’ field
{
"fulfillment": {
"speech": "Choose an option:",
"data": {
"chat_id": 123,
"text": "Select one:",
"reply_markup": {
"keyboard": [
["Option 1"],
["Option 2"]
],
"one_time_keyboard": true,
"resize_keyboard": true
}
}
}
}
But the keyboard isn’t showing up in Telegram. Am I missing something? How can I get these custom buttons to display? Any help would be appreciated!
From my experience, the key to displaying custom keyboards in a Telegram bot using Dialogflow is to implement a middleware layer that intercepts and modifies the Dialogflow response before sending it to Telegram. In your webhook, after receiving the Dialogflow response, you can add the custom keyboard options to the message structure expected by Telegram. This approach maintains Dialogflow’s natural language processing capabilities while fully utilizing Telegram’s UI features. For example, you first receive and process the webhook request with Dialogflow, then create the Telegram message structure by including both the text reply and the custom keyboard before sending it via the Telegram API. This method has provided flexibility and better control over bot interactions in my projects.
I faced a similar situation with Telegram and Dialogflow. The main issue lies in Dialogflow not directly supporting Telegram features such as custom keyboards. My solution was to handle Telegram messages separately. After receiving the Dialogflow response, I manually created a new message for Telegram. I added the response text and then attached the custom keyboard before sending it on. This method allows me to maintain Dialogflow’s natural language functions while also fully leveraging Telegram’s interface capabilities. It does require extra setup but eventually provides more control over the final output.
hey emma, i had same issue. dialogflow doesn’t handle telegram keyboards directly. u need to process dialogflow response in ur backend, then construct telegram msg with keyboard separately. it’s bit tricky but works gr8. lemme know if u need more help!