> ## Documentation Index
> Fetch the complete documentation index at: https://n-a-818b4087.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Receive updates at a public HTTPS endpoint instead of polling.

Use a webhook when you want Telegram to push updates to your server. The endpoint must be publicly reachable over HTTPS.

```python theme={null}
telegram.set_webhook(
    url = 'https://example.com/webhook',
    certificate = '/path/to/certificate.pem',
    allowed_updates = ['message', 'callback_query'],
    secret_token = 'your-secret-token',
    max_connections = 40,
    drop_pending_updates = False
)
```

The certificate is optional and is only needed for a self-signed certificate. It accepts a path, bytes, or an open file object. When uploading from memory, use `certificate_file_name` to choose the name.

## Inspect and remove the webhook

```python theme={null}
print(telegram.get_webhook_info())

telegram.delete_webhook(drop_pending_updates = True)
```

## Webhooks and polling are exclusive

A webhook and `poll_updates()` cannot be used at the same time. Call `delete_webhook()` before switching back to polling.

> [!WARNING]
>
> Keep the `secret_token` private and verify Telegram's `X-Telegram-Bot-Api-Secret-Token` header in your webhook handler. Anyone who knows the endpoint URL can send requests to it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.