> ## 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 Instagram message received

> Starts when someone sends an Instagram professional account a direct message.

`metaAds.onInstagramMessageReceived` starts when someone sends a selected Instagram professional account a direct message.

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

export default automation("Acknowledge Instagram messages", () => {
  const message = metaAds.onInstagramMessageReceived({
    instagramAccountId: "instagram-account-id",
  })
  metaAds.sendInstagramMessage({
    instagramAccountId: message.instagramAccountId,
    recipientId: message.senderId,
    text: "Thanks for your message! We'll reply shortly.",
  })
})
```

Find `instagramAccountId` with [List Instagram accounts](https://docs.automate.ax/reference/integrations/meta-ads/actions/list-instagram-accounts.md). The account must be linked to a Facebook Page the connection manages and must allow connected tools under **Settings > Messages and story replies > Message controls > Connected Tools > Allow access to messages**. Messages the account sends don't start the trigger, and messages a person removes start [On Instagram message deleted](https://docs.automate.ax/reference/integrations/meta-ads/triggers/on-instagram-message-deleted.md) instead. Optional `account` selects a static project account binding.

The event includes:

* `senderId`, the person's Instagram-scoped ID (IGSID); pass it as `recipientId` to reply
* `instagramAccountId`, `recipientId`, `messageId`, and `timestamp` in Unix milliseconds
* `text` and `attachments`, such as `image`, `video`, `ig_reel`, `ig_post`, or `story_mention`
* `quickReplyPayload`, `replyTo` with a replied-to `messageId` or `story`, and `referral` for Click-to-Instagram-Direct ads
* `isUnsupported`, `true` when Meta can't render the message content

Each `messageId` starts at most one run. The trigger needs `instagram_basic`, `instagram_manage_messages`, `pages_manage_metadata`, `pages_read_engagement`, and `pages_show_list`.


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