PHPackages                             davidpiesse/facebook\_messenger\_php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. davidpiesse/facebook\_messenger\_php

AbandonedLibrary[API Development](/categories/api)

davidpiesse/facebook\_messenger\_php
====================================

A PHP wrapper for the Facebook Messenger Platform

0.2.7(9y ago)731569MITPHP

Since Jul 27Pushed 7y ago6 watchersCompare

[ Source](https://github.com/davidpiesse/facebook_messenger_php)[ Packagist](https://packagist.org/packages/davidpiesse/facebook_messenger_php)[ RSS](/packages/davidpiesse-facebook-messenger-php/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Currently abandoned - Please use Marcel's Botman.io (its much better)
=====================================================================

[](#currently-abandoned---please-use-marcels-botmanio-its-much-better)

Facebook Messenger PHP Wrapper
==============================

[](#facebook-messenger-php-wrapper)

This package is a wrapper around the majority of the functionality of the Facebook Messenger platform. A list of features not yet implemented is below.

This package is still in development; so please do submit pull requests / issues you are having.

Installation
------------

[](#installation)

Just use compser to bring it in.

```
composer require davidpiesse/facebook_messenger_php
```

Currently we are in dev mode so you may need to set `minimum-stability:"dev"` in your composer.json

Demo
----

[](#demo)

A demo project (Laravel based) is [here](https://github.com/davidpiesse/messenger-bot)In the meantime you can interact with a demo ChatBot created using this wrapper.

Search for **@laravelmessengerbot** in Facebook messenger and you can test a load of the function. Or go here

Todo
----

[](#todo)

Things still to implement

- User Profile
- All Airline Templates
- Sending of a file stream
- Payments

Current dependencies are GuzzleHttp/Guzzle, rappasoft/laravel-helpers and illuminate/http. These allow the package to make easy requests to the FB Messenger API and also deal with arrays in a super amazing way.

License
-------

[](#license)

MIT

Who to call for help
--------------------

[](#who-to-call-for-help)

Just add an issue or send me an email at piesse \[at\] gmail \[dot\] com or on Twitter @mapdev

\#Sending Messages

Usage
-----

[](#usage)

To send messages to a user create an instance of the Messenger class and insert your token

```
$messenger = new Messenger($token);
```

and then to send a text message

```
$messenger->sendMessage(new TextMessage('Foo Bar'),'recipient_id');
```

[Facebook API Link](https://developers.facebook.com/docs/messenger-platform/send-api-reference)

Still writing this...

Incoming Webhook
================

[](#incoming-webhook)

For Facebook Messenger you provide a webhook URL for their API to contact your server when certain events occur. [-Link-](https://developers.facebook.com/docs/messenger-platform/webhook-reference)

Most of these revolve around incoming messages from a user; be it a text message, attachment, postback etc. these are all handled by the **Callback** object.

Pass in an array of data from the post request {in Laravel use ` $request->all()`}

```
$callback = new Callback($request->all());
```

The data incoming should look similar to this

```
{
  "object":"page",
  "entry":[
    {
      "id":"PAGE_ID",
      "time":1458692752478,
      "messaging":[
        {
          "sender":{
            "id":"USER_ID"
          },
          "recipient":{
            "id":"PAGE_ID"
          },
          ...
        }
      ]
    }
  ]
}
```

The `$callback` object parses all this information and allows you to easily retrieve it and determine what to do with it.

Structure
---------

[](#structure)

Below is a guide on how to find the data you want in the Callback object Within a normal Facbook Webhook POST request are two top level parameters: +`object` (always = `'page'`) +`entry` (almost always one &amp; a collection of `Entry` objects)

To get at the data you must iterate `$callback->entries` to make sure you do not miss a batch of messages.

The Callback also has three methods `textMessages()`, `postbackMessages()`, and `attachmentMessages()`. These give you quick access to an array of `EntryMessages` of these specific types.

Within an 'entry' are a couple of properties and a array of `EntryMessages`

- `id` (Page ID)
- `time` (Timestamp)
- `messaging` (Array of entry messages)

`Entry` has the first two properties plus a `message` array (Laravel Collection). This is the array of `EntryMessages`.

This array of entry messages is where all the real information is. There are two main parts to it. THe shell (EntryMessage) contains the `sender_id` and `recipient_id` along with a `timestamp`.

It also provides you a set of boolean return methods to determine what type of message it is.

- `isText()`
- `isPostback()`
- `isRead()`
- `isDelivered()`
- `isAuthentication()`
- `isAccountLinking()`
- `isEcho()`

Each of these allow you to filter the type of message it is and access its `$entry_message->message` or other dynamic property appropriately.

### Read

[](#read)

If the message is of type Read then `$entry_message->read` is set and is of type `Read`

##### Properties

[](#properties)

- `watermark`
- `seq`

### Delivered

[](#delivered)

If the message is of type Read then `$entry_message->delivery` is set and is of type `Delivered`

##### Properties

[](#properties-1)

- `watermark`
- `seq`
- `mids[]`

### Authentication

[](#authentication)

If the message is of type Read then `$entry_message->authentication` is set and is of type `Authentication`

##### Properties

[](#properties-2)

- `ref`

### Account Linking

[](#account-linking)

If the message is of type Read then `$entry_message->account_linking` is set and is of type `AccountLinking`

##### Properties

[](#properties-3)

- `status`
- `authorization_token`
- `linked` (bool)
- `unlinked` (bool)

### Postback

[](#postback)

If the message is of type Read then `$entry_message->postback` is set and is of type `POstback`

##### Properties

[](#properties-4)

- `payload`

### Message

[](#message)

If the message is of type Read then `$entry_message->message` is set and is of type `Message`

##### Properties

[](#properties-5)

- `mid`
- `seq`
- `isText` (bool)
- `isSticker` (bool)
- `hasAttachments` (bool)
- `text`
- `quick_reply`
- `attachments[]`

### Echo

[](#echo)

The same as `$entry_message->message` except with some more properties attached.

##### Additional Properties

[](#additional-properties)

- `app_id`
- `mid`
- `metadata` (bool)
- `seq` (bool)

Examples
========

[](#examples)

Here are some code snippets to get you started

```
//create a callback object
$callback = new Callback($request->all())
```

```
//get all textmessages from the callback (regardless of entry or EntryMessage)
$textmessages = $callback->textMessages(); //returns Entry Message collection
```

```
//check if EntryMessage $entrymessage is a postback and return the payload string
if($entrymessage->isPostback)
    return $entrymessage->postback->payload;
```

```
//get URL of an image attachment sent to you 0- assuming onely one attachment and entry etc.
if($entrymessage->isMessage){
    if($entrymessage->message->hasAttachments && ($entrymessage->message->attachments[0]->isImage){
        $image_url = $entrymessage->message->attachments[0]->url;
    }
}
```

As Laravel Collection is iuncluded it is a great way to delve into your callback easily

```
$callback = new Callback($request->all())
$callback->entries->each(function ($entry){
    //for each entry access their entry messages
    $entry->messages->each(function($entrymessage){
        //get sender_id to send a message back
        $sender_id = $entrymessage->sender_id;
        //for each entry message check is a postback or a message
        if($entrymessage->isPostback){
            //Do something with the postback
            $payload = $entrymessage->postback->payload;
        }else if($entrymessage->isMessage){
            //do somethingwith the message
            $message = $entrymessage->message;
        }
    });
});
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~96 days

Total

2

Last Release

3527d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9beea64e2348d11d5f96d4138ccfcf393bab92e803faa27437d794c279575d20?d=identicon)[davidpiesse](/maintainers/davidpiesse)

---

Top Contributors

[![davidpiesse](https://avatars.githubusercontent.com/u/800650?v=4)](https://github.com/davidpiesse "davidpiesse (16 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davidpiesse-facebook-messenger-php/health.svg)

```
[![Health](https://phpackages.com/badges/davidpiesse-facebook-messenger-php/health.svg)](https://phpackages.com/packages/davidpiesse-facebook-messenger-php)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.5M923](/packages/statamic-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[flat3/lodata

OData v4.01 Producer for Laravel

99346.1k](/packages/flat3-lodata)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.1k1](/packages/jasara-php-amzn-selling-partner-api)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
