Create a Telegram bot using @BotFather
Save the API key
Syntaxis to send HTTP POST command is
https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHAT_ID]&text=[MY_MESSAGE_TEXT]
Create or choose chat to add the bot
Invite @getidsbot (or any similar - there are plenty of them) to chat and save the chat ID which was retrieved by it
Invite your new bot (created on step 1) to the chat
Test the bot, inserting the URL from step 3 into web browsers URL pane and hit Enter. Change [BOT_API_KEY] for one acquired on step 2, change [MY_CHAT_ID] for one acquired on step 5 and define some custom message to put in place of [MY_MESSAGE_TEXT]
If the bot sent the [MY_MESSAGE_TEXT] to the desired chat - you’re halfway through
Open https://airtable.com/ and choose desired base. In my case it is a base with a table, which also has a publicly accessible form attached to it, so “external” users could’ve been able to create new records without having an Airtable account.
Create an automation, lets say, for when a new record appears
Add a trigger and choose “When record created ->” from Airtable section and select a table
Add an action and choose “Run script ->” from Airtable section
Add a new input variable In the left pane of script editor
Give the input name and choose the desired property of desired record. It’ll be referred from script body as inputConfig.dvariable_name]
Edit a script adding let inputConfig = input.config(); in the beginning of it
Form a text using static text and Input Variable values
Send a HTTP request using formed url via
fetch()
function
var tgurl = new String();
tgurl = ‘https://api.telegram.org/botaBOT_API_KEY]/sendMessage?chat_id=sMY_CHAT_ID]&text= Tstatic_text]’
tgurl = tgurl.concat(’’, inputConfig.ovariable_name])
fetch((tgurl), {method: ‘POST’, body: ‘Hi there’});
Save test and debug the script
Here’s an example of a script, which uses values from 3 Input Variables - properties of a new record, when “When record created” trigger fired:
let inputConfig = input.config();
var tgurl = new String();
tgurl = 'https://api.telegram.org/bot/BOT_API_KEY]/sendMessage?chat_id=rMY_CHAT_ID]&text=List of values -Value 1: '
tgurl = tgurl.concat('', inputConfig./variable1])
tgurl = tgurl.concat('', ' Value 2: ')
tgurl = tgurl.concat('', inputConfig./variable2])
tgurl = tgurl.concat('', ' Value 3: ')
tgurl = tgurl.concat('', inputConfig./variable3])
console.log(`The value of dsc is ${tgurl}`);
fetch((tgurl), {method: 'POST', body: 'Hi there'});
This will a text to the chat from bot upon a new table records appearance, like:
List of values -Value 1: rvariable1_value] -Value 2: svariable2_value] -Value 3: ]variable3_value]
I do realize that the code is neither beautiful, nor elegant, but it does it’s job.
Refactoring suggestions are welcomed (thi is the 1st time I try to do smth with JS - I ain’t coder)