Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A forwarded message does not contain an ID in the message context #94

Closed
angelomelonas opened this issue Mar 7, 2023 · 8 comments
Closed
Labels
released The feature was released in some version

Comments

@angelomelonas
Copy link
Contributor

angelomelonas commented Mar 7, 2023

First of all, thank you for this excellent library!

I would like to report a bug that I found. If a voice note (media message) is forwarded, it does not contain the id field in $message['context']['id'], resulting in the following exception:

{
  "message": "Uncaught PHP Exception TypeError: \"Netflie\\WhatsAppCloudApi\\WebHook\\Notification\\Support\\Context::__construct(): Argument #1 ($replying_to_message_id) must be of type string, null given, called in /app/vendor/netflie/whatsapp-cloud-api/src/WebHook/Notification/MessageNotificationFactory.php on line 131\" at /app/vendor/netflie/whatsapp-cloud-api/src/WebHook/Notification/Support/Context.php line 13",
  "context": {
    "exception": {
      "class": "TypeError",
      "message": "Netflie\\WhatsAppCloudApi\\WebHook\\Notification\\Support\\Context::__construct(): Argument #1 ($replying_to_message_id) must be of type string, null given, called in /app/vendor/netflie/whatsapp-cloud-api/src/WebHook/Notification/MessageNotificationFactory.php on line 131",
      "code": 0,
      "file": "/app/vendor/netflie/whatsapp-cloud-api/src/WebHook/Notification/Support/Context.php:13"
    }
  }
}

Would a solution be to make the id field in the Context object optional? Then the code would be:

$notification->withContext(new Support\Context(
    $message['context']['id'] ?? null,
    $message['context']['forwarded'] ?? false,
    $referred_product ?? null
));

I'd be happy to open a pull request for this 👍🏼

@aalbarca
Copy link
Contributor

I think maybe the problem could be that the field is message_id instead of id, could you send me a trace of the raw response sent by Facebook?

Thanks!

@aalbarca
Copy link
Contributor

Any news @angelomelonas ?

@angelomelonas
Copy link
Contributor Author

Hi @aalbarca! My apologies, I was recently moving, so I was not able to have another look at this. I'll get back to you ASAP.

@angelomelonas
Copy link
Contributor Author

angelomelonas commented Mar 23, 2023

It does indeed seem like the id (or message_id) field is missing from the context when a message (text/media) is forwarded. The following is an example of a voice message that was forwarded:

array:2 [
  "object" => "whatsapp_business_account"
  "entry" => array:1 [
    0 => array:2 [
      "id" => "101194536240516"
      "changes" => array:1 [
        0 => array:2 [
          "value" => array:4 [
            "messaging_product" => "whatsapp"
            "metadata" => array:2 [
              "display_phone_number" => "..."
              "phone_number_id" => "101573099534713"
            ]
            "contacts" => array:1 [
              0 => array:2 [
                "profile" => array:1 [
                  "name" => "..."
                ]
                "wa_id" => "..."
              ]
            ]
            "messages" => array:1 [
              0 => array:6 [
                "context" => array:1 [
                  "forwarded" => true
                ]
                "from" => "..."
                "id" => "..."
                "timestamp" => "1679567250"
                "type" => "audio"
                "audio" => array:4 [
                  "mime_type" => "audio/ogg; codecs=opus"
                  "sha256" => "9/6n0ir1ABZwjZeyr3nHuXPFlkwQsG2SgmZDpLSi7Kw="
                  "id" => "6610964145599458"
                  "voice" => false
                ]
              ]
            ]
          ]
          "field" => "messages"
        ]
      ]
    ]
  ]
]

And a normal forwarded text message:

array:2 [
  "object" => "whatsapp_business_account"
  "entry" => array:1 [
    0 => array:2 [
      "id" => "101194536240516"
      "changes" => array:1 [
        0 => array:2 [
          "value" => array:4 [
            "messaging_product" => "whatsapp"
            "metadata" => array:2 [
              "display_phone_number" => "..."
              "phone_number_id" => "101573099534713"
            ]
            "contacts" => array:1 [
              0 => array:2 [
                "profile" => array:1 [
                  "name" => "..."
                ]
                "wa_id" => "..."
              ]
            ]
            "messages" => array:1 [
              0 => array:6 [
                "context" => array:1 [
                  "forwarded" => true
                ]
                "from" => "..."
                "id" => "..."
                "timestamp" => "1679567488"
                "text" => array:1 [
                  "body" => "some forwarded text"
                ]
                "type" => "text"
              ]
            ]
          ]
          "field" => "messages"
        ]
      ]
    ]
  ]
]

@angelomelonas angelomelonas changed the title A forwarded voice note does not contain an ID in the message context A forwarded message does not contain an ID in the message context Mar 28, 2023
@angelomelonas
Copy link
Contributor Author

angelomelonas commented Mar 29, 2023

Have you perhaps had a moment to look at the response, @aalbarca? 😄

@aalbarca
Copy link
Contributor

Could you maybe open a PR with the fix? 🙏

@angelomelonas
Copy link
Contributor Author

@aalbarca pull request #100 😄

@aalbarca
Copy link
Contributor

Fixed on 2.0.3 release. Thanks @angelomelonas for the PR ;)

@aalbarca aalbarca added the released The feature was released in some version label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released The feature was released in some version
Projects
None yet
Development

No branches or pull requests

2 participants