WeLoveNocode Blog

How to Create Telegram bot in 30 minutes - Integromat Tutorial

Almost every team that goes agile regularly does stand up with reports on their work and plans for the day, and often these meetings devour too much time. Let's try to automate and speed up this process.

In this tutorial, you will learn how to make a simple telegram bot for daily standups using Integromat

The MVP is as follows: a user subscribes to a bot, with /start, then every day he receives 3 questions:
1) What did you do yesterday?
2) What are you going to do today?
3) What problems did you encounter?

The user answers in the chat. Everything is stored in a database and the reports are controlled by the project manager. Profit!

Get Started: Create a database in Airtable

First, let's create a simple database in Airtable consisting of two tables - "id_users" with the "tg_id_chat" column - where we will store the unique IDs of our users' accounts and the "reports" table with the "tg_id_chat" key and the "report" column, where the users' answers will be stored. An example of DB can be copied here

Let's create the first Integromat script “standups_get_answer”

(that will receive messages from users)

The first Telegram bot "Watch updates" module to listen to all incoming messages. To configure it, you need to create a connection through the API token of your bot's telegram, which can be obtained in tg @BotFather /newbot

itegromat module telegram bot watch updates
set telegram API

1. telegram module: Watch updates
set webhook

Next, let's create two branches of the script, for the case when a user registers for the first time through the command "/start", and when he or she sends in answers to the questions.

Add the element "Router", adjust the branching by matching the text from the listened message.

integromat module router

If you entered a message that is not equal to "/start", go to the Airtable module "Create a record" to log the responses. First, you need to connect the Airtable API.

integromat module Airtable
API airtable

Then select a table, columns to record and drag and drop the desired data sources into them.

integromat module Airtable
save messages

To implement a new user registration script via "/start" let's first check if it is in the database. You can do this using the Airtable "Search Records" module.
In the "Formula" field we enter a search query, "sort" sorts the output, "limit" limits the number of output lines. 

integromat module Airtable
search existing id

Run the current script and pay attention to the output data from the "Coincidence" search module. The image on the left - no matches, on the right - with the output of the found strings.

integromat module Airtable
compare outputs

For the branching of the script we will check the existence of the ID parameter in "Bundle 1", i.e. if this user does not exist in the id_users table, we will create a new line in Airtable, if it does exist - we will send the answer in Telegram with the text "You already subscribed".

integromat module Airtable router

In the 'condition' field we also drag and drop the required 'ID' field with the mouse.

On the route "Not found" we create the Airtable module "Create a record", with which we record the ID of a new user.

integromat module Airtable create a record
save id

On the "exist" route, we create a Telegram module "Send a text message or a reply", and set up the message sending.

integromat module telegram bot send a text message or a reply
You already subscribed!

Second Integromat script standups_send_message

Connect Airtable’s "Search Records" module, it will display a list of all entries in the id_users table. In this case, there is a restriction on the output of 10 rows, but it is possible to see more. 

integromat module Airtable search result
search last 10 id of users

By clicking on the clock icon, we can set up mailing start schedules, here - it’s set to every day at 10 o'clock.

integromat module timer
mailing shedule

Now that we have got the list of all user IDs, let's configure the mailing of messages using the Telegram bot module "Send a text message or a reply".  In the field "Chat ID" drag and drop the appropriate source, fill in "text".

Telegram bot module Send a text message or a reply
send message

Save it and... Done!
Now you can run both scripts in automatic mode

integromat scenarios
lets start scripts

That's what the telegram test looks like.

telegram bot

A team of 10 people will spend about 900 operations per month, which is covered by a free Integromat subscription.

Subscribe to the blog and stay tuned for new articles about Nocode tools!
How do I do this