Preventing Duplicate Telegram Webhook Processing in Yii2 With an Idempotent Queue
A Telegram booking flow can break when a webhook handler runs slow external calls, such as PDF generation or CRM syncs, inside the request lifecycle. Telegram treats slow or failed responses as lost and resends the same update, sometimes for up to 24 hours, which can cause duplicate bookings and notifications. The recommended fix is to split handling into a fast synchronous step that verifies authenticity and drops duplicates, followed by asynchronous processing by queue workers. Yii2's default CSRF protection rejects Telegram's requests, so it should be disabled only on the webhook controller and replaced with verification of the X-Telegram-Bot-Api-Secret-Token header. Requests lacking a valid token should receive a 403 response before the body is parsed, with hash_equals() used to guard the comparison.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in