netflie / whatsapp-cloud-api

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform
https://netflie.es/portfolio/whatsapp-business-cloud-api-php-sdk/
MIT License
449 stars 163 forks source link

New types of conversation category break the webhook processing. #110

Closed muniter closed 1 year ago

muniter commented 1 year ago

Facebook rolled out today June 1 conversation based pricing and with it the category types.

https://developers.facebook.com/docs/whatsapp/updates-to-pricing

Therefore it started sengind this data in the webhooks:

{
    "object": "whatsapp_business_account",
    "entry": [
        {
            "id": "108536708899139",
            "changes": [
                {
                    "value": {
                        "messaging_product": "whatsapp",
                        "metadata": {
                            // redacted
                            "display_phone_number": "5XXXXXXXXXXX",
                            // redacted
                            "phone_number_id": "1XXXXXXXXXXXXXX"
                        },
                        "statuses": [
                            {
                                "id": "wamid.HBgMNTczMjEyMjMyNzczFQIAERgSMzE3RUQ4MTdDQzU2OTZDRTRDAA==",
                                "status": "delivered",
                                "timestamp": "1685626673",
                                // redacted
                                "recipient_id": "5XXXXXXXXXXX",
                                "conversation": {
                                    "id": "d488be6b630353e08249383a9a699f64",
                                    "origin": {
                                        "type": "authentication"
                                    }
                                },
                                "pricing": {
                                    "billable": true,
                                    "pricing_model": "CBP",
                                    "category": "authentication"
                                }
                            }
                        ]
                    },
                    "field": "messages"
                }
            ]
        }
    ]
}

This makes the webhook->read() throw erros not recognizing the type of conversation.


[2023-06-01 13:37:59][LOGGED_OUT][req-64789f37982b5][error][UnexpectedValueException] UnexpectedValueException: Value 
'authentication' is not part of the enum Netflie\WhatsAppCloudApi\WebHook\Notification\Support\ConversationType in /ap
p/vendor/myclabs/php-enum/src/Enum.php:245
Stack trace:
#0 /app/vendor/myclabs/php-enum/src/Enum.php(73): MyCLabs\Enum\Enum::assertValidValueReturningKey('authentication')
#1 /app/vendor/netflie/whatsapp-cloud-api/src/WebHook/Notification/Support/Conversation.php(16): MyCLabs\Enum\Enum->__
construct('authentication')
#2 /app/vendor/netflie/whatsapp-cloud-api/src/WebHook/Notification/StatusNotificationFactory.php(21): Netflie\WhatsApp
CloudApi\WebHook\Notification\Support\Conversation->__construct('d488be6b630353e...', 'authentication', NULL)
#3 /app/vendor/netflie/whatsapp-cloud-api/src/WebHook/NotificationFactory.php(33): Netflie\WhatsAppCloudApi\WebHook\No
tification\StatusNotificationFactory->buildFromPayload(Array, Array)
#4 /app/vendor/netflie/whatsapp-cloud-api/src/WebHook.php(32): Netflie\WhatsAppCloudApi\WebHook\NotificationFactory->b
uildFromPayload(Array)
#5 /app/modules/Whatsapp/controllers/DefaultController.php(44): Netflie\WhatsAppCloudApi\WebHook->read(Array)
derrickobedgiu1 commented 1 year ago

True. This needs an urgent fix

aalbarca commented 1 year ago

I don't have the possibility to perform a real test.

Can someone test the branch of this PR? CC @muniter

Does anyone know the payloads for the rest of the categories (marketing, utility, service...)? I can't find examples of payloads in the Facebook documentation.

Thanks.

derrickobedgiu1 commented 1 year ago

The PR solves all the issues. No more errors "service" and "authentication" after testing it.

aalbarca commented 1 year ago

Thanks @derrickobedgiu1 published 2.0.4 release with the fix.

muniter commented 1 year ago

Thanks!! I see the errors gone in my application after upgrading. Using service and authentication.