Google Sheets Formula & Telegram Message ✈️ – Telegram Group

Google Sheets Formula & Telegram Message ✈️

Here’s a formula sample with IMPORTXML:

=IMPORTXML(
"https://script.google.com/macros/s/AKfyc...VnFp/exec?msg="&if(C3>500;"Hey sum is > 500!"&C3;"") &
"&chat_id=13246789";"/table/row")

It will send a new message to Telegram.

The idea is based on this post by Tanaike.

By the way, IMPORTDATA formula will also work:

=IMPORTDATA(
"https://script.google.com/macros/s/AKfyc...VnFp/exec?msg="&if(C3>500;"Hey sum is > 500!"&C3;"") &
"&chat_id=13246789")

Sample message:

Install

Full installation requires 4 files:

Please see this instruction on Miro Board

All files are available for view/copy here.

#1 of 4. ? Telegram Bot

The process is not easy to repeat. Please carefully follow these steps:

Here’s the official instruction on how to create a new Bot on Telegram

The next steps are inside the script editor. After you save the code and the project, do the following:

When you deploy WebApp, Google will ask you to allow the script to run. Here’s an article on how to pass authorization: https://spreadsheet.dev/authorizing-an-apps-script

Next, go back to Telegram.

The bot must be an admin to read messages

Next, go back to your script editor:

?? The response from Apps Script looks is message info in JSON format. Copy chat id from it.

From the same script, you may already send a message to Telegram! To test your Bot:

#2 of 4. ✏️ Memory

Please copy my Spreadsheet to use it as a Memory holder. It would be your place with information about sent messages to Telegram.

After you make a copy, please remember the file ID. Here’s mine:

1pI12qRVgIY7i03tVdd9jNd2GwPDgOi1RLthdpVpdMD8

I’ve copied it from the browser URL:

You’ll need this ID in the next step.

For now, there’s an issue. When you open a Spreadsheet, your formula will recalculate and send the same message again. One way to resolve the issue of duplicates is to write all sent messages into memory.

?Formula → ?Web-App → ?Telegram + ✏️Memory

I had to decide which type of memory to use. I stopped on simple writing data to a Sheet for these reasons:

#3 of 4. ? WebApp for Beeper

In this step you may need some information from previous steps:

Please follow these steps:

Please don’t forget to change: 1) token, 2) Memory Spreadsheet ID

#4 of 4. ✈️ Formula 2 Telegram

In this step you may need some information from previous steps:

Here’re we finally installed the code. Now you may use formulas to send messages to Telegram. I’ve made a template to make it easier:

This template demonstrates how to use the code.

The key here is to launch WebApp with a formula. The process is the same as if you run this URL with parameters from your browser as any other URL.

Here’s what WebApp URL looks like:

https://script.google.com/macros/s/LongLongKeyGoesHere…/exec

That’s not all! You also need to pass 2 parameters to your script. Your final URL will hold these parameters: message and chat id. Here’s a sample URL with parameters:

https://script.google.com/macros/s/LongLongKeyGoesHere…/exec?msg=Hello&chat_id=-12346789

URL has 2 parameters here:

And here the fun part starts. As this URL is passed via formula, you can use any other formulas to combine your message into Telegram. This means you now can control which messages will come to Telegram:

First of all please note: the message should be encoded because you send it via Web URL. Luckily we have a native Google Sheets function to encode the text: ENCODEURL. Please encode the message only. Your final URL may look like this:

https://script.google.com/macros/s/LongLongKeyGoesHere…/exec?msg=Hellooooo%20There&chat_id=-650350317

Hellooooo%20There = encoded string. The actual message is “Hellooooo There”.

To get your text encoded simply use this formula:

=ENCODEURL("Hellooooo There")

Put your message inside this formula and see how text is encoded.

Telegram API may change in the future. It now supports these HTML tags:

<b>Bold</b>
<i>Italic</i>
<a href="https://twitter.com/max__makhrov">URL</a>
<code>Code inside text</code>
<pre>Code</pre>

Try these texts and see what message you’ll get.

One important tag is not supported by Telegram, but I’ve implemented it into the script:

<br>

?? This one will create a new line. Please try:

Thanks for reading!<br>Max

Finally to send a message try one of the following formulas:

=IMPORTXML(
"https://script.google.com/macros/s/AKfyc...VnFp/exec?msg="&if(C3>500;"Hey sum is > 500!"&C3;"") &
"&chat_id=13246789";"/table/row")

or

=IMPORTDATA(
"https://script.google.com/macros/s/AKfyc...VnFp/exec?msg="&if(C3>500;"Hey sum is > 500!"&C3;"") &
"&chat_id=13246789")

You’ll need to change the Web App URL and chat_id, and now that’s all!

Ten articles before and after

Monitor Server with Telegram Bot and Python – Telegram Group

How to create a Telegram bot with Python in under 10 min! – Telegram Group

Телеграм бот для уведомлений об ордерах Binance – Telegram Group

IntruderDet —An Intruder Detection Bot for my Appartment – Telegram Group

Send APK automatically to Telegram using Dart/Flutter – Telegram Group

How to Create a Telegram Chatbot in 2022 – Telegram Group

Telegram Bot 跟我想的不一樣. 第一天進公司時,Slack就被邀進同事們訂便當的群組,在上面會宣布今天訂那一家便… – Telegram Group

TRX1 Dev Blog #11 (November 2021) – Telegram Group

Serverless Telegram bot with Kotlin, Firebase and Google Cloud Functions – Telegram Group

How To: Deploy Java Telegram Bot to Heroku – Telegram Group