Skip to main content
The webhookCallback function creates a callback that integrates your grammY bot with web frameworks for webhook-based deployments. Instead of long polling, webhooks allow Telegram to push updates directly to your server.

Function Signature

Bot<C>
required
Your bot instance
FrameworkAdapter | string
required
Framework adapter name or custom adapter. Built-in adapters:
  • 'express' - Express.js
  • 'koa' - Koa
  • 'fastify' - Fastify
  • 'std/http' - Deno std/http
  • 'hono' - Hono
  • 'oak' - Oak (Deno)
  • 'worktop' - Worktop (Cloudflare Workers)
  • 'cloudflare' - Cloudflare Workers
  • 'aws-lambda' - AWS Lambda
  • 'azure' - Azure Functions
  • 'vercel' - Vercel
WebhookOptions
Optional configuration for webhook behavior
Returns: Framework-specific request handler function

WebhookOptions

Configuration options for webhook handling.
'throw' | 'return' | ((...args: any[]) => unknown)
Strategy for handling request timeouts:
  • 'throw' (default) - Throw an error on timeout
  • 'return' - Return successfully on timeout
  • Function - Custom timeout handler
number
Request timeout in milliseconds. Defaults to 10000 (10 seconds).
string
Secret token for validating requests via the X-Telegram-Bot-Api-Secret-Token header. Should match the token you set when configuring the webhook.

Basic Usage

Express

Koa

Fastify

Deno (std/http)

Hono

Advanced Configuration

With Secret Token

Custom Timeout Handling

Different Paths

Cloud Platform Examples

Vercel

Cloudflare Workers

AWS Lambda

Azure Functions

Setting Up the Webhook

After deploying your webhook server, configure Telegram to send updates to it:

Webhook Best Practices

1. Use HTTPS

Telegram requires HTTPS for webhooks (except localhost for testing).

2. Validate Requests

Always use a secret token to validate incoming requests:

3. Handle Timeouts

Telegram expects responses within 60 seconds. For long-running operations, acknowledge quickly:

4. Error Handling

Implement proper error handling:

5. Monitor Health

Add health check endpoints:

Debugging Webhooks

Check Webhook Info

Delete Webhook

Test Locally with ngrok

Complete Example

See Also