How To Create A Facebook Messenger Bot Using Laravel

Submitted by azazqadir - 1 year ago

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:

$fb_message = file_get_contents("message.txt");
$fb_message = json_decode($fb_message);
$rec_id = $fb_message->entry[0]->messaging[0]->sender->id; //Sender's ID
$rec_msg= $fb_message->entry[0]->messaging[0]->message->text; //Sender's Message
$data_to_send = array(
'recipient'=> array('id'=>"$rec_id"), //ID to reply
'message' => array('text'=>"Hi I am Test Bot") //Message to reply
$options_header = array ( //Necessary Headers
'http' => array(
'method' => 'POST',
'content' => json_encode($data_to_send),
'header' => "Content-Type: application/json\n"
$context = stream_context_create($options_header);

Ads cover the costs of maintaining Laravel-tricks

comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks