为什么我的Facebook bot不再重播所有向我的页面发送消息的人

  • 本文关键字:消息 Facebook bot 不再 php
  • 更新时间 :
  • 英文 :


我的Facebook bot仅回复页面作者,但没有页面作者,它没有回复其他正在向我的页面发送消息的答案。我找不到任何解决方案。:

  <?php  
      $challenge = $_REQUEST['hub_challenge'];
      $verify_token = $_REQUEST['hub_verify_token'];
      $accessToken = "mytokem is here";
      // Set this Verify Token Value on your Facebook App 
      if ($verify_token === 'Verifytoken') {
         echo $challenge;
      }
     $input = json_decode(file_get_contents('php://input'), true);
     // Get the Senders Graph ID
     $sender = $input['entry'][0]['messaging'][0]['sender']['id'];
     // Get the returned message
     $message = $input['entry'][0]['messaging'][0]['message']['text'];
     echo $message;
     //API Url and Access Token, generate this token value on your Facebook App Page
     $url = 'https://graph.facebook.com/v2.6/me/messages?         access_token='.$accessToken;
     //Initiate cURL.
      $ch = curl_init($url);
     //The JSON data.
     $jsonData = '{
        "recipient":{
             "id":"' . $sender . '"
         }, 
         "message":{
             "text":"hello user"
         }
      }';
      //Tell cURL that we want to send a POST request.
      curl_setopt($ch, CURLOPT_POST, 1);
      //Attach our encoded JSON string to the POST fields.
      curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
      //Set the content type to application/json
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:           application/json'));
      //Execute the request but first check if the message is not empty.
      if(!empty($input['entry'][0]['messaging'][0]['message'])){
          $result = curl_exec($ch);
       }

在测试模式下您的FB bot应用程序?您的FB应用程序已获得Facebook批准。如果在测试中进行应用,则只有管理员或测试仪才能使用bot。

您必须在机器人向世界开放之前进行审核过程,并准备与任何人聊天。

最新更新