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

前端 未结 2 551
北恋
北恋 2021-01-21 01:42

I have relatively simple Facebook Messenger bot in php for research purposes:

$access_token = \"xxxxxxx\";
$challenge = $_REQUEST[\'hub_challenge\'];
$verify_tok         


        
相关标签:
2条回答
  • 2021-01-21 02:17

    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
    
    0 讨论(0)
  • 2021-01-21 02:28

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

    0 讨论(0)
提交回复
热议问题