> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# On Messenger message received

> Starts when someone sends a Facebook Page a Messenger message.

`metaAds.onMessengerMessageReceived` starts when someone sends a selected Facebook Page a Messenger message.

```ts automations/meta-ads-on-messenger-message-received.automation.ts theme={null}
import { automation } from "automate.ax"
import { metaAds } from "automate.ax/meta-ads"

export default automation("Acknowledge Messenger leads", () => {
  const message = metaAds.onMessengerMessageReceived({ pageId: "page-id" })
  metaAds.sendMessengerMessage({
    pageId: message.pageId,
    recipientId: message.senderId,
    text: "Thanks for your message! We'll reply shortly.",
  })
})
```

Messages the Page sends, read receipts, reactions, and button taps don't start the trigger. Optional `account` selects a static project account binding.

The event includes:

* `senderId`, the person's Page-scoped ID (PSID); pass it as `recipientId` to reply
* `pageId`, `recipientId`, `messageId`, and `timestamp` in Unix milliseconds
* `text`, `attachments` with each `type` and provider `payload`, and `quickReplyPayload`
* `replyToMessageId` when the person replies to a specific message
* `referral` when the message comes from a Click-to-Messenger ad, with `adId`, `source`, `type`, `ref`, and `adsContextData`

Each `messageId` starts at most one run. The trigger needs `pages_manage_metadata`, `pages_messaging`, and `pages_show_list`. Until the app has Advanced Access, Meta only delivers messages from people with a role on the Meta app.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.