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

ActiveLibrary[API Development](/categories/api)

mangoweb/messenger
==================

Facebook Messenger PHP interface

v1.2.0(9y ago)153802[1 issues](https://github.com/manGoweb/Messenger/issues)MITPHPPHP &gt;=7.0

Since Oct 6Pushed 9y ago17 watchersCompare

[ Source](https://github.com/manGoweb/Messenger)[ Packagist](https://packagist.org/packages/mangoweb/messenger)[ Docs](https://github.com/mangoweb/messenger)[ RSS](/packages/mangoweb-messenger/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

Messenger PHP
=============

[](#messenger-php)

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

[](#installation)

Use composer:

```
$ composer require mangoweb/messenger
```

Usage
-----

[](#usage)

[![Example screencast](doc/screencast.gif)](doc/screencast.gif)

The `PAGE_ACCESS_TOKEN` must be Facebook Page `access_token` with `pages_messaging` permission. `RECIPIENT_ID` is different for each Facebook App, Page and User.

### Sending messages

[](#sending-messages)

```
use Mangoweb\Messenger\Page;
use Mangoweb\Messenger\PageSender;
use Mangoweb\Messenger\Message;
use Mangoweb\Messenger\CardElement;
use Mangoweb\Messenger\Button;
use Mangoweb\Messenger\QuickReply;

$page = new Page(PAGE_ACCESS_TOKEN);
$sender = new PageSender($page);

// Sending simple text message
$textMessage = Message::text('Hello world!');
$sender->send(RECIPIENT_ID, $textMessage);

// Sending an image attachment
$imageMessage = Message::image('https://unsplash.it/400/300');
$sender->send(RECIPIENT_ID, $imageMessage);

// Sending complex message with two cards and some button
$cardButtons = [
	Button::url('Github', 'https://github.com/manGoweb/Messenger')
];

$cards = [
	CardElement::create('Lorem', 'ipsum dolor', 'https://github.com/manGoweb/Messenger', 'https://unsplash.it/400/300?random', $cardButtons),
	CardElement::create('Foo', NULL, NULL, 'https://unsplash.it/400/300?random')
];

$messageWithCards = Message::generic($cards);
$sender->send(RECIPIENT_ID, $messageWithCards);
```

### Thread management

[](#thread-management)

```
use Mangoweb\Messenger\Page;
use Mangoweb\Messenger\Greeting;
use Mangoweb\Messenger\GetStartedButton;
use Mangoweb\Messenger\PersistentMenu;
use Mangoweb\Messenger\Button;

$page = new Page(PAGE_ACCESS_TOKEN);

// Detect if page is already hooked to your Facebook App
echo ($page->isHookedToApp(APP_ID) ? 'already hooked' : 'not yet hooked') . "\n";

// Load basic info about a Page
$info = $page->loadInfo();
echo $info['name'] . "\n";

// Load info about user as the Page can see them
$profile = $page->loadProfile(RECIPIENT_ID);
echo $profile['first_name'] . ' ' . $profile['last_name'] . "\n";

// Set greeting text
$page->setGreeting(Greeting::text('Hello world'));

// Set "get started" button payload
$page->setGetStartedButton(GetStartedButton::payload('1'));

// Set persistent menu buttons
$page->setPersistentMenu(PersistentMenu::buttons([
	Button::postback('Help', 'help'),
	Button::postback('Sign in', 'sign-in'),
]));
```

### Receiving messages

[](#receiving-messages)

```
use Mangoweb\Messenger\Receiver;

$receiver = new Receiver();

// Define event hooks
$receiver->onMessage[] = function($message) {
	echo "Someone sent us a message" . "\n";
	var_dump($message);
};

$receiver->onPostback[]  = function($postback) {
	echo "Someone clicked on a postback button" . "\n";
	var_dump($postback);
};

// Load JSON payload from Messenger request
$httpBody = file_get_contents('php://input');
/*
$httpBody = '{
	"object":"page",
	"entry":[
		{
			"id":"PAGE_ID",
			"time":1458692752478,
			"messaging":[
				{
					"sender":{
						"id":"USER_ID"
					},
					"recipient":{
						"id":"PAGE_ID"
					},
					"timestamp":1458692752478,
					"message":{
						"mid":"mid.1458696618141:b4ef9d19ec21086067",
						"seq":51,
						"attachments":[
							{
								"type":"image",
								"payload":{
									"url":"IMAGE_URL"
								}
							}
						]
					}
				}
			]
		}
	]
}';
*/
$payload = json_decode($httpBody, TRUE);

// Process the payload
$receiver->processBody($payload);
```

Tests
-----

[](#tests)

Add `tests/php.ini` (you may use the templates `php-unix.ini` or `php-win.ini`).

In `tests/local.php` you can define constants for testing real API calls (you may use the template `local.sample.php`)

```
$ ./vendor/bin/tester -c tests/php.ini tests
```

License
-------

[](#license)

MIT. See full [license](license.md).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community13

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

Total

3

Last Release

3472d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/136dc45567e352da93d3341284618066ce34b24679a9f853947fb3c23ceb033d?d=identicon)[viliamkopecky](/maintainers/viliamkopecky)

---

Top Contributors

[![ViliamKopecky](https://avatars.githubusercontent.com/u/316435?v=4)](https://github.com/ViliamKopecky "ViliamKopecky (54 commits)")

---

Tags

botscomposerfacebookmessengerfacebookMessenger

### Embed Badge

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

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

###  Alternatives

[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[facebook/php-ads-sdk

PHP SDK for Facebook Business

9014.1M8](/packages/facebook-php-ads-sdk)[kerox/messenger

PHP Library to interact with Facebook Messenger Platform

58302.1k1](/packages/kerox-messenger)[casperlaitw/laravel-fb-messenger

A Laravel Package to Integrate Facebook Messenger API

10631.5k](/packages/casperlaitw-laravel-fb-messenger)[tgallice/fb-messenger-sdk

Facebook Messenger Bot php sdk

9315.2k](/packages/tgallice-fb-messenger-sdk)[joelbutcher/facebook-graph-sdk

Facebook SDK for PHP

42728.5k1](/packages/joelbutcher-facebook-graph-sdk)

PHPackages © 2026

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