PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of uche   Basic PHP Facebook Messenger Bot   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Basic PHP Facebook Messenger Bot
Exchange messages with Facebook Messenger users
Author: By
Last change:
Date: 1 year ago
Size: 854 bytes
 

Contents

Class file image Download
<?php
/*Created by MmuoDev.
 */
require_once 'classes/botClass.php';
require_once
'classes/constants.php';

if (isset(
$_GET['hub_verify_token'])) {
    if (
$_GET['hub_verify_token'] === VERIFY_TOKEN) { //Token entered during setup. It is defined as a constant in constants.php
       
echo $_GET['hub_challenge'];
        return;
    } else {
        echo
'Invalid Verify Token';
        return;
    }
}
$accessToken = ACCESS_TOKEN; //Access token generated by Facebook. It is defined as a constant in constants.php.
$bot = new botClass(); //Initialize an object of the bot class
$input = json_decode(file_get_contents('php://input'), true); //JSON decode messages received
$bot->setAccessToken($accessToken);
$message = $bot->readMessage($input); //Call the method that reads messages
$bot->sendMessage($message); //Call the method that sends messages