Search code examples
telegramwebhookstelegram-bot

Querying existing webhooks


An existing application has webhooks set up with the Telegram API.

A newer application want to use the same bot to send messages, eventually with the same named action webhook.

Initially, one would want to first query existing webhooks to identify existing ones, then possibly delete them, based on the increasing complexity of the operating context. The telegram API documentation does not appear to have methods for such actions.

A) can one query one's bot webhooks and delete them?

In any instance, the new server will have its own certificate for TLS communications.

curl -F "url=https://b.example.online/<WEBHOOKLOCATION>" https://api.telegram.org/bot<YOURTOKEN>/setWebhook

B) If one sets a new webhook with the same action (or webhooklocation in Telegram-speak) name, does that kill the existing ones, say

curl -F "url=https://a.example.online/<WEBHOOKLOCATION>" https://api.telegram.org/bot<YOURTOKEN>/setWebhook

or will the notifications be sent to two webhooks (i.e. the combination of certified URL and action name are considered a unique object) ?

C) what happens to the basic webhooks /start /help etc. ? Are they responded to by the Telegram servers if webhooks not present? Again, can they have multiple certified domain destinations to the same action


Solution

  • One avenue is to revoke the token @BotFather which probably kills the related webhooks. The new token allows webhook creation anew.

    There is a deleteWebhook action though not documented at the official documentation link

    Through trial an error, the conclusion is that only one webhook exists per bot. Having set different webhooks for different apps with the same bot, only the last one is active (the old one is deleted).