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

PHP Fatal error: Uncaught Netflie\WhatsAppCloudApi\Response\ResponseException #87

Closed derrickobedgiu1 closed 1 year ago

derrickobedgiu1 commented 1 year ago

Hello, I've observed a glitch in the list message functionality but I can't seem to trace the line throwing this error. Apparently, all the fields are working fine except the footer for the LIST Message. It looks like you made it compulsory not to be NULL but the DOC has it as an Optional field. When I pass in the footer value I get the success message but when I don't I get an error message. Have a look at it below:

[03-Feb-2023 20:07:06 UTC] PHP Fatal error:  Uncaught Netflie\WhatsAppCloudApi\Response\ResponseException in /***********/vendor/netflie/whatsapp-cloud-api/src/Response.php:150
Stack trace:
#0 /*************/vendor/netflie/whatsapp-cloud-api/src/Client.php(62): Netflie\WhatsAppCloudApi\Response->throwException()
#1 /****************/vendor/netflie/whatsapp-cloud-api/src/WhatsAppCloudApi.php(278): Netflie\WhatsAppCloudApi\Client->sendMessage()
#2 /**********/public_html/*******/test.php(29): Netflie\WhatsAppCloudApi\WhatsAppCloudApi->sendList()
#3 {main}
  thrown in /*************/vendor/netflie/whatsapp-cloud-api/src/Response.php on line 150

I'm hoping the asterisks won't affect your identification of the issue as I did it to protect the path to my online directory The error is for List Messages feature only

aalbarca commented 1 year ago

This is an error thrown by WhatsApp server. You have to debug the response: https://github.com/netflie/whatsapp-cloud-api#message-response

derrickobedgiu1 commented 1 year ago

I've checked and it's saying the footer is required. I don't know why it's returning the error because I'm able to make a successful Option List message to a user with the footer nulled out with the payload below:

$data = [
    "messaging_product" =>"whatsapp",
    "recipient_type" => "individual",
    "to" => "256742**********",
    "type" => "interactive",
    "interactive" => [
        "type" => "list",
        "header" => [
            "type" => "text",
            "text" => "Header"
        ],
        "body" => [
            "text" => "Text content here"
        ],
        // "footer" => [
        //     "text" => "Footer Here"
        // ],
        "action" => [
            "button" => "CHOOSE",
            "sections" => [
                [
                    "title" => "Sec Title",
                    "rows" => [
                        [
                            "id" => "1",
                            "title" => "Sec 1",
                            "description" => "Desc1"
                        ]
                    ]
                ],
                [
                    "title" => "Sec 2 Title",
                    "rows" => [
                        [
                            "id" => "2",
                            "title" => "Sec 2",
                            "description" => "Desc2"
                        ]
                    ]
                ],
                // add more sections as needed
            ]
        ]
    ]
];

Meanwhile part of the error log returned by nulling the footer with the Netflie API:

[body:protected] => {"error":{"message":"(#100) The parameter interactive['footer']['text'] is required.","type":"OAuthException","code":100,"fbtrace_id":"AQt9fAy0KqzZdoGp4PwuGzf"}} [decoded_body:protected] => Array ( [error] => Array ( [message] => (#100) The parameter interactive['footer']['text'] is required. [type] => OAuthException [code] => 100
donmbelembe commented 1 year ago

I just faced an issue with the sendList too, my issue was that my footer string was too long, Actually whastapp return the error description but the Netflie\WhatsAppCloudApi\Response->throwException() does not take that message in consideration.

below is the whatsapp response after dumping it

Netflie\WhatsAppCloudApi\Response^ {#1644
  #http_status_code: 400
  #headers: array:19 [
    "Vary" => array:2 [
      0 => "Origin"
      1 => "Accept-Encoding"
    ]
    "x-business-use-case-usage" => array:1 [
      0 => "{"106809675644000":[{"type":"whatsapp","call_count":1,"total_cputime":1,"total_time":1,"estimated_time_to_regain_access":0}]}"
    ]
    "x-fb-rlafr" => array:1 [
      0 => "0"
    ]
    "Content-Type" => array:1 [
      0 => "text/javascript; charset=UTF-8"
    ]
    "WWW-Authenticate" => array:1 [
      0 => "OAuth "Facebook Platform" "invalid_request" "(#131009) Parameter value is not valid""
    ]
    "Access-Control-Allow-Origin" => array:1 [
      0 => "*"
    ]
    "facebook-api-version" => array:1 [
      0 => "v15.0"
    ]
    "Strict-Transport-Security" => array:1 [
      0 => "max-age=15552000; preload"
    ]
    "Pragma" => array:1 [
      0 => "no-cache"
    ]
    "Cache-Control" => array:1 [
      0 => "no-store"
    ]
    "Expires" => array:1 [
      0 => "Sat, 01 Jan 2000 00:00:00 GMT"
    ]
    "x-fb-request-id" => array:1 [
      0 => "ATZX1Vrfh60IR4qiGNENI4T"
    ]
    "x-fb-trace-id" => array:1 [
      0 => "HOPjUckcrum"
    ]
    "x-fb-rev" => array:1 [
      0 => "1006914144"
    ]
    "X-FB-Debug" => array:1 [
      0 => "HmAOwbu2xnfbdsQfXaw95gBkR7i+XsVGIwAl5X3uFnfDjIt68aB/YLa9RnAPBxH7AnDtrq5yJ0TwIMIS1ymogw=="
    ]
    "Date" => array:1 [
      0 => "Sat, 04 Feb 2023 19:49:48 GMT"
    ]
    "Transfer-Encoding" => array:1 [
      0 => "chunked"
    ]
    "Alt-Svc" => array:1 [
      0 => "h3=":443"; ma=86400"
    ]
    "Connection" => array:1 [
      0 => "keep-alive"
    ]
  ]
  #body: "{"error":{"message":"(#131009) Parameter value is not valid","type":"OAuthException","code":131009,"error_data":{"messaging_product":"whatsapp","details":"Footer text length invalid. Min length: 1, Max length: 60"},"error_subcode":2494010,"fbtrace_id":"ATZX1Vrfh60IR4qiGNENI4T"}}"
  #decoded_body: array:1 [
    "error" => array:6 [
      "message" => "(#131009) Parameter value is not valid"
      "type" => "OAuthException"
      "code" => 131009
      "error_data" => array:2 [
        "messaging_product" => "whatsapp"
        "details" => "Footer text length invalid. Min length: 1, Max length: 60"
      ]
      "error_subcode" => 2494010
      "fbtrace_id" => "ATZX1Vrfh60IR4qiGNENI4T"
    ]
  ]
  #request: Netflie\WhatsAppCloudApi\Request\MessageRequest\RequestOptionsListMessage^ {#1629
    -access_token: "EABTwT5HWCO8BAEZCdXUpxBayrGzYEnq9xGus0EzfQ37I4haBZBXN11WO5VoupgX8AYYSC5kyxhH0PoKTKa5TmTVEPA4V6ya1bXcwjK3s2fLuD2oB0ZC6iIW8Bv2ZA19d9nRyQFoNCdPaW5EiLZBfIvtZAghSUmYJo09LslJ0N2rFUOWdVXhphY"
    -timeout: 60
    #message: Netflie\WhatsAppCloudApi\Message\OptionsListMessage^ {#1628
      -messaging_product: "whatsapp"
      -recipient_type: "individual"
      -to: "243904094051"
      #type: "list"
      -header: "Rate your experience"
      -body: "Thanks for your time"
      -footer: "Please consider rating your shopping experience in our website"
      -action: Netflie\WhatsAppCloudApi\Message\OptionsList\Action^ {#1595
        #button: "Submit"
        #sections: array:1 [
          0 => Netflie\WhatsAppCloudApi\Message\OptionsList\Section^ {#1600
            #title: "Stars"
            #rows: array:5 [
              0 => Netflie\WhatsAppCloudApi\Message\OptionsList\Row^ {#1598
                #id: "1"
                #title: "⭐️"
                #description: "Experience wasn't good enough"
              }
              1 => Netflie\WhatsAppCloudApi\Message\OptionsList\Row^ {#1603
                #id: "2"
                #title: "⭐⭐️"
                #description: "Experience could be better"
              }
              2 => Netflie\WhatsAppCloudApi\Message\OptionsList\Row^ {#1606
                #id: "3"
                #title: "⭐⭐⭐️"
                #description: "Experience was ok"
              }
              3 => Netflie\WhatsAppCloudApi\Message\OptionsList\Row^ {#1607
                #id: "4"
                #title: "⭐⭐️⭐⭐"
                #description: "Experience was good"
              }
              4 => Netflie\WhatsAppCloudApi\Message\OptionsList\Row^ {#1608
                #id: "5"
                #title: "⭐⭐️⭐⭐⭐️"
                #description: "Experience was excellent"
              }
            ]
          }
        ]
      }
    }
    -from_phone_number_id: "103532992643000"
  }
}
aalbarca commented 1 year ago

@derrickobedgiu1 fixed in 2.0.2 release. You can now pass the footer argument as an empty string.

Thanks for reporting the bug :)