Fecebook Messenger Bot in PHP doesn't always respond to user

只谈情不闲聊 提交于 2019-12-01 20:32:56

This might also happen if you forget to set the content-type as well.

Only users listed as Admins or Developers or Testers in your app roles (https://developers.facebook.com/apps/YOUR_APP_ID/roles/) can interact with your chat bot webhook. It won't be available to other users unless your app is approved by Facebook and publicly available. From the Docs:

When you're ready to release your app to the public, it must go through an approval process. This will walk you through the submission process and also acceptable and unacceptable usage.

About your second question, Facebook sends an API call to your webhook in the form of JSON data which includes sender id & recipient id in the HTTP request body. But when you visit your webhook manually, you don't have those parameters in your request body so $sender will be empty in your case. And that's why the CURL request to Facebook API fails with the error "The parameter recipient is required" because "recipient":{"id":"'.$sender.'"}, will be empty.

If you want to try your webhook manually, use actual recipient id, something like:

Curl Command:

curl -i -X POST -H 'Content-Type: application/json' -d '{"object":"page","entry":[{"id":43674671559,"time":1460620433256,"messaging":[{"sender":{"id":853241244787916},"recipient":{"id":43674671559},"timestamp":1460620433123,"message":{"mid":"mid.1460620432888:f8e3412003d2d1cd93","seq":12604,"text":"Testing Chat Bot .."}}]}]}' https://YOUR_WEBHOOK_URL_HERE
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!