Tasker and Telegram Integration

Alberto Piras
Geek Culture
Published in
4 min readJul 9, 2021

--

Today, I’ll explain how to send messages on Telegram using Tasker. I’ll show, in particular, the methods to send text messages and your location.

I find this useful to schedule messages for my family group, for example, when I arrive at someplace.

Requirements

  • Tasker 5.12.22
  • Telegram

All the calls I’ll show and more are available on the Telegram Bot API website provided by Telegram.

Step 1. Create a Telegram Bot

To send messages on Telegram, we need to create a bot using BotFather. Here you can find an official guide on how to use it.

By sending the command /newbot, BotFather will guide you in creating a bot.

At the end of the process, it will provide a token to send messages using your bot.

Step 2. Try the API and create the tasks

The URL structure to send Telegram messages is the following.

https://api.telegram.org/bot<token>/METHOD_NAME

I’ve created a Postman project to test all the calls I needed. You can import them with this file.

Get your chatId

The chatId parameter is the unique identifier for the target of any call, so it is always required.

To find your chatId, you can send a message on Telegram to the bot. To find the one of a group/channel, you have to send a message like this in the chat: /start@bot_username.

After sending the message, you can use the getUpdates call to see the messages your bot received.

The key $.result[].message.chat.id has the value of your id.

The URL is https://api.telegram.org/bot<token>.

Available methods

There are several messages a bot can send. You can read them all on Available Methods.

I created some POST calls using Postman, but the GET ones were easier to use in Tasker. Telegram allows both methods.

All methods in the Bot API are case-insensitive. We support GET and POST HTTP methods. Use either URL query string or application/json or application/x-www-form-urlencoded or multipart/form-data for passing parameters in Bot API requests.
On successful call, a JSON-object containing the result will be returned.

Method sendMessage

The call you need to send text messages is sendMessage. Here you can see how to use it.

The URL is https://api.telegram.org/bot<token>.

The following screenshot shows how to do the same in Tasker.

%telegramToken is the token BotFather gave me, %par1 and %par2 are the parameters my task received. You can read more about it on the Perform Task user guide.

Method sendLocation

The call you need to send your location is sendLocation. In the following screenshot, you can see how to get your current location and send it to your chat.

%telegramToken is the token BotFather gave me, %par1 is the parameter my task received, the other variables are explained in the Get Location v2 user guide.

You can download the tasks I have explained here.

Step 3. Get creative

You can now create some more calls and use them in a task.

For example, I wrote this task that sends my location every m minutes for n times.

The task on the left asks the user the interval between the messages and how many times to send them, then sends me a notification with an action to run the other one and then starts notifying the group.

The task on the right stops the first task and resets the variables.

EDIT: Read this article to see the updated version using the live location.

Another example is the following profile which sends my location when I receive a message from my family group with a specific keyword.

On the left, the notification event; on the right, the profile.

In the notification event, the Text field is the keyword, while the Other Text is the group name. I used Other Text instead of Title because the latter is the exact notification title, while the former looks for some words in the title, and Telegram changes the title based on the sender of the message.

--

--

Alberto Piras
Geek Culture

Software development engineer at Amazon. Thoughts and articles are my own.