PHP Classes

How to Interact with Facebook Users Using a Basic PHP Facebook Messenger Bot: Exchange messages with Facebook Messenger users

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 79 This week: 2All time: 10,091 This week: 96Up
Version License PHP version Categories
basic-facebook-bot 1.0The PHP License5PHP 5, Chat, Social Networking
Description 

Author

This class can exchange messages with Facebook Messenger users.

It can process the contents of a message received by a Facebook Messenger bot script and returns the message sender's Facebook user identifier and the message text.

The class can also send a message to a Facebook user via Facebook Messenger.

Picture of uche
Name: uche <contact>
Classes: 9 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 279819 in Nigeria Nigeria
Week rank: 27 Up4 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 7x

Example

<?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


  Files folder image Files  
File Role Description
Files folder image.idea (1 file)
Files folder imageclasses (2 files)
Accessible without login Plain text file index.php Example Example script

  Files folder image Files  /  .idea  
File Role Description
  Accessible without login Plain text file workspace.xml Data Auxiliary data

  Files folder image Files  /  classes  
File Role Description
  Plain text file botClass.php Class Class source
  Accessible without login Plain text file constants.php Conf. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:79
This week:2
All time:10,091
This week:96Up