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

# Messenger and Instagram

> Connect a Facebook Page and its Instagram account for a tenant.

A Facebook Page and the Instagram account that is linked to it connect together. The tenant signs in with its own
Facebook account. Connecting a Page makes a Messenger channel, and an Instagram channel when the Page has an Instagram
account. Reading needs `channels:read`. Everything else needs `channels:write`.

## Connect with Facebook Login

**1. Read the settings**

`GET /api/v1/partner/tenants/{external_ref}/channels/meta/pages/` returns `app_id`, `config_id`, `graph_version`,
`scopes` and `server_ready`. Use them to open Facebook Login in your own page. If `server_ready` is `false`, Messenger
sign-in is not set up on this server. The answer also lists the connected `pages` and the `candidates` of a login.

**2. Send the login result**

`POST` the same path with `{ "code": "..." }`, or `{ "access_token": "..." }`.

```json theme={null}
{ "code": "CODE_FROM_META" }
```

If the Facebook account manages no Page, the call answers 409. If it manages one Page, that Page connects at once and
the answer holds `page`. If it manages more than one, the answer holds `candidates`.

**3. Pick a Page**

When the answer lists `candidates`, call `POST .../channels/meta/pages/pick/` with `{ "page_id": "..." }`. If the offer
is gone, the call answers 409, and the person logs in again.

You can also send `page_id` with the login result in step 2 to choose the Page at once.

## Connect with the business's own Meta app

A business that runs its own Meta app can send `page_id`, `page_access_token`, `app_id` and `app_secret` in one `POST` to
the same path. All four are required. The answer holds `page` and `subscribed`. If the webhook is not subscribed, the
business sets the `webhook_url` and `verify_token` from the settings answer in its own app.

## The Page object

```json theme={null}
{
  "page_id": "300000000000001",
  "page_name": "Acme Dental",
  "ig_account_id": "",
  "ig_username": "",
  "status": "pending",
  "is_primary": true,
  "channels": ["messenger"],
  "own_app": false,
  "last_health": {},
  "last_health_check_at": null,
  "settings": {},
  "agent": null
}
```

## Switch on, check, change, disconnect

| Call | Use |
| - | - |
| `POST .../channels/meta/pages/{page_id}/activate/` | Send `assistant_id` to switch an agent on for the Page and its Instagram account. Send `"on": false` to pause. |
| `GET .../channels/meta/pages/{page_id}/health/` | Check the token, the webhook and the Instagram link. The result is kept for 10 minutes. Add `?refresh=true` to ask Meta again. |
| `GET` or `POST .../channels/meta/pages/{page_id}/settings/` | Read or change the settings. |
| `DELETE .../channels/meta/pages/{page_id}/` | Disconnect the Page and its Instagram account. The answer is 204. |

Settings: `typing_indicator`, `mark_seen`, `rich_blocks`, `reply_wait_seconds`, `agent_allowlist_mode`, `agent_allowlist`
and `agent_rollout_percent`. Send only the fields that change. Both calls answer with all of them.

## Replies

On Messenger and Instagram a person can send text only. A customer must write first. See
[Conversations](https://docs.impellabs.tech/partners/conversations.md).


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