Skip to main content

Hi all.

Perhaps someone can help me.

I need help from someone who understands the Telegram API.

Below is the code of a script which should work under certain conditions in Automations and send a message to a Telegram user via bot in an open chat with some data from the table.

At the moment the script sends an error


error_code: 400
description: "Bad Request: message text is empty"

The script works fine in the sandbox and sends messages. Not in Airtable.

Perhaps the problem is related to Airtable and its specific variables?

How do you think it is possible to solve this problem.

On Stack Owerflow people occasionally write about this problem, but their solutions have not helped me.

I would be grateful for an answer.


const token = 'ххх';
let inputConfig = input.config();
let message = `${inputConfig.first_name}, документ готов по заказу №${inputConfig.order}.<br>Вы можете скачать его <a href = "${inputConfig.doc_link}"по ссылке</a>.<br>Ждем Вас снова.<br>Ваш, RealEstate DocuService`;
console.log(`${message}`);
const options = {
method: 'POST',
Host: 'api.telegram.org:443',
headers: {
Accept: 'application/json',
'User-Agent': 'Airtable',
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: `${message}`,
parse_mode: 'HTML',
disable_web_page_preview: true,
disable_notification: true,
reply_to_message_id: 0,
chat_id: `${inputConfig.chat_id}`
})
};
fetch(`https://api.telegram.org/bot${token}/sendMessage?chat_id=${inputConfig.chat_id}`)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

HI @NikPaw

Do you have all of the input.config variables set up on the script?


HI @NikPaw

Do you have all of the input.config variables set up on the script?



were the variables first_name, order, doc_link, chat_id

All of them are well displayed by console.log




were the variables first_name, order, doc_link, chat_id

All of them are well displayed by console.log



Hm Nik, looks like you’re not sending the options


Could you replace:


fetch(`https://api.telegram.org/bot${token}/sendMessage?chat_id=${inputConfig.chat_id}`)

with:


fetch(`https://api.telegram.org/bot${token}/sendMessage?chat_id=${inputConfig.chat_id}`, options)

And see whether that works?


Hm Nik, looks like you’re not sending the options


Could you replace:


fetch(`https://api.telegram.org/bot${token}/sendMessage?chat_id=${inputConfig.chat_id}`)

with:


fetch(`https://api.telegram.org/bot${token}/sendMessage?chat_id=${inputConfig.chat_id}`, options)

And see whether that works?


@Adam_TheTimeSavingCo you have helped me a lot.

Thank you very much for the tip.

I somehow thought that options was for tying additional parameters like ?=param=‘Yes’ into the link

Now it really works. The script sends the message through the bot.

✨ 🕺


Reply