Skip to content

Handle multiple messages in a single Meta Cloud API (and Turn.io) webhook payload #3025

@coderabbitai

Description

@coderabbitai

Bug: Webhook handlers silently drop all but the first message in a batch

Reported by: @SmittieC
Related PR: #2975
Related comment: #2975 (comment)

Description

The handle_meta_cloud_api_message Celery task (and similarly the Turn.io handler) calls MetaCloudAPIMessage.parse / TurnWhatsappMessage.parse, which is hardcoded to access only the first element of the messages array (messages[0]) in a Meta/Turn.io webhook payload.

According to Meta's API documentation, a single webhook delivery can contain multiple messages. If a webhook delivers a batch of messages, all messages after the first will be silently ignored, leading to data loss without any error or notification.

Affected code

  • apps/channels/tasks.pyhandle_meta_cloud_api_message
  • apps/channels/tasks.pyhandle_turn_message
  • apps/channels/datamodels.pyMetaCloudAPIMessage.parse / TurnWhatsappMessage.parse

Suggested Fix

Modify the task(s) to iterate over the messages array in the webhook payload and process each message individually, rather than only processing the first one.

Notes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions