• Category
  • >NLP

Building Telegram Chatbot with Dialogflow

  • Ripul Agrawal
  • Jun 22, 2020
  • Updated on: Jun 18, 2020
Building Telegram Chatbot with Dialogflow title banner

“Connecting Artificial Intelligence and Customer Service.”

 

Introduction

 

A chatbot is an AI-driven application for human interaction with the computer program either via text or text-to-speech mode. It’s developed to communicate the same way as human activity in their chat.

 

The chatbot is developed by the proper tuning and testing based on NLU to make it more adaptable by humans. You must have been using a chatbot in your life from seeking some online product to hunting for pizza at dominos online store.

 

Some of the common ML Chatbots include Google Assistant, Alexa, Siri, Cortona, etc. If you own windows, android phones, or iPhones, then you must be conscious of these apps.

 

If you look into the industrial application of chatbot, there are many as many firms who are using it to scale their business at a greater level, as it supports them in managing their relations with customers. Like in Facebook Messenger, Telegram, Slack, Skype, Twitter, etc. there are some inbuilt chatbots where users can interact in the same way as humans interact. 

 

While surfing the internet, you might find in some websites an option of "Chat with us", so when you click on that there will be a pop up with some program generated message, which is a chatbot developed by the company for customer support. 

For example, you can see below image, of domino’s chat option,


This image is showing the chatbot used by Domino's developed using Dialogflow.

Domino's Virtual assistant


The sole purpose of this blog is to develop a chatbot. As with the evolution of technology, there are so several tools available for chatbot development like it can be developed by writing programs in a different language utilizing available libraries and frameworks like RASA, Dialogflow, Amazon Alex.

 

These frameworks let you integrate these chatbots with your own developed applications or some existing ones as with telegram, Facebook messenger, Slack, Skype, etc.

 

What is Dialogflow?

 

It’s a natural language understanding platform, owned by Google Service. It can be used to develop conversational interfaces for websites, mobile applications. It also supports both text and text-to-speech features for interaction with the user.

 

As many companies are using their services by integrating with their business to scale their customer support. Dominos, The Wall Street Journal, Ticketmaster, KLM Royal Dutch Airlines, etc. have used Dialogflow services in the integration of their customer support on their websites.

 

Apart from these, it can be further utilized to create bots for the existing platforms, including Google Assistant, Messenger, Telegram, Slack, Hangouts, Twitter, etc. 

 

You can make your own chatbot on these for just fun among your buddies or expand your business via social media. Later you will witness one such application of bot for the Analytics Steps.

 

From now onwards, you will start developing your first virtual agent using Dialogflow console, for that first log in to your google account, and move to the Dialogflow page.


This image is showing the homepage of the Dialogflow, showing all of its services and case studies.

Dialogflow home page


Now click on the Sign up for free.


This image is showing the sign-in page of the Dialogflow console

Sign in with Google


Now feed your Google account details. Following this, there will be a pop-up asking for your location and time-zone, fill the valid details.

 

Next, create a new agent by pressing CREATE AGENT.


This image is showing the first page after sign-in and page where you can create a new agent.

Create Agent


Next set the agent name of your choice and that fit best of its soul purpose, also provide the language of the bot and the time zone and press create.


This image is showing the page to fill up the agent name with other details including language and timezone.

Fill up the agent details


Now before heading towards the development, you should be aware of some important terminology which will be further used in the development. These are as follows,

 

1. Intents

 

It refers to the group of texts/sentences from the user, that reflects the intention of the user while talking to the agent. And those sentences which form one intent will be used as Training Phrases to trigger that particular intent. 


There are some default intents already trained for intentions which everyone shares like greetings, welcome intents, apart from this, you can also add small talks as well with prebuilt responses.

 

In the default intents, user can store their own training phrases as per their convenience and responses simultaneously. Also, you can create your own intents i.e. customizable. Follow the below steps for the same,

 

  • Create Intent


Showing the page where you can create a new intent along with a list of all created intents.

Creating Intent


  • Set the name of the intent

 

It should be relatable with the intents training phrases so it won’t be difficult in future if you need to make some changes or any updates,


This image is showing the section where you have to enter the intent name while creation.

Enter the name of Intent


  • Add Training Phases

 

Now add some training phases, use common words, by navigating to the training phases section. There will be different phrases for every intent and the user will use these or similar sentences while interacting with agents.


This image is showing the page to add Training phrases corresponding to its intent, basically phrases which users enter while communicating with the agent.

Add training phrases


  • Add Responses

 

Now its time to set responses text which will be generated by the agent. There can be one or more responses at a time for a single user phrase.


This image is showing the page to add default responses, consist only text responses and valid for every platform.

 Add Responses


You can set custom responses as per the platform you want it to integrate. 

In the above image, you can see there are two options to add responses;

  • One is the default, it includes the text responses only,

  • The other one is the Telegram, where you can add responses with images, and

  • Cards with multi-features as it provides buttons as well. 

At all, if you have used telegram bots then, you must be aware of those or refer to the below figure for the same.


This image is showing the page where you can add custom responses to integrate with the Telegram, which includes images, buttons, hyperlinks as its response.

Add responses for Telegram


As in the above image, you can see how to add button, image, hyperlinks in the response by the chatbot.

 

  • Save and Train

 

            Now before moving to the next intent first press Save at the top to save all the phrases and responses,


  This image is showing the notifications of saved changes in your intent.

Save the Changes


Wait till the training complete, as there will be a pop up at the bottom once training completes,


 This image is showing the pop-ups you will get once the Dialogflow's training completed

Training of Dialogflow


  • Test your agent

 

Once you are done with the creating of all the required intents, now its time to test your assistant, by just navigating to the Try it now section in the side panel,


This image is showing the page where you can test your agent either with text or voice command like the Google assistant.

Try it now


To test this out, you can also use speech-to-text as well.

 

In the below image you can see some examples of user-bot conversation with the Telegram generated responses.


This image is showing the conversation demo of your agent in the "Try it now" panel.

Chatbot Demo 


As from the above image, it is clear that there are images, clickable links in the form of buttons in bot’s response.

 

Further, there are many more advancements that can be done in chatbot development i.e. use of Entities, Context, Small talk, and Events.

 

2. Entities

 

It is something that natural language processing (NLP) chatbots can pluck from phrases that users enter in order to turn around accurate recommendations and answers. It can be a time, place, person, item, number, etc.

 

 

Integration with Telegram

 

Now it's time to integrate your first agent with a telegram and let your friends explore your bot.

 

  • Open the telegram either on the phone or in a laptop and log in with your credentials.

  •  Search for @botfather and type /start and it will show a list of commands,


This image is showing the "@botfather" on telegram to set your authorize your first agent at the telegram.

Commands by botfather


  • As this is your first bot so type the /newbot command,

  • Then provide with the display name and username for your bot,

  • Got the access token, copy it and save it for later use,

  • Navigate to the Dialogflow.

  • Move to Integrations tab,


        This image is showing the dashboard of the Dialogflow.

 Integrate bot with other apps


  • Navigate to telegram and enable it as in the below image.


   This image is showing the platforms with which this agent can be integrated. Also, you can enable agent for available platforms at this page.

Enable the Telegram Integration


  • Paste the access token and press start,  now your bot is ready to use.


This image is showing the page where you can start the bot for telegram by pasting access token gotten from the "@botfather"

Start the Telegram bot


Take a live demo of a chatbot on Telegram.

 

You can integrate every chatbot with more apps like Facebook messenger, hangouts, Slack, Twitter, Skype, Google Assistant, and many more following the official documentation, with some limitations.

 

You can see the snap of integration of this with web demo. As it doesn’t support clickable hyperlinks and images, just only simple text.


This image is showing the web-demo of your agent when it will be integrated with any website.

Web Demo


Further to make your bot more advanced as per your requirements follow this.


 

Conclusion

 

A chatbot is basically a computer program based on Natural language understanding which simulates the human-human interaction and makes it more smooth. Chatbots helps the business in expanding by improved customer services, increased customer engagement, etc.

 

Many Rest APIs and frameworks are there for its development, one of them is Dialogflow that have been used here for the chatbot development as it is built on Google infrastructure and powered by Google Machine Learning. Also, integrations with other services or applications are easier by this. It has been integrated with the Telegram and the web demo.

Latest Comments

  • Ripul Agrawal

    Dec 09, 2020

    For any queries, please reach out to me at ripulagrawal98@gmail.com