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

# Facebook Messenger

> Connect your agent to Facebook Page messages

## Overview

Facebook Messenger integration allows your agent to respond to messages sent to your Facebook Business Page.

<CardGroup cols={2}>
  <Card title="2.9B Users" icon="users">
    Massive Facebook user base
  </Card>

  <Card title="Page Integration" icon="facebook">
    Connect to business page
  </Card>

  <Card title="Rich Media" icon="image">
    Images, videos, buttons
  </Card>

  <Card title="Social Context" icon="network-wired">
    See user's public profile
  </Card>
</CardGroup>

## Prerequisites

<Info>
  Meta updates Facebook and its developer tools frequently. The steps below describe what you need; for exact, up-to-date screens, see Meta's [Messenger Platform documentation](https://developers.facebook.com/docs/messenger-platform/).
</Info>

<Steps>
  <Step title="Facebook Business Page">
    You need admin access to a Facebook Page. The dashboard method connects it for you via Facebook login — no developer app required.
  </Step>

  <Step title="Facebook App (CLI only)">
    Only needed for the CLI method. Create one at [developers.facebook.com](https://developers.facebook.com).
  </Step>
</Steps>

## Connection Method 1: Admin Dashboard (Recommended)

<Info>
  The dashboard connects Facebook via **Facebook Login (OAuth)** — you authorize Lua in a Facebook popup and pick your Page there, so there's nothing to copy or paste. Use the [CLI method](#connection-method-2-cli-advanced) if you'd rather supply a Page access token manually.
</Info>

<Steps>
  <Step title="Open the dashboard">
    ```bash theme={null}
    lua admin
    ```

    Or visit [https://admin.heylua.ai](https://admin.heylua.ai).
  </Step>

  <Step title="Open your agent">
    Click **Agents** in the main side navigation, then select your agent's card.
  </Step>

  <Step title="Add a channel">
    Click the **+** (plus) icon to add a channel, then choose **Facebook**.

    <Frame>
      <img src="https://mintcdn.com/luaglobal/5airD3u2P6mv3Ovl/images/channels/admin-add-channel.png?fit=max&auto=format&n=5airD3u2P6mv3Ovl&q=85&s=ab13d8f9a731bc706b9e112cf4226701" alt="Add a channel" width="3016" height="1576" data-path="images/channels/admin-add-channel.png" />
    </Frame>

    *Screenshot: The agent's add-channel (+) control and the channel options*
  </Step>

  <Step title="Accept terms & connect">
    Tick the box to accept the **Terms of Service** and **Privacy Policy**, then click **Connect**.
  </Step>

  <Step title="Authorize with Facebook">
    A Facebook login popup opens. Log in, select the **Page** you want to connect, and grant the messaging permissions Facebook requests. When the popup closes, the channel is connected.

    <Note>
      This popup is Facebook's own UI and changes periodically. See Meta's [Messenger Platform documentation](https://developers.facebook.com/docs/messenger-platform/) if you get stuck.
    </Note>
  </Step>

  <Step title="Connection success">
    Facebook appears in your connected channels and is ready to receive messages.
  </Step>
</Steps>

## Connection Method 2: CLI (Advanced)

### CLI Setup with Page Token

<Steps>
  <Step title="Get Page Access Token">
    From your Facebook App Dashboard:

    1. Go to your app
    2. Messenger → Settings
    3. Generate a Page Access Token
    4. Copy the token

    See Meta's [Messenger Platform documentation](https://developers.facebook.com/docs/messenger-platform/) for the current steps.
  </Step>

  <Step title="Get Page ID">
    From your Facebook Page:

    1. Go to page settings
    2. Copy Page ID

    Or from URL: `facebook.com/[page-id]`
  </Step>

  <Step title="Run lua channels">
    ```bash theme={null}
    $ lua channels
    ✅ Using agent: myAgent

    ? What would you like to do? 🔗 Link new channel
    ? Select channel type: 💬 Facebook Messenger

    ? Enter Facebook page access token: ****
    ? Enter Facebook page ID: 705555819301071

    📡 Creating Facebook channel...

    ✅ Facebook channel created successfully!

    💬 Page Name: My Business Page
    📄 Category: Local Business
    🔗 Webhook: https://wa.heylua.ai/fb/webhook/xyz789
    ```
  </Step>

  <Step title="Configure Webhook in Facebook App">
    1. Go to App Dashboard
    2. Messenger → Settings → Webhooks
    3. Click "Add Callback URL"
    4. Paste the webhook URL from the CLI output
    5. Enter your verify token
    6. Subscribe to `messages`, `messaging_postbacks`, and `messaging_optins`

    See Meta's [Messenger Platform Webhooks guide](https://developers.facebook.com/docs/messenger-platform/webhooks) for the current UI.
  </Step>
</Steps>

## Testing

<Steps>
  <Step title="Send a message to your Page">
    Open Messenger and send a message to your Page (for example, "Hi!").
  </Step>

  <Step title="Agent responds">
    Your agent replies automatically in the Messenger thread.
  </Step>

  <Step title="View in admin">
    Monitor the conversation in the admin dashboard.

    <Frame>
      <img src="https://mintcdn.com/luaglobal/5airD3u2P6mv3Ovl/images/channels/admin-facebook-conversation.png?fit=max&auto=format&n=5airD3u2P6mv3Ovl&q=85&s=48cfa1b7137f8ac4403154162e2c5462" alt="Admin conversation" width="3012" height="1570" data-path="images/channels/admin-facebook-conversation.png" />
    </Frame>

    *Screenshot: The conversation in the admin dashboard*
  </Step>
</Steps>

## Features

<CardGroup cols={2}>
  <Card title="Text Messages" icon="message">
    Send and receive text
  </Card>

  <Card title="Rich Media" icon="image">
    Images, videos, files
  </Card>

  <Card title="Quick Replies" icon="list">
    Suggested response buttons
  </Card>

  <Card title="Templates" icon="file">
    Reusable message templates
  </Card>
</CardGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Response Time">
    * Respond quickly (within minutes)
    * Facebook shows "Typically responds in..."
    * Fast responses improve visibility
  </Accordion>

  <Accordion title="Use Page Features">
    * Set greeting message
    * Configure away message
    * Use quick replies
    * Add call-to-action buttons
  </Accordion>

  <Accordion title="Monitor Page Rating">
    * Check page rating regularly
    * Respond to all messages
    * Address negative feedback
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Instagram" icon="instagram" href="/channels/instagram">
    Connect Instagram DMs
  </Card>

  <Card title="Email" icon="envelope" href="/channels/email">
    Add email support
  </Card>
</CardGroup>
