fix: Fixes reply-to in WhatsApp Cloud API (#13467)

This change https://github.com/chatwoot/chatwoot/pull/13371 broke the
functionality. When a user replies to a WhatsApp message, the reply
context wasn't being properly stored in Chatwoot due to #13371

WhatsApp sends reply messages with a `context` field containing the
original message ID:
```json
{
    "messages": [{
      "context": {
        "from": "phone_number",
        "id": "wamid.ORIGINAL_MESSAGE_ID"
      },
      "from": "phone_number",
      "id": "wamid.REPLY_MESSAGE_ID",
      "text": { "body": "This is a reply" }
    }]
  }
```
However, the in_reply_to_external_id was being overridden when building
the message because content_attributes was explicitly set to either {
external_echo: true } or {}, which discarded the reply-to information.
This commit is contained in:
Pranav
2026-02-06 14:01:01 -08:00
committed by GitHub
parent 0e30e3c00a
commit 6a7cbcf5ba
3 changed files with 70 additions and 9 deletions

View File

@@ -175,6 +175,9 @@ class Whatsapp::IncomingMessageBaseService
end
def create_message(message, source_id: nil)
content_attrs = outgoing_echo ? { external_echo: true } : {}
content_attrs[:in_reply_to_external_id] = @in_reply_to_external_id if @in_reply_to_external_id.present?
@message = @conversation.messages.build(
content: message_content(message),
account_id: @inbox.account_id,
@@ -184,8 +187,7 @@ class Whatsapp::IncomingMessageBaseService
status: outgoing_echo ? :delivered : :sent,
sender: outgoing_echo ? nil : @contact,
source_id: (source_id || message[:id]).to_s,
content_attributes: outgoing_echo ? { external_echo: true } : {},
in_reply_to_external_id: @in_reply_to_external_id
content_attributes: content_attrs
)
end