How to Automate Extraction of Telegram Locations and Add Them to Sheets for Micro-Mobility Startups in Europe?

This topic was automatically generated from Slack. You can find the original thread here.

Hey everyone! I just came across Pipedream and wanted to see if it’s possible to extract telegram locations from a group chat and turn each location into a row in sheets? Is there anyway to automate this process using telegram bots? if not is there any other social media app that would allow that sort of workflow?

The clients I am trying to build it for are billion dollar micro-mobility start ups and their ops is a mess in Europe where everything is regulated, so your insight would be extremely helpful and they would become life long customers of your service :slight_smile:

Hi Ali, welcome. Take a look at our Telegram actions here. I don’t see a prebuilt action for this specifically, but it looks like the Telegram Bot API supports retrieving the location of chats, messages, and other objects. Try searching those docs for the word “location” and you’ll see the references.

Then you can add a new HTTP request or Node.js code step in a workflow to send a custom request to Telegram to get the data you need.

Then you can use the Google Sheets - Add Single Row action to write that data to a sheet.

Can you help me build a workflow that answer’s Ali’s original question (fetches message location data from the Telegram API) and adds that data to a row in Google sheets?

Sure, I can help you build a workflow to fetch message location data from the Telegram API and add that data to a row in Google Sheets. Here’s a step-by-step guide: 1. First, you’ll need a Telegram bot. Follow the instructions in the Telegram Bot API documentation to create a bot and obtain its API token. 2. In your Pipedream workflow, add an HTTP trigger. This will allow you to receive updates from your Telegram bot. 3. Set up a webhook in Telegram to send updates to your Pipedream workflow’s HTTP trigger URL. You can do this by making a request to the setWebhook method of the Telegram Bot API: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { telegramBotToken: { type: "string", label: "Telegram Bot Token", }, pipedreamWebhookURL: { type: "string", label: "Pipedream Webhook URL", }, }, async run({ $ }) { const apiUrl = `https://api.telegram.org/bot${this.telegramBotToken}/setWebhook`; return await axios($, { method: "POST", url: apiUrl, data: { url: this.pipedreamWebhookURL, }, }); }, }); 4. In your workflow, add a new Node.js code step to extract the location data from incoming Telegram messages: ```
export default defineComponent({ async run({ steps }) { const message = steps.trigger.event.body.message; if (message.location) { const { latitude, longitude } = message.location; return { latitude, longitude }; } else { console.log(“No location data found in the message.”); } }, });

This is just an example based on your original question — you can ask Pi any questions like this just by at-mentioning it. That can be helpful for finding the right triggers / actions and answering basic questions about Pipedream.

re: #2 and #3, aren’t there native Telegram triggers I can use on Pipedream, instead of HTTP triggers?

You’re correct! Pipedream has native Telegram triggers that you can use instead of HTTP triggers. To use a native Telegram trigger: 1. In your Pipedream workflow, click on the trigger menu and search for the “Telegram” app. 2. Select the desired Telegram trigger, such as “New Updates”. 3. Connect your Telegram account by providing the required API token. 4. Configure the trigger according to your needs. Once you have the Telegram trigger set up, you can continue with the rest of the workflow to extract location data and add it to Google Sheets as described in my previous response.

Thank you for the prompt response! I will go through it tomorrow.