Reputation: 11
I followed this website on setting up a webhook between my Telegram Bot and Apps Script webapp. I setup the webhook according to the guide and deploy the webapp. Nothing happens when I send any message to the bot (the bot is supposed to echo the message). The app receives no POST request (at least according to the logger) when I do so, indicating a problem with the webhook.
For testing purposes, the webApp simply echoes whatever message the bot receives back to the sender.
I setup the webhook by visiting
https://api.telegram.org/bot{API_TOKEN}/setWebHook?url={CURRENT_WEB_APP_URL}
and get a "webhook is set" message in response.
I then deploy the webapp and send one "test" message to the bot. No response from the bot, and nothing logged in the built in logger. Sending a getWebhookInfo yields the following:
ok true
result
url "https://script.google.com/macros/s/XXXXXXXXXXXXXX/exec"
has_custom_certificate false
pending_update_count 0
max_connections 40
function doPost(e)
{
Logger.log(e);
var contents = JSON.parse(e.postData.contents);
var id = contents.message.from.id;
var userID = contents.message.from.username;
var text = contents.message.text.split(' ');
var name = contents.message.from.first_name;
sendMessage(id, text);
}
function sendMessage(id, text)
{
var url = telegramAPI + "/sendMessage?chat_id="+id+"&text"+text;
var response = UrlFetchApp.fetch(url);
}
function setWebhook()
{
var url = telegramAPI + "/setWebhook?url="+webAppUrl;
var response = UrlFetchApp.fetch(url);
Logger.log(response);
}
I expect the bot to reply but nothing happens. Any clue on what's wrong?
Upvotes: 1
Views: 2177
Reputation: 11
var url = telegramAPI + "/sendMessage?chat_id="+id+"&text"+text;
Added "=" to "&text" and it worked. Sorry for wasting your time.
Upvotes: 0