Download the PHP package torgodly/messenger-bot without Composer
On this page you can find all versions of the php package torgodly/messenger-bot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download torgodly/messenger-bot
More information about torgodly/messenger-bot
Files in torgodly/messenger-bot
Package messenger-bot
Short Description Facebook Messenger webhooks and Page comments for Laravel (BotMan-style API, no BotMan dependency).
License MIT
Homepage https://packagist.org/packages/torgodly/messenger-bot
Informations about the package messenger-bot
torgodly/messenger-bot
Facebook Messenger webhooks for Laravel (messages, postbacks, quick replies, feed comments). API similar to BotMan (hears, payload, onComment) without BotMan.
PHP 8.3+ · Laravel 12 or 13
Install
One Facebook Page (default): the command above writes the usual .env keys, validates the token when possible, and subscribes webhooks. You do not configure tenant resolution.
Several Pages (multi-tenant): use the same install command with flags so .env is filled for you—no custom resolver class is required:
(--model= is optional in interactive mode; you can add MESSENGER_BOT_TENANCY_CONNECTION_MODEL later.) The package resolves incoming webhooks by loading that Eloquent model where facebook_page_id matches the Page ID (override column with MESSENGER_BOT_TENANCY_PAGE_ID_COLUMN). Set MESSENGER_BOT_TENANCY_RESOLVER only if you need a fully custom lookup.
Configure
| Env / setting | Purpose |
|---|---|
APP_URL |
Public base URL (no trailing slash). |
MESSENGER_BOT_APP_ID, MESSENGER_BOT_APP_SECRET |
Meta app. |
MESSENGER_BOT_VERIFY_TOKEN |
Same string in Meta → Webhooks → Verify Token. |
MESSENGER_BOT_PAGE_ACCESS_TOKEN |
Optional; leave empty and use OAuth for production. |
MESSENGER_BOT_TENANCY_ENABLED, MESSENGER_BOT_TENANCY_CONNECTION_MODEL |
Multi-tenant mode and the Eloquent model used for Page → tenant mapping (see install --tenant). |
Meta — Facebook Login: add redirect URI (exact match):
https://YOUR-DOMAIN/messenger-bot/oauth/facebook/callback
(or MESSENGER_BOT_OAUTH_REDIRECT_URI if set)
Meta — Webhooks (Page): callback https://YOUR-DOMAIN/webhook/messenger (or MESSENGER_BOT_WEBHOOK_PATH), same verify token.
Webhook and OAuth routes are registered outside the web middleware group (no CSRF 419 on Meta POSTs). Set MESSENGER_BOT_AUTO_REGISTER_ROUTES=false only if you register the webhook route yourself.
Usage — handlers
Register once at boot (e.g. App\Providers\AppServiceProvider::boot() or routes/web.php):
Priority (higher runs first): MessengerBot::hears('pattern', $handler, priority: 10);
Get Started: register payload() for MESSENGER_BOT_GET_STARTED_PAYLOAD or set MESSENGER_BOT_GET_STARTED_REPLY for a default when no handler matches.
Usage — OAuth (single Page)
Open in browser (as Page admin):
https://YOUR-DOMAIN/messenger-bot/oauth/facebook
Token is cached; profile sync runs on install. Clear with php artisan messenger-bot:clear-page-token.
Usage — multi-tenant
-
Database row per Page — an Eloquent model implements
MessengerBot\Contracts\MessengerConnectableand usesMessengerBot\Laravel\Concerns\InteractsWithMessengerConnection. By default it readstenant_id, primary key (oridcolumn) for the connection id, andfacebook_page_idfor the Graph Page id. OverridemessengerTenantIdColumn(),messengerConnectionKeyColumn(), ormessengerFacebookPageIdColumn()if your columns differ. -
Turn it on —
php artisan messenger-bot:install --tenant --model=Your\\Modelor setMESSENGER_BOT_TENANCY_ENABLED=trueandMESSENGER_BOT_TENANCY_CONNECTION_MODEL=Your\\Model. Webhooks then load that model withwhere(facebook_page_id, <Page id from Meta>). If no row matches, legacy behaviour depends onMESSENGER_BOT_TENANCY_FALLBACK_LEGACY/MESSENGER_BOT_TENANCY_SKIP_UNRESOLVED(see config comments). -
OAuth — after the user is logged into your app, send them to Facebook with the connectable model so the callback can store the token for that row:
-
Posts and background jobs — same object everywhere:
- Inside webhook handlers — optional active resolution:
MESSENGER_BOT_OAUTH_DUAL_WRITE_LEGACY (default true) also fills the legacy global token cache for tools that still expect a single Page. MESSENGER_BOT_OAUTH_REQUIRE_MT_SIGNATURE=false is for local debugging only. Swap ConnectionTokenRepository in the container if you store tokens in the database instead of cache.
Usage — multi-tenant (advanced)
MESSENGER_BOT_TENANCY_RESOLVER— bind a class implementingMessengerBot\Kernel\Contracts\TenantResolverwhen the default Eloquent lookup is not enough.MessengerBot\Laravel\Tenancy\EloquentMessengerTenantResolver— optional base class if you prefer a dedicated resolver class over config-onlyconnection_model(seestubs/eloquent_messenger_tenant_resolver.php.stub).- Raw OAuth query params —
tenant_id,connection_id,mt_sigwheremt_sigishash_hmac('sha256', $tenantId."\n".$connectionId, config('messenger-bot.app_secret')); the package signs these for you viaMessengerOAuth.
Usage — Page posts (Graph)
Inject MessengerBot\Kernel\Contracts\SyncsFacebookPagePosts.
Single-tenant: tenancy off; forConnectable() still works with any object implementing MessengerConnectable (stable keys + Page id). Legacy token must match pageId when a legacy page_id is cached.
Invalidate post list cache:
Background refresh (raw keys or connectable):
Example DB migration stub: stubs/migrations/create_mb_connections_table.php.stub.
Artisan
| Command | Purpose |
|---|---|
messenger-bot:install |
Publish config, .env keys, token check, subscribe, menu. |
messenger-bot:install --tenant [--model=] |
Same as above plus multi-tenant .env defaults (MESSENGER_BOT_TENANCY_*). |
messenger-bot:sync-page |
Re-subscribe webhook fields, persistent menu. |
messenger-bot:token-status |
Cached token / expiry hint. |
messenger-bot:clear-page-token |
Clear legacy cached Page token. |
--skip-token-check on install/sync skips Graph GET /me.
Events
WebhookReceived, MessageReceived, PostbackReceived, CommentCreated, PostsSynced, PostsCacheHit, PostsCacheMiss, plus outgoing send events.
References
- Messenger templates (use methods on
Bot). - README-EXTERNAL-RULES.md — store tenant rules and menus in your app (examples).
- CHANGELOG.md
403 webhook: wrong app secret vs Meta, or leave MESSENGER_BOT_SIGNATURE_ENABLED=false only in local tests.
All versions of messenger-bot with dependencies
ext-json Version *
illuminate/support Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/routing Version ^12.0|^13.0
illuminate/events Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.0
illuminate/cache Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/bus Version ^12.0|^13.0
illuminate/queue Version ^12.0|^13.0