Bot keeps receiving duplicate voice message repeatedly from Telegram API

My Telegram bot was functioning normally until I accidentally sent an audio message. Now it’s stuck in a loop where the same voice message keeps getting delivered to my webhook endpoint over and over.

Looking at my server logs, I notice the identical message_id keeps appearing. The bot no longer processes new text messages and instead continuously receives this voice message data:

{
  "update_id": 847392158,
  "message": {
    "message_id": 42,
    "from": {
      "id": 5829471063,
      "is_bot": false,
      "first_name": "John",
      "last_name": "Smith",
      "language_code": "en"
    },
    "chat": {
      "id": 5829471063,
      "first_name": "John",
      "last_name": "Smith",
      "type": "private"
    },
    "date": 1710945672,
    "voice": {
      "duration": 5,
      "mime_type": "audio/ogg",
      "file_id": "BwACAgUAAxkBAAMcZgpnX8MxoQR8hVSj8Y-3JLqWS_mAArdPAAJqxtCYzV36q8bEfpN1CA",
      "file_unique_id": "AgADt08AAirG0Jg",
      "file_size": 52814
    }
  }
}

How can I stop this endless loop and get my bot working again?

Had this exact same issue with a different message type. Your webhook handler probably isn’t acknowledging the message to Telegram’s servers properly. You might be returning a 200 status code, but there’s likely an exception or error happening in your code before it gets there. Check if your voice message processing is throwing any unhandled exceptions. I’d wrap your message handling code in a try-catch block and make sure you’re always returning a successful response, even when processing fails. Also check if you’ve got any filters that might be silently rejecting voice messages - this can mess up the acknowledgment too.

Your webhook endpoint may be crashing or timing out when it receives the voice message, causing Telegram to continuously retry until a valid response is returned. As a quick fix, consider using the deleteWebhook method to temporarily disable your webhook, then clear any pending updates by invoking getUpdates. Ensure that your code properly handles voice messages—even if you’re ignoring them, it’s essential to process the update and send a 200 status response. I experienced a similar issue where my bot got stuck on a photo message for hours. Once I resolved the handler, I simply re-enabled the webhook.

yep, the 200 status code is crucial! if your bot doesn’t respond correctly, telegram thinks the message isn’t processed and just keeps resending it. double-check your webhook to make sure it returns that 200 after handling the voice msg.