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   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 80 All time: 10,110 This week: 129Up
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: 279420 in Nigeria Nigeria
Week rank: 195 Up6 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 (4)  
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 (4)  /  .idea  
File Role Description
  Accessible without login Plain text file workspace.xml Data Auxiliary data

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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:80
This week:0
All time:10,110
This week:129Up