Dialogflow Telegram Integration allows you to easily create Telegram bots with natural language understanding based on the Dialogflow technology.
Limitations
Only the default agent language is supported by this integration.
Setting Up Telegram
In order to set up the Telegram integration for your agent, you'll need the following:
- a Telegram account .
Creating a Bot in Telegram
- Login to Telegram and go to https://telegram.me/botfather
- Click the Startbutton in the web interface or type /start
- Click on or type /newbotand enter a name
- Enter a username for the bot, ending in "bot" (e.g. garthsweatherbot)
- Copy the generated access token
Setting Up Dialogflow
- In Dialogflow, go to Integrationsin the left hand menu
- Click on the Telegramtile
- Paste the Access Tokeninto the related field
- Click the Startbutton
Testing
BotFather will provide a link to your bot once you've completed the setup. Go to
this link to test out your agent.
Regenerating Telegram Token
To regenerate the Telegram token for an agent with Telegram integration enabled, do the following:
- Go to the Dialogflow integration settings and click STOP.
- Regenerate the token in Telegram.
- Enter the new Telegram token in the integration settings and click START.
Integrating Agent with a New Telegram Bot
For an agent with Telegram integration enabled, to link it to a new Telegram bot, do the following:
- Go to the Dialogflow integration settings and click STOP.
- Delete the old bot in Telegram if needed.
- Enter the new Telegram token in the integration settings and click START.
Events
The following events are triggered by this integration:
Event | Description |
---|---|
TELEGRAM_WELCOME
|
Triggered when a user starts a conversation with your Telegram bot or types /start
. |
TELEGRAM_HELP
|
Triggered when a user inputs /help
while conversing with your Telegram bot. |
TELEGRAM_SETTINGS
|
Triggered when a user inputs /settings
while conversing with your Telegram bot. |
Rich response messages
The following rich response messages are supported.
Image responses
Supported formats and sizes:
- 5 MB max size
Card responses
Either the image URL field or the title field is mandatory.
Buttons with a URL and with a text postback are supported. When tapped, a button with a URL will open a web page, whereas a button with text will send the text as a user query.
Quick reply responses
Quick replies in one-click Telegram integrations correspond to keyboard buttons in Telegram .
When a user clicks one of the buttons, the buttons are dismissed. This prevents the issue where users could click buttons that are attached to old messages in a conversation.
Custom payload responses
Formatted text and hyperlinks in one-click Telegram integration
Your Telegram bots can send formatted text and hyperlinks.
The following example sends formatted text with a hyperlink using the Markdown parsing mode:
{ "telegram" : { "text" : "You can read about *entities* [here](/docs/concept-entities)." , "parse_mode" : "Markdown" } }
See the Telegram documentation for reference.
Inline Keyboard Buttons
The following example shows how you can define Inline Keyboard buttons in the Custom payload element.
{ "telegram": { "text": "Pick a color", "reply_markup": { "inline_keyboard": [ [ { "text": "Red", "callback_data": "Red" } ], [ { "text": "Green", "callback_data": "Green" } ], [ { "text": "Yellow", "callback_data": "Yellow" } ], [ { "text": "Blue", "callback_data": "Blue" } ], [ { "text": "Pink", "callback_data": "Pink" } ] ] } } }