Home

Awesome

PHPFaceBot

PHPFaceBot is a framework that provides all the groundwork to create a Facebook Messenger Bot app in PHP.

To use this, you'll need to have a web server running Apache, with PHP 5.3+. See system requirements below for more details.

To set up a Facebook Messenger Bot now, see the instructions below.

Facebook Messenger Bot setup quick guide

Follow this documentation.

Brief steps: (after completing server setup with working Apache, see below)

  1. Create app and page.
  2. Go to the app's App Dashboard, Add Product -> Messenger.
  3. Setup webhooks.
  4. Check fields message_deliveries, messages, messaging_optins, and messaging_postbacks. Also use messaging_referrals for getting ref parameters.
  5. Get Page Access token.
  6. Subscribe App to Page.
  7. Test.

Setting up with Apache

  1. Git clone this repo in your home directory.
  2. Use the example apache config file, edit accordingly, put in your Apache vhost or conf.d directory.
  3. Run letsencrypt to get SSL certs - this is required, Facebook wants all webhooks to have SSL.
  4. (Alternatively, use Cloudflare's free plan and get SSL that way, but you need to wait 24 hours for the cert)
  5. Verify your setup by visiting your domain on browser.

Supported Messenger API features

The framework also handles:

Unsupported Messenger API features

System requirements

Required:

  1. PHP 5.3 or above
  2. Apache web server
  3. PHP module: curl - to make HTTP API requests
  4. PHP module: json - to encode/decode data to and from API

Optional:

  1. Redis - my choice of a data store (database). Optional because the demo bot can still run without it, just set REDIS_ENABLED to 0 in your config file. Some features will be disabled without it.
  2. phpiredis - my choice of a PHP Redis client. You can use a different Redis client (and modify the Redis.php wrapper code), or you can even use a different database.
  3. PHP module: POSIX - only if you want to use the built-in queue-consumer setup for sending analytics data to Mixpanel.
  4. APC - my opcode cache of choice, which also provides user cache features. (If you use PHP 5.5+, you get OPcache, which accomplishes the same thing. Similar to PHP-FPM.)

Included PHP libraries in this framework

For documentation purposes, here is the list of PHP libraries that are included in this framework. I am including their code files in this framework directly so it's not necessary to install composer or run composer updates when using this.

  1. ToroPHP - quick, simple and robust URL routing.
  2. PHPWit.ai - very simple PHP bindings for wit.ai API, for only the NLP (text processing) method.
  3. Mixpanel PHP - only needed if you want to send tracking data to Mixpanel analytics service.
  4. phpJobDaemon - only needed if you want to use the queue consumer setup for Mixpanel