a big greetings to all, I'm a little ask, since I like to dig into google first. but this time I can not find anything that can solve or direct me.
I am developing a bot for facebook in very simple php, what I need is for the person that sent a message, something similar to this: "Attention SRES, I need help with my TDC, my ID is ....." , the same read it, take that message and create a ticket, and respond to the user something like: "Thanks for writing so-and-so ..."
Already create my app on developers.facebook.com generate my access_token and my verify_token, configure the Webhooks and tick the corresponding boxes, and also subscribe the page that will receive the messages and the bot will respond. also what it says of revision for app of messenger, that is to say everything what it gives me to configure in google as tutorial I have seen.
I've even taken several github codes and watched several videos from youtube and none of them send me the message, and the webhooks accepts the response url, let's say everything as it should be.
One of the last codes used was this:
if (isset($_GET['hub_verify_token'])) { if ($_GET['hub_verify_token'] === 'xxxxx') { echo $_GET['hub_challenge']; return; } else { echo 'Invalid Verify Token'; return; } } /* receive and send messages */ $input = json_decode(file_get_contents('php://input'), true); if (isset($input['entry'][0]['messaging'][0]['sender']['id'])) { $sender = $input['entry'][0]['messaging'][0]['sender']['id']; //sender facebook id $message = $input['entry'][0]['messaging'][0]['message']['text']; //text that user sent $url = 'https://graph.facebook.com/v2.6/me/messages?access_token=xxxxxx'; /*initialize curl*/ $ch = curl_init($url); /*prepare response*/ $jsonData = '{ "recipient":{ "id":"' . $sender . '" }, "message":{ "text":"You said, ' . $message . '" } }'; /* curl setting to send a json post data */ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); if (!empty($message)) { $result = curl_exec($ch); // user will get the message } }
I would like to advise you if there is another option of the facebok api, if this type of code no longer works, since it is the most seen on the web.
I've used other apis such as twitter (I can even read normal DM teet answer them and interact with the user as if a human answered him.), Instagram has managed to send msj of promotions, but with the one of facebook took two days and does not answer any message.
Please, I would greatly appreciate the help, I have not asked many questions in this forum, if something is wrong, please let me know ...
Thank you very much, regards.