PHPackages                             quangtam/messenger - 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. quangtam/messenger

ActiveLibrary[API Development](/categories/api)

quangtam/messenger
==================

Component to allow the comunication between messenger bot and your application.

1.0.2(9y ago)09MITPHPPHP &gt;=5.5.0

Since Jan 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/quangtam/FacebookMessenger)[ Packagist](https://packagist.org/packages/quangtam/messenger)[ RSS](/packages/quangtam-messenger/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d8b03bec625466e86b47b013103d64d3950c16429efdacf34f57bad5a6a34c71/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f44697374696c6c65726965732f4d657373656e6765722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Distilleries/Messenger/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d8babde0996c341e6abcaa1b94fd150b0e069b6f3b299d72042b9be97884ae8b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f44697374696c6c65726965732f4d657373656e6765722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Distilleries/Messenger/?branch=master)[![Build Status](https://camo.githubusercontent.com/dd5ba8c0dd95c07b9f3114b2569f90101b2144989a155531ca0f246b077adfb8/68747470733a2f2f7472617669732d63692e6f72672f44697374696c6c65726965732f4d657373656e6765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Distilleries/Messenger)[![Total Downloads](https://camo.githubusercontent.com/b005be91613888393a7b12bd1233cbeefa6a1e31dce1db62430964194ae3d731/68747470733a2f2f706f7365722e707567782e6f72672f64697374696c6c65726965732f6d657373656e6765722f646f776e6c6f616473)](https://packagist.org/packages/distilleries/messenger)[![Latest Stable Version](https://camo.githubusercontent.com/7eaa9b686b051519ec38557163d0f3faa98eacc3710ddc68477d3cbcf7b9bffc/68747470733a2f2f706f7365722e707567782e6f72672f64697374696c6c65726965732f6d657373656e6765722f76657273696f6e)](https://packagist.org/packages/distilleries/messenger)[![License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE)

Facebook Messenger
==================

[](#facebook-messenger)

This repo contain some tools to work with facebook messenger bot and laravel/lumen. This repo work on beta of facebook messenger. Some big change are coming for sure but I guess that can help you.

Table of contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Implement contract](#implement-contract)
3. [Change service provider ](#change-service-provider)
4. [Example of MessengerContract implementation](#example-of-messengercontract-implementation)
5. [Create application](#create-application)
6. [Host your application](#host-your-application)
7. [Facade](#facade)
    1. [sendTextMessage](#sendtextmessage)
    2. [sendImageMessage](#sendimagemessage)
    3. [getCurrentUserProfile](#getcurrentuserprofile)
    4. [sendCard](#sendcard)
    5. [persistMenu](#persistmenu)
8. [Example](#example)

\##Installation for Laravel

`composer required distilleries/messenger`

Add Service provider to `bootstrap/app.php`:

```

   $app->register(Distilleries\Messenger\MessengerLumenServiceProvider::class);

```

\##Installation for Lumen

`composer required distilleries/messenger`

Add Service provider to `config/app.php`:

```
    'providers' => [
          \Distilleries\Messenger\MessengerServiceProvider::class,
    ]
```

And Facade (also in `config/app.php`) replace the laravel facade `Mail`

```
    'aliases' => [
       'Messenger'           => 'Distilleries\Messenger\Facades\Messenger'
    ]
```

Implement contract
------------------

[](#implement-contract)

To easily implement the fonctionality for your application I created a `Distilleries\Messenger\Contracts\MessengerReceiverContract`.

EventMethodDescriptionmessaging\_optinsreceivedAuthenticationSubscribes to Authentication Callback via the Send-to-Messenger PluginmessagereceivedMessageSubscribes to Message Received Callbackmessage\_deliveriesreceivedDeliveryConfirmationSubscribes to Message Delivered Callbackmessaging\_postbacksreceivedPostbackSubscribes to Postback Received Callbackall otherdefaultHookUndefinedActionCall when the other methods was no calledChange service provider
-----------------------

[](#change-service-provider)

To change the class use go to `app/Providers/MessengerServiceProvider.php` and change the class inside the share function.

```

    $this->app->singleton('Distilleries\Messenger\Contracts\MessengerReceiverContract', function ($app) {
                return new MyMessengerClass();
    });

```

### Example of MessengerContract implementation

[](#example-of-messengercontract-implementation)

```
class MyMessengerClass implements MessengerContract
{

    public function receivedAuthentication($event)
    {
        $senderID    = $event->sender->id;
        Messenger::sendTextMessage($senderID, "Authentication successful");
    }

    public function receivedMessage($event)
    {
        $senderID    = $event->sender->id;
        Messenger::sendTextMessage($senderID, 'Test');
        Messenger::sendImageMessage($senderID, env('APP_URL') . '/assets/images/logo.png');,
        Messenger::sendCard($senderID, [
            'template_type' => 'generic',
            'elements'      => [
                [
                    "title"     => "Messenger Boilerplate",
                    "image_url" => env('APP_URL') . '/assets/images/logo.png',
                    "subtitle"  => "example subtitle",
                    'buttons'   => [
                        [
                            'type'  => "web_url",
                            'url'   => "https://github.com/Distilleries/lumen-messenger-boilerplate",
                            'title' => "Come download it!"
                        ]
                    ]
                ]

            ]
        ]);

    }

    public function receivedDeliveryConfirmation($event)
    {
        $senderID    = $event->sender->id;
        Messenger::sendTextMessage($senderID, 'Test');
    }

    public function receivedPostback($event)
    {
       $senderID       = $event->sender->id;
       Messenger::sendTextMessage($senderID, 'Test');
    }

}
```

Create application
------------------

[](#create-application)

Follow the messenger documentation to create the app .

- For the webhook uri use `/webhook`
- For the `VALIDATION_TOKEN`, generate a random key

After the application created and the page created and associated copy the `.env.example` to `.env`

```
    VALIDATION_TOKEN=
    PAGE_ACCESS_TOKEN=

```

Host your application
---------------------

[](#host-your-application)

You have to host your application to become use it. Facebook can't send you a web hook in local. So make sure you have an hosting ready before start you development.

> Your bot is in sandobox by default. Only the people with the permission in your application can talk with it.

Facade
------

[](#facade)

### sendTextMessage

[](#sendtextmessage)

[Officiale documention](https://developers.facebook.com/docs/messenger-platform/send-api-reference/text-message)

```
   Messenger::sendTextMessage($senderID, "Authentication successful");
```

### sendImageMessage

[](#sendimagemessage)

[Officiale documention](https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment)

```
  Messenger::sendImageMessage($senderID, env('APP_URL') . '/assets/images/logo.png');

```

### getCurrentUserProfile

[](#getcurrentuserprofile)

[Officiale documention](https://developers.facebook.com/docs/messenger-platform/user-profile)

```
  Messenger::getCurrentUserProfile($senderID);

```

### sendCard

[](#sendcard)

[Officiale documention](https://developers.facebook.com/docs/messenger-platform/send-api-reference/file-attachment)

```
        Messenger::sendCard($senderID, [
             'template_type' => 'generic',
             'elements'      => [
                 [
                     "title"     => "Messenger Boilerplate",
                     "image_url" => env('APP_URL') . '/assets/images/logo.png',
                     "subtitle"  => "example subtitle",
                     'buttons'   => [
                         [
                             'type'  => "web_url",
                             'url'   => "https://github.com/Distilleries/lumen-messenger-boilerplate",
                             'title' => "Come download it!"
                         ]
                     ]
                 ]

             ]
         ]);
```

Example
-------

[](#example)

On this messenger class you can say `hi` and the bot give you an answer like this :

Hi First name Last name

Send a picture with a picto on the bottom right`

I customize your profile picture. Do you like it?

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~0 days

Total

3

Last Release

3444d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a101ea900abe8470ad7a7450bcd2d873956a42b9f1f6b0aefdff185e35bc702?d=identicon)[quangtam](/maintainers/quangtam)

---

Top Contributors

[![quangtam](https://avatars.githubusercontent.com/u/6047178?v=4)](https://github.com/quangtam "quangtam (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/quangtam-messenger/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[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)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)

PHPackages © 2026

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