PHPackages                             fakellyh/bot-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. fakellyh/bot-messenger-php

ActiveLibrary[API Development](/categories/api)

fakellyh/bot-messenger-php
==========================

A PHP library streamlining the integration and smooth utilization of the Messenger API for the development of interactive chatbots.

1.2.0(1y ago)452MITPHPPHP &gt;=8.0

Since Nov 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nombanafi/bot-messenger-php)[ Packagist](https://packagist.org/packages/fakellyh/bot-messenger-php)[ RSS](/packages/fakellyh-bot-messenger-php/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (3)Versions (6)Used By (0)

Facebook Messenger Bot
======================

[](#facebook-messenger-bot)

A PHP library streamlining the integration and smooth utilization of the Messenger API for the development of interactive chatbots.

[![Latest Stable Version](https://camo.githubusercontent.com/b7150b62ff875d1a582ce70bfce418180840df8baafe4fa326e699009a998de9/687474703a2f2f706f7365722e707567782e6f72672f66616b656c6c79682f626f742d6d657373656e6765722d7068702f76)](https://packagist.org/packages/fakellyh/bot-messenger-php) [![Total Downloads](https://camo.githubusercontent.com/f622dcf348d2d38fd0ce5ff993283f0cea53b35f487bf0a89a54aefd22f75387/687474703a2f2f706f7365722e707567782e6f72672f66616b656c6c79682f626f742d6d657373656e6765722d7068702f646f776e6c6f616473)](https://packagist.org/packages/fakellyh/bot-messenger-php) [![Latest Unstable Version](https://camo.githubusercontent.com/d69b825e5fc7b3604d7feff648896778449802c38865264d28587f2c297a62fc/687474703a2f2f706f7365722e707567782e6f72672f66616b656c6c79682f626f742d6d657373656e6765722d7068702f762f756e737461626c65)](https://packagist.org/packages/fakellyh/bot-messenger-php) [![License](https://camo.githubusercontent.com/4427c8026378d1d9c550395bd121eea431d3021b1ba9c791fd67e5073ae7f274/687474703a2f2f706f7365722e707567782e6f72672f66616b656c6c79682f626f742d6d657373656e6765722d7068702f6c6963656e7365)](https://packagist.org/packages/fakellyh/bot-messenger-php) [![PHP Version Require](https://camo.githubusercontent.com/6ca03dcd654152f2348413cdc7272d06c12732bd6a5ca4796a71335a936ccf06/687474703a2f2f706f7365722e707567782e6f72672f66616b656c6c79682f626f742d6d657373656e6765722d7068702f726571756972652f706870)](https://packagist.org/packages/fakellyh/bot-messenger-php)

Getting Started
===============

[](#getting-started)

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

[](#installation)

It is better to use composer :

```
composer require fakellyh/bot-messenger-php
```

Usage
=====

[](#usage)

Add the autoloader
------------------

[](#add-the-autoloader)

```
require_once __DIR__.'/vendor/autoload.php';
```

Create a Messenger instance
---------------------------

[](#create-a-messenger-instance)

```
use Fakell\BotMessenger\Client;
use Fakell\BotMessenger\Messenger;

$client = new Client('');
$messenger = new Messenger($client);

// Or quick instance

$messenger = Messenger::create('');
```

Send text message to user
-------------------------

[](#send-text-message-to-user)

```
$messenger->sendMessage(, "Hello world");
```

Set action status
-----------------

[](#set-action-status)

[![senderAction](assets/image/senderAction.png)](assets/image/senderAction.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Types\ActionType;

$messenger = Messenger::create();
// Mark seen last message
$messenger->setActionSatus(, ActionType::MARK_SEEN);
// Set typing on
$messenger->setActionSatus(, ActionType::TYPING_ON);
// Set typing off
$messenger->setActionSatus(, ActionType::TYPING_OFF);
```

See [here](https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions) for best practice.

Send message with quick reply
-----------------------------

[](#send-message-with-quick-reply)

[![Quick reply](assets/image/quickReply.png)](assets/image/quickReply.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Message;
use Fakell\BotMessenger\Model\QuickReply\Text;
use Fakell\BotMessenger\Model\QuickReply\UserEmail;
use Fakell\BotMessenger\Model\QuickReply\UserPhoneNumber;

$messenger = Messenger::create();
$message = new Message("Pick a size:");
$message->setQuickReplies([
    new Text("Small", "YOUR_PAYLOAD", "https://image.com"),
    new Text("Medium", "YOUR_PAYLOD"), // image url can be null
    // You can use too UserPhoneNumber and UserEmail to detect automaticly these value
    new UserPhoneNumber(),
    new UserEmail(),
])

$messenger->sendMessage(, $message);
```

Send Template Message
---------------------

[](#send-template-message)

### Generic Template

[](#generic-template)

[![Generic Template](assets/image/genericTemplate.png)](assets/image/genericTemplate.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Attachment\Template\Generic\Generic;
use Fakell\BotMessenger\Model\Attachment\Template\Generic\GenericElement;
use Fakell\BotMessenger\Model\Message;

$messenger = Messenger::create();

// Cannot exceed 10 GenericElement
$genericElement = [
    new GenericElement(
        "Summer collection 2019",
        "Featured outfit",
        "https://myimage.com/image.png"
    ),
    new GenericElement(
        "Other title",
        "I don't know",
        "https://myimage.com/image2.png", // image url can be null
    ),
];

$template = new Generic($genericElement);
$message = new Message($template);

// You add quick reply if needed
// $message->addQuickReply(...)

$messenger->sendMessage(, $message);
```

### Button Template

[](#button-template)

[![Button Template](assets/image/buttonTemplate.png)](assets/image/buttonTemplate.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Attachment\Template\Button\Button;
use Fakell\BotMessenger\Model\Button\PhoneNumber;
use Fakell\BotMessenger\Model\Button\Postback;
use Fakell\BotMessenger\Model\Button\WebUrl;
use Fakell\BotMessenger\Model\Message;

$messenger = Messenger::create();

// Check the namespace carefully  Fakell\BotMessenger\Model\Attachment\Template\Button\Button
$button = new Button("What can I do to help?",
    [
        new Postback("Get Order Satuts", "YOUR_PAYLOaD"),
        new PhoneNumber("Call Me", "+261340226111"),
        //Button can be WebUrl
        new WebUrl("Go to my site", "https://mysupersite.com")
    ]
);

$message = new Message($button);

// You add quick reply if needed
// $message->addQuickReply(...)

$messenger->sendMessage(, $message);
```

### Media Template

[](#media-template)

[![Media Template Image](assets/image/mediaTemplate-2.png)](assets/image/mediaTemplate-2.png) [![Media Template Video](assets/image/mediaTemplate-1.png)](assets/image/mediaTemplate-1.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Attachment\Template\Media\Media;
use Fakell\BotMessenger\Model\Button\Postback;

$messenger = Messenger::create();

$media = new Media(Media::TYPE_IMAGE, , [
    new Postback("I want some!")
    // 3 button max or []
])

// Just change Media::TYPE_VIDEO for video media

$message = new Message($button);

// You add quick reply if needed
// $message->addQuickReply(...)

$messenger->sendMessage(, $message);
```

### Receipt Template

[](#receipt-template)

[![Receipt Template](assets/image/ReceiptTemplate.png)](assets/image/ReceiptTemplate.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Message;
use Fakell\BotMessenger\Model\Attachment\Template\Receipt\Address;
use Fakell\BotMessenger\Model\Attachment\Template\Receipt\Receipt;
use Fakell\BotMessenger\Model\Attachment\Template\Receipt\Summary;
use Fakell\BotMessenger\Model\Attachment\Template\Receipt\Adjustment;
use Fakell\BotMessenger\Model\Attachment\Template\Receipt\RecieptElement;

$messenger = Messenger::create();

$receiptElements = [
    new RecieptElement("Classic White T-Shirt", 450, "100% Soft and Lu..", 2, "USD", "https://image.com/withe.png"),
    new RecieptElement("Classic Gray T-Shirt", 600, "100% Soft and Lu..", 1, "USD", "https://image.com/gray.png"),
];

$summary = new Summary(56.14);
$receipt = new Receipt("FIOMBONANTSOA Nombana Fahendrena", "N°001", "USD", "VISA 1232135", $receiptElements, $summary);

// Adjustement and Address is optional you can skip this if not needed
$adjustement = [
    new Adjustment("Transportation costs", 20),
    new Adjustment("Bus trasport costs", 5)
];
$adress = new Address("Miami", "city name", 20012, "State", "Madagascar", "SecondStreet or Null");
$receipt->setAdjustments($adjustement);
$receipt->setAddress($adress);

$message = new Message($receipt);

$messenger->sendMessage(, $message);
```

File, Image, Video, Audio Attachment
------------------------------------

[](#file-image-video-audio-attachment)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Attachment\Audio;
use Fakell\BotMessenger\Model\Attachment\File;
use Fakell\BotMessenger\Model\Attachment\Image;
use Fakell\BotMessenger\Model\Attachment\Video;
use Fakell\BotMessenger\Model\Message;

$messenger = Messenger::create();

// Image

// Locale file
$image = new Image("./image.png");
// or remoteFile
$image = new Image("https://image.com/fakell.png");

// I don't write in the following code the file remote from others because Image, File, Audio, Video supports a remote file
// Note that it is better to use a local file

// File
$file = new File("./myfile.txt");

// Audio
$audio = new Audio("./mysong.mp3");

// Video
$video = new Video("./myvideo.mp4");

$message = new Message($image); // You can change $image per $file, $audio, $video

$messenger->sendMessage(, $message);
```

Personas
--------

[](#personas)

[![Personas](assets/image/Personas.png)](assets/image/Personas.png)

### Personas management

[](#personas-management)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Personas\Personas;

$messenger = Messenger::create();

// Add personas

$personas = new Personas("Fakell", "https://image.com/profile.png");
$messenger->addPersonas($personas); // if successful, this will return an array containing the personas's id

// Get one personas info
$personas = $messenger->getPersonas();

// Get All personas, this will return an array Personas[]
$personasList = $messenger->getAllPersonas();

// Delete personas
$messenger->deletePersonas();
```

### Personas Usage

[](#personas-usage)

```
use Fakell\BotMessenger\Messenger;

$messenger = Messenger::create();

// Just by specifying in the third argument the id of the presonas
// You can also use in Attachment type
$messenger->sendMessage(, "Hello", );
```

Messenger Options
-----------------

[](#messenger-options)

### Persistent Menu

[](#persistent-menu)

[![Persistent Menu](assets/image/persistentMenu.jpg)](assets/image/persistentMenu.jpg)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\Button\Postback;
use Fakell\BotMessenger\Model\Button\WebUrl;
use Fakell\BotMessenger\Model\MessengerProfile\PersistentMenu\PersistentElement;
use Fakell\BotMessenger\Model\MessengerProfile\PersistentMenu\PersistentMenu;
use Fakell\BotMessenger\Types\MessengerAndroidLocales;

$elements = [
    // This is used by default if the language is not defined on the list
    new PersistentElement(
        [
            new Postback("Talk To an Agent", "YOUR_PAYLOAD"),
            new Postback("Outfit suggestions", "YOUR_PAYLOAD"),
            new WebUrl("Shop now", "https://ourwebsite.com"),
            // ...
        ],
        MessengerAndroidLocales::DEFAULT
    ),
    // This is used if the language is French
    new PersistentElement(
        [
            new Postback("Parler à un agent", "YOUR_PAYLOAD"),
            new Postback("Suggestions de tenues", "YOUR_PAYLOAD"),
            new WebUrl("Acheter maintenant", "https://ourwebsite.com/fr"),
            // ...
        ],
        MessengerAndroidLocales::FR_FR
    ),
    // See more in MessengerAndroidLocales or MessengerLocales
];

$persistentMenu = new PersistentMenu($elements);

$messenger->setMessengerOptions($persistentMenu);
```

### Greeting

[](#greeting)

You can personalize the greeting text using the person's name. You can use the following template strings:

- `{{user_first_name}}`
- `{{user_last_name}}`
- `{{user_full_name}}`

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\MessengerProfile\Greeting\Greeting;
use Fakell\BotMessenger\Model\MessengerProfile\Greeting\GreetingElement;
use Fakell\BotMessenger\Types\MessengerAndroidLocales;

$messenger = Messenger::create();

$elements = [
    // Default
    new GreetingElement("Welcome to my super page {{user_full_name}}"),
    // French Language
    new GreetingElement("Bienvenue sur ma super page {{user_full_name}}", MessengerAndroidLocales::FR_FR),
    // Spanish Language
    new GreetingElement("Bienvenido a mi súper página {{user_full_name}}", MessengerAndroidLocales::ES_ES),
    // and more ...
];

$greeting = new Greeting($elements);
$messenger->setMessengerOptions($greeting);
```

### Get Started Button

[](#get-started-button)

[![Get started](assets/image/getStarted.png)](assets/image/getStarted.png)

```
use Fakell\BotMessenger\Messenger;
use Fakell\BotMessenger\Model\MessengerProfile\GetStarted\GetStarted;

$messenger = Messenger::create();

$getStarted = new GetStarted("YOUR_PAYLOD");

$messenger->setMessengerOptions($getStarted);
```

Support
=======

[](#support)

If you think there is an actual problem in this library, please [open](https://github.com/fakellgit/bot-messenger-php/issues/new) an issue if there isn't one already created.

Author
------

[](#author)

Nombana Fahendrena FIOMBONANTSOA [Facebook](https://www.facebook.com/fakellyh)

License
=======

[](#license)

MIT

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance42

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Total

5

Last Release

482d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.2.5

1.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2cb8478afae7515af03cb8b52e7ffda62f75d99f953311d85f3d315365a985db?d=identicon)[fakellyh](/maintainers/fakellyh)

---

Top Contributors

[![nombanafi](https://avatars.githubusercontent.com/u/161061207?v=4)](https://github.com/nombanafi "nombanafi (2 commits)")

---

Tags

facebookbotMessengerbot messengerfacebook messengerconversationbot conversationmadagascar

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fakellyh-bot-messenger-php/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M736](/packages/sylius-sylius)[tgallice/fb-messenger-sdk

Facebook Messenger Bot php sdk

9315.3k](/packages/tgallice-fb-messenger-sdk)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M47](/packages/tencentcloud-tencentcloud-sdk-php)[kerox/messenger

PHP Library to interact with Facebook Messenger Platform

58318.7k1](/packages/kerox-messenger)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

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