i try learning API telegram and i have some issue with ‘Parameter’ ‘link_preview_options’
https://core.telegram.org/bots/api#sendmessage
https://core.telegram.org/bots/api#sendmessage
function sendTelegramMessage(chatId, text) {
var token = "my_token";
var apiUrl = "https://api.telegram.org/bot" + token + "/sendMessage";
var payload = {
method: "post",
payload: {
chat_id: chatId,
text: text,
parse_mode: "HTML",
link_preview_options: {is_disabled: true},
},
};
var response = UrlFetchApp.fetch(apiUrl, payload);
}
I get
Exception: Request failed for https://api.telegram.org returned code 400. Truncated server response: {"ok":false,"error_code":400,"description":"Bad Request: can't parse link preview options JSON object"} (use muteHttpExceptions option to examine full response)
at sendTelegramMessage(NotifyTG:17:32)
17 var response = UrlFetchApp.fetch(apiUrl, payload);
this parameter should remove thumbnails in links from messages sent by the telegram bot
It works without ‘link_preview_options: {is_disabled: true},’
function sendTelegramMessage(chatId, text) {
var token = "my_token";
var apiUrl = "https://api.telegram.org/bot" + token + "/sendMessage";
var payload = {
method: "post",
payload: {
chat_id: chatId,
text: text,
parse_mode: "HTML",
// link_preview_options: {is_disabled: true},
},
};
var response = UrlFetchApp.fetch(apiUrl, payload);
}
2
Answers
Changed this part:
On this
Now it works and I don't know why =/
You may need to serialize the link_preview_options object: