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_updatesBooleanOptionalPass 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
| Code | Error | Cause |
|---|---|---|
| 401 | Unauthorized | Invalid bot token — double-check the token passed to Bot("") |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
deleteWebhookis idempotent. Calling it when no webhook is set returnsTruewithout error — safe to call during any startup/reset sequence.drop_pending_updates: trueis 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 passfalse) if you want to process accumulated messages.- You must delete the webhook before using
getUpdates. If an active webhook is registered,getUpdatesreturns an error. Always calldeleteWebhookfirst 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
getWebhookInfoto inspect the current state. Before deleting, you can callgetWebhookInfoto confirm whether a webhook is active and how many pending updates exist. - GramIO handles webhook lifecycle in
bot.start(). When you callbot.start()for long polling mode, GramIO automatically removes any existing webhook. ManualdeleteWebhookcalls are mainly needed in scripts or migration utilities.
See Also
- setWebhook — register a webhook URL
- getWebhookInfo — inspect the current webhook configuration
- getUpdates — long polling alternative to webhooks
- Webhook guide — full guide for setting up webhooks with GramIO