Tasker and Telegram integration: live location

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

--

In this story, I’ll integrate the task to share your location shown in Tasker and Telegram integration sending a Live Location instead.

The fundamental thing to understand is that the bot cannot update the live location on its own. The task has to do it.

Telegram Bot API

You can find all the APIs used below on the Available Methods page.

The %par1 in the following tasks is the chat identifier. Read the article linked at the beginning to understand how to get it.

Method sendLocation

The call sendLocation has the optional parameter live_period that allows us to send a live location by specifying a positive number of seconds between 60 (1 minute) and 86400 (24 hours).

In the following screenshot, you can see the task to call this method.

It performs the following actions:

  1. Get Location v2: obtains my current location. You can read more details in the Get Location v2 user guide.
  2. HTTP Request: calls the API as shown in the screenshot on the right. %telegramToken is the token BotFather gave me, %par1 and %par2 are the parameters the task received.
  3. Return: gives the caller task a value. With %http_data[message_id] it returns the message identifier to later update and/or stop the live location.

Method editMessageLiveLocation

The call editMessageLiveLocation allows the bot to update the live location sent with the previous method. The parameters are quite the same except the message_id, which is the identifier of the live location message.

In the following screenshot, you can see the task to call this method.

It performs the following actions:

  1. Get Location v2: obtains my current location.
  2. HTTP Request: calls the API as shown in the screenshot on the right to update the live location message identified by %par2.

Method stopMessageLiveLocation

The call stopMessageLiveLocation ends the live location sent with the first method before the live_period ends. It requires the parameter message_id.

In the following screenshot, you can see the task to call this method.

It performs an HTTP Request that calls the API as shown in the screenshot on the right to end the live location message identified by %par2.

You can download all the tasks explained here.

Send Live Location Task

It is now possible to send a live location message, update it and eventually stop it.

The following task asks the user how often it should update the live location, for how many times, and shows a notification to update or stop it at any moment.

It performs the following actions:

  1. Input dialog: asks the user how often, in minutes, it should update the location.
  2. Variable Set: saves the user input in the %familyLocationInterval variable.
  3. Input dialog: asks the user how many times it should update the location.
  4. Variable Set: saves the user input in the %familyLocationTimes variable.
  5. Variable Set: calculate the live_period parameter like this: (%familyLocationInterval * (%familyLocationTimes + 1)) * 60. It adds one to the times to make sure that slow networks don’t interfere.
  6. Notify: sends a notification to let the user update and stop the location manually.
  7. Perform Task: sends a Telegram message to the group to notify them what it is doing.
  8. Variable Set: sets the %familyLocationIndex variable to 0.
  9. Perform Task: sends the live location to the group using the first method explained earlier. It saves the return value in the %familyLocationMessageId variable.
  10. If: checks that the message was sent and an id was returned.
  11. Wait: waits %familyLocationInterval minutes.
  12. Perform Task: updates the live location using the editMessageLiveLocation method.
  13. Variable Add: increments the %familyLocationIndex variable by 1.
  14. Goto: if the index is less than the times, it goes back to the Wait action at position 11.

The last action calls the following task.

It dismisses the notification, clears the variables, and uses the stopMessageLiveLocation method to stop the live location message.

--

--

Alberto Piras
Geek Culture

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