How to create a Facebook (FB) Messenger bot using Cloudways Laravel
Cloud Platform. Name the app whatever you wish. Then, scroll down and
enter your Web ID. Click Skip Quick Start.
Now, enter your email address. Choose an appropriate category for your
chat bot.
Click Create App ID.
Once you’re done with the above steps, follow the steps below.
Source:
http://www.cloudways.com/blog/set-up-facebook-messenger-bot-in-cloudways/
<?php
$token = "YOUR TOKEN GOES HERE";
file_put_contents("message.txt",file_get_contents("php://input"));
$fb_message = file_get_contents("message.txt");
$fb_message = json_decode($fb_message);
$rec_id = $fb_message->entry[0]->messaging[0]->sender->id;
$rec_msg= $fb_message->entry[0]->messaging[0]->message->text;
$data_to_send = array(
'recipient'=> array('id'=>"$rec_id"),
'message' => array('text'=>"Hi I am Test Bot")
);
$options_header = array (
'http' => array(
'method' => 'POST',
'content' => json_encode($data_to_send),
'header' => "Content-Type: application/json\n"
)
);
$context = stream_context_create($options_header);
file_get_contents("https://graph.facebook.com/v2.6/me/messages?access_token=$token",false,$context);
?>