Problem with Telegram Webhook Using Google Apps Script

44 views
Skip to first unread message

Bowo Work

unread,
Jun 20, 2024, 3:54:16 AM (9 days ago) Jun 20
to Google Apps Script Community
So basically, I created a Telegram bot to add data sent from Telegram to a spreadsheet. I created a few bots, and all of them work fine with almost identical scripts. These bots send data in private messages to the bot, which then stores all the data in a spreadsheet.

Now, I am trying to create a similar bot, but in this case, the users will send data from a group, not privately. The problem I am facing is with the webhook. I use the same webhook function:

function setWebhook() {
    var url = telegramUrl + "/setWebhook?url=" + urlPublish;
    var response = UrlFetchApp.fetch(url);
    Logger.log("Webhook Response: " + response.getContentText());
}

In private, it works perfectly. However, in a group, after 30-40 minutes, the bot stops responding. When I check the webhook info using:

https://api.telegram.org/botTOKENHERE/getWebhookInfo

I find the problem. Initially, after running the script, the response looks like this:

{
"ok": true,
"result": {
"url": "https://script.google.com/macros/s/XXXXXXXX/exec",
"has_custom_certificate": false,
"pending_update_count": 0,
"max_connections": 40,
"ip_address": "216.58.206.46"
}
}

But after 30-40 minutes, the URL value changes to:

{
"ok": true,
"result": {
"url": "https://technical-webhook.fun:8443/webhook/XXXXX",
"has_custom_certificate": false,
"pending_update_count": 0,
"max_connections": 40,
"ip_address": "188.114.96.3"
}
}

Can someone please help me understand what is happening?

Badhesh Chauhan

unread,
Jun 27, 2024, 10:20:41 AM (2 days ago) Jun 27
to Google Apps Script Community
What I imagine it's not possible auto change webhook url you can deeply check May be some code or your token compromise and someone doing this
Message has been deleted
Message has been deleted
Message has been deleted

Alex

unread,
Jun 28, 2024, 11:12:09 AM (20 hours ago) Jun 28
to Google Apps Script Community
Bowo

Change the group to supergroup and assign your bot as an admin

Also you have to use doPost and don't return ContentService! 
Reply all
Reply to author
Forward
0 new messages