Integrating Recipe Bot with Telegram

In my previous post, I explained how we can create a recipe finder bot. In this post, we will Integration it with Telegram and customize the returned message.

API.ai provides one-click integration for many platforms. We will enable Telegram integration in this tutorial.

Create a new Telegram Bot

Following these step from api.ai to create and setup a new BOT.

Now if you go back to our “find recipe” intent, you will see a new tab for Telegram under Response.

You can create Text, Image, Card or Custom payload type of message here for Telegram bot. But we will let our Webhook handle it.

Returning message for Telegram from Webhook

In the response from webhook, we can put a message for Telegram, or any other integrations, under data field. It will be processed by Telegram.

Read more about it here.

Here is a sample of how it should look like:

Telegram Bot Api Doc  is a good resource to get an idea of what <telegram_message> can be. We will be using it’s “sendMessage” method by supplying text and parse_mode fields. We want out Recipe bot to return a rich text message with some bold text. We will be passing parse_mode=Markdown for that purpose.

Here is an early preview of an example message return by our webhook:

Notice the “*” in our text field for the telegram. That’s the markdown formatting.

There are several other html tags we can use with this markdown.

(http://www.example.com/) `inline fixed-width code` “`text pre-formatted fixed-width code block “`

Final Webhook code in Node.js

I won’t go in too deep about the webhook implementation.

You can find the complete project on my GitHub.

Here is a screenshot of the telegram bot live:

Share this:

Like this:

Leave a Reply

Your email address will not be published. Required fields are marked *