Why Webhooks?
Lower Latency
Updates arrive instantly without polling delays
Lower Load
No constant connections to Telegram’s servers
Scalable
Works well with serverless platforms and load balancers
Cost-Effective
Reduced bandwidth and compute costs
Basic Setup
Framework Integration
grammY supports many web frameworks:- Express
- Fastify
- Koa
- Node HTTP
Serverless Platforms
Cloudflare Workers
Deno Deploy
Vercel
Webhook Configuration
Security
Secret Token Verification
HTTPS Requirement
Telegram only sends webhooks to HTTPS URLs. For local development, use tunneling tools like ngrok, Cloudflare Tunnel, or Serveo.
Local Development with Tunneling
Using ngrok
Health Checks
Managing Webhooks
Error Handling
Best Practices
Use Secret Tokens
Always verify webhook requests with secret tokens
Handle Gracefully
Return 200 OK even if your handler fails to prevent retries
Keep URLs Secret
Use your bot token as part of the webhook path
Monitor Webhook Info
Regularly check
getWebhookInfo() for errorsTroubleshooting
Webhook not receiving updates
Webhook not receiving updates
- Verify your URL is accessible from the internet
- Check that you’re using HTTPS with a valid certificate
- Ensure your server responds quickly (under 60 seconds)
- Check
getWebhookInfo()for error messages
SSL certificate errors
SSL certificate errors
- Use a valid SSL certificate from a trusted CA
- Self-signed certificates must be uploaded via
setWebhook - Check certificate expiration
Updates delayed or dropped
Updates delayed or dropped
- Check your
max_connectionssetting - Ensure your server responds within 60 seconds
- Monitor webhook info for pending update count
- Consider scaling your infrastructure