Bot Creator

Bot Creator

Source

Before you can create the bot, you need to get the bot token from the Telegram, You can get your bot token from @botfather. BotFather is a Telegram's official bot to create the bots. or go to Telegram app and search for @botfather. Start the bot and send "/newbot" and follow the instructions, in the end, you will get your bot token, copy and keep it ready.

Click on "MY BOTS" in the navigation bar, In this page, you can see all your bots. To create a new bot copy-paste the token obtained from the BoFather in the above input field and click "Create New Bot" button.

Now your bot is linked with Bot Creator. You need to define your chat flows to make it operational. Click on edit to create chat flows.

In this page your bot's complete functionality is defined in the form of Chats and Triggers. If you have not read about the Chats and Triggers,

Click on 'Create New Chat'

Give a chat name as 'start' (it can be anything), we are going to link this chat with '/start' command. so whenever user sends '/start' command to bot, the bot will follow events present in this chat.

Click on 'Add Event'

You can have multiple tasks in an event. click on 'Add New Task'

From tasks dropdown select 'Reply', We want to reply the user with what this bot can do.

Now fill the message field with the message you want to send to user. If you observe we have used "{{ first_name }}" in the message, this helps making the message specific to user, "{{ first_name }}" will be replaced with the user's first name. you can use html bold tags to make text bold.

Now we want to add custom keyboard, so that user can easily know, what bot can do. click on 'Custom Keyboard'.

Add two buttons 'world summary' and 'country wise summary'. When user clicks 'world summary' we want to show covid19 cases stats of the world, and when user clicks 'country wise summary' we are going to ask him which country stats he wants to see, based on the input we are going to show the user-specified country stats.

Click on 'save chat' to save your first chat.

Now we are going to add '/start' command, To add command click on Commands under Triggers.

Click 'Add Command' and fill the command as 'start', select the chat 'start' from the dropdown, describe what this command does. Click on 'Update Bot' to update the bot with existing chats and triggers. Currently we have one command '/start', one chat 'start' and two custom keyboard buttons. we have linked 'start' chat with the '/start' command, so whenever user sends '/start' command 'start' chat will be invoked.

We need to create two more chats to link with the above two custom keyboard buttons. You can see custom keyboard buttons by clicking 'Custom Keyboard' under Triggers.

Lets create a chat to handle 'World summary' button click. Go to chats, click create new chat, name the chat as "World summary", click add Event and click add Task. We are going to use a to get the stats about the covid19 cases. So we need to make a http get request to to get summary about the world.

The API returns the above json result for us, we are going to use the just 3 lines from this result. To make a http request to 3rd party sites select "HTTPRequest" from tasks dropdown.

Select request method as 'GET', fill URL as https://api.covid19api.com/summary. Fill the error message as 'To many requests, Try again Later'. This error message will be sent to the user, if the http request recieves status code other than 200. The result of the http request will be saved in 'http_result' as a json object. Click on 'Add New Task' and select task as reply, In this reply we are going to reply user with the world summary.

We are sending total confirmed, total deaths and total recovered, we can get these values from http result that is stored in 'http_result' variable as shown above. Click on Save Chat.

Now go to custom keyboard section and link 'World summary' chat to 'world summary' button.

We need to create one more chat, Click create new chat and name it 'country wise summary', add Event , add Task, select task as 'Reply'

In this task we are going to ask user which country stats he want to see.

Now we need to add another Event which will execute once the user sends country name, click add Event and click add Task, In this task we will capture the user input to use it in next task. Select task as 'CaptureData'

Save user input in variable named 'country', we use this country variable in next task to fetch stats about that country from covid19api. Click add new task and select as 'HTTPRequest'.

We need to request URL by replacing 'c' with the actual country name to get details about the country. We get a big list of details having all day wise stats, we need only the latest date details. that can be obtained as shown in above reply.

Now save the chat and got to custom keyboard and link this chat with 'country wise summary' button

Congratulations, We have finished creating the first bot, click on 'Update Bot' to save the configuration.

Click on chat to start chatting with the bot.

Below screenshots show chatbot in action.

Report Page