Skip to content

deleteWebhook

Returns: TrueOfficial docs ↗

Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.

Parameters

drop_pending_updatesBooleanOptional
Pass True to drop all pending updates

Returns

On success, True is returned.

GramIO Usage

ts
// Remove webhook and preserve pending updates for processing
await 
bot
.
api
.
deleteWebhook
({});
ts
// Remove webhook and discard all queued updates (clean start)
await 
bot
.
api
.
deleteWebhook
({
drop_pending_updates
: true });
ts
// Check current webhook status, then remove if active
const 
info
= await
bot
.
api
.
getWebhookInfo
({});
if (
info
.
url
) {
console
.
log
(`Removing webhook: ${
info
.
url
}`);
await
bot
.
api
.
deleteWebhook
({
drop_pending_updates
: true });
console
.
log
("Webhook removed. Switching to long polling.");
}
ts
// Remove webhook as part of bot shutdown / maintenance script
async function 
disableWebhook
() {
await
bot
.
api
.
deleteWebhook
({
drop_pending_updates
: false });
console
.
log
("Webhook removed. Pending updates preserved for next startup.");
} await
disableWebhook
();

Errors

CodeErrorCause
401UnauthorizedInvalid bot token — double-check the token passed to Bot("")
429Too Many Requests: retry after NRate limit hit — check retry_after, use auto-retry plugin

TIP

Use GramIO's auto-retry plugin to handle 429 errors automatically.

Tips & Gotchas

  • deleteWebhook is idempotent. Calling it when no webhook is set returns True without error — safe to call during any startup/reset sequence.
  • drop_pending_updates: true is a one-way operation. All queued updates that arrived while the webhook was active are permanently discarded. Use this for a clean restart; omit it (or pass false) if you want to process accumulated messages.
  • You must delete the webhook before using getUpdates. If an active webhook is registered, getUpdates returns an error. Always call deleteWebhook first when switching to long polling mode.
  • Webhook removal does not stop your HTTP server. The Telegram API stops sending requests, but your HTTPS server continues running. You must handle the server lifecycle separately.
  • Use getWebhookInfo to inspect the current state. Before deleting, you can call getWebhookInfo to confirm whether a webhook is active and how many pending updates exist.
  • GramIO handles webhook lifecycle in bot.start(). When you call bot.start() for long polling mode, GramIO automatically removes any existing webhook. Manual deleteWebhook calls are mainly needed in scripts or migration utilities.

See Also