Messenger and Instagram

Base URL: https://chatsa.co/api/v1

A partner account can connect its Facebook Pages, and the Instagram professional accounts linked to them, so every Messenger and Instagram Direct message reaches you as a signed webhook and you reply from your own product. Your customer connects in the same Facebook window as lead ads, with your product's name on it.

These conversations are team only: ChatSa's AI never answers them. Every message is kept in the account's ChatSa inbox and delivered to you; what your own assistant or your users reply is up to you.

Availability. GET /partner/capabilities says whether Messenger and Instagram are on (messenger, instagram). Show the button only when they are. Messenger and Instagram use only permissions Meta has already approved for ChatSa, so any business can connect.

This uses the partner API: authenticate with the account's key (Authorization: Bearer <account key>). Paths are under https://chatsa.co/api/v1/.

Open the Facebook window#

POST /api/v1/partner/facebook/signups
Authorization: Bearer <account key>

{ "return_url": "https://app.example.com/chatsa/facebook/done", "state": "<random, up to 500 characters>", "locale": "en", "features": ["messages"] }

features is ["messages"], ["lead_ads"] or both. Leave it out and the window connects whatever is available now (see capabilities); asking for a feature that is off answers 503 not_configured. The answer, the return URL rules and the 30-minute single-use window are as for lead ads; the answer also lists features.

The window#

Open url in a popup. Facebook's own window asks the business to log in and choose its Pages. For each chosen Page the person can send messages from:

  • Messenger is connected for the Page, and the Instagram professional account linked to the Page (if there is one) for Instagram Direct.
  • ChatSa subscribes the Page to its messages, keeping everything else the Page is already subscribed to (lead ads included).
  • A Page already connected somewhere else (another ChatSa account, or a ChatSa chatbot answering it with AI) is refused with page_in_use, and its Instagram account with it. An Instagram account connected somewhere else is refused with instagram_in_use. The other Pages still connect. A Page never moves between accounts on its own: disconnect it there first.

The window then goes to return_url with status = connected (something connected), cancelled or error, plus signup and state (check state first). reason on an error: no_pages (no Page the person can message from was shared), page_in_use (every Page is used elsewhere) or subscribe_failed (Facebook refused).

Read the result#

GET /api/v1/partner/facebook/signups/{id}:

{
  "data": {
    "status": "connected",
    "features": ["messages"],
    "pages": [],
    "social": [
      { "channel": "messenger", "account_id": "104829375610245", "name": "Acme Plumbing", "page_id": "104829375610245", "status": "connected", "connected_at": "2026-11-30T09:15:00Z" },
      { "channel": "instagram", "account_id": "17841400012345678", "name": "Acme Plumbing", "username": "acmeplumbing", "page_id": "104829375610245", "status": "connected", "connected_at": "2026-11-30T09:15:00Z" }
    ],
    "refused": [
      { "channel": "messenger", "page_id": "104829375610299", "account_id": "104829375610299", "name": "Acme Drains", "reason": "page_in_use" }
    ],
    "feature_errors": { "messages": null },
    "error": null
  }
}

social lists what is connected for messages; pages the lead ads Pages, when the window also connected lead ads. feature_errors says why one feature connected nothing while another did. error is set only when nothing connected.

The account's Messenger and Instagram accounts#

GET /api/v1/partner/social/accounts:

{
  "data": [
    { "channel": "messenger", "account_id": "104829375610245", "name": "Acme Plumbing", "page_id": "104829375610245", "status": "connected", "connected_at": "2026-11-30T09:15:00Z" },
    { "channel": "instagram", "account_id": "17841400012345678", "name": "Acme Plumbing", "username": "acmeplumbing", "page_id": "104829375610245", "status": "connected", "connected_at": "2026-11-30T09:15:00Z" }
  ]
}

account_id is the Facebook Page id (Messenger) or the Instagram account id. status is connected, or reconnect when Facebook stopped accepting the connection (the person lost access to the Page, changed their password, or removed ChatSa): open a new window to reconnect.

DELETE /api/v1/partner/social/accounts/{channel}/{account_id} stops one of them: { "data": { "channel", "account_id", "disconnected": true } }, or 404 not_found. The conversations stay readable. Once nothing of the account still uses the Page, ChatSa takes the subscriptions it added off the Page.

Receiving messages#

Subscribe your account webhook to social.* (or social.message.received and social.message.sent by name). These are their own events: message.* is WhatsApp's, with phone numbers in from and to. The envelope's chatbot_id is the account's Messenger and Instagram chatbot; you have no Connect endpoint for it, so the events reach the account endpoint.

social.message.received#

{
  "id": "evt_5b7c9d1e-2f3a-4b5c-8d9e-0f1a2b3c4d5e",
  "event": "social.message.received",
  "chatbot_id": "6a1f…",
  "timestamp": "2026-11-30T17:04:12.000Z",
  "data": {
    "message_id": "b2c4…",
    "channel": "messenger",
    "conversation_id": "9e1d…",
    "account": { "id": "104829375610245", "name": "Acme Plumbing" },
    "from": { "id": "7104829375610245", "name": "Jordan Lee", "username": null },
    "type": "text",
    "text": "Can you come look at a slow drain this week?",
    "media": null,
    "reply_to_message_id": null,
    "reply_window_until": "2026-12-01T17:04:11.000Z",
    "received_at": "2026-11-30T17:04:11.000Z"
  }
}
FieldMeaning
typetext, image, video, audio, file, postback (a button or ice breaker; text is its title), story_reply, story_mention or share (a shared post or link)
from.idThe person's id for this Page (Messenger) or this Instagram account. Use it as to to reply and to read the thread. It is unique only within one channel and account.id: the same person has another id on another Page
from.name, from.usernameFrom the person's Facebook or Instagram profile when Meta shares it, else null (username is Instagram's)
media[{ "type", "url", "expires_at", "mime_type", "size" }] or null. Each file is copied once, and url is a ChatSa link valid 24 hours (read the thread for a fresh one). A file over 25 MB, or one Facebook would not give, has url: null
reply_to_message_idThe message_id of the message this one answers, when ChatSa has it
reply_window_until24 hours after this message: the end of the window in which you can reply

social.message.sent#

Every message the business sends, whoever sent it:

{
  "event": "social.message.sent",
  "data": {
    "message_id": "c3d5…", "channel": "instagram", "conversation_id": "9e1d…",
    "account": { "id": "17841400012345678", "name": "Acme Plumbing" },
    "to": { "id": "9104829375610245" },
    "type": "text", "text": "Tuesday at 9 works. See you then!", "media": null,
    "source": "api", "sender_name": "Riley", "sent_at": "2026-11-30T17:06:40.000Z"
  }
}

source is api (your own send, with the same message_id as its answer), inbox (a reply from ChatSa's inbox) or app (typed by the business in Facebook or Instagram itself, or sent by another tool on the Page).

  • Each message is delivered once, also when Facebook repeats its notification. Use message_id (and X-ChatSA-Delivery) to skip repeats.
  • Your own sends are never delivered a second time from Facebook's copy of them.
  • A new conversation (conversation_id) starts after 24 hours of silence; key your threads by channel, account.id and the person's id.

Send a message#

POST /api/v1/social/messages
Authorization: Bearer <account key>
Idempotency-Key: reply-7731

{ "channel": "messenger", "account_id": "104829375610245", "to": "7104829375610245", "text": "Tuesday at 9 works. See you then!", "sender": { "name": "Riley" } }

201 { "data": { "message_id", "conversation_id", "sent_at" } }.

  • Inside 24 hours only. Messenger and Instagram allow a business to reply within 24 hours of the person's last message. After that, the send is refused with 409 window_closed; it can't be sent later with a tag.
  • Send text, or instead one attachment: { "type": "image" | "video" | "audio" | "file", "url": "https://…" } (Instagram: image, video or audio). The link must be public https; Facebook downloads it.
  • Text is at most 2,000 characters on Messenger and 1,000 bytes on Instagram (about 500 Arabic characters). Longer text is refused, never split.
  • Idempotency-Key is required, up to 100 characters. The same key with the same account key answers the same result for 24 hours without sending again (Idempotent-Replayed: true).
  • 60 sends a minute per key.
StatuscodeWhen
400invalid_request, idempotency_key_required, message_too_longThe body, the header, the length
401unauthorizedNo key, or a revoked one
403forbiddenThe account is suspended
404not_connectedThe account has no such Page or Instagram account
409window_closedNo message from the person in the last 24 hours (window_open_until), or Facebook said the window closed
409reconnect_requiredFacebook no longer accepts the connection: open a new window
422invalid_media, recipient_unavailableThe attachment link; the person can't receive messages from the Page
429rate_limitedSlow down (Retry-After)
502send_failedFacebook refused (meta_code). With delivery_unknown: true the answer was lost after Facebook may have sent it: check the thread and don't send it again

Read a thread#

GET /api/v1/social/threads/{channel}/{to}?account_id=104829375610245&limit=50&before=… (600 reads a minute):

{
  "data": {
    "channel": "messenger",
    "account": { "id": "104829375610245", "name": "Acme Plumbing" },
    "contact": { "id": "7104829375610245", "name": "Jordan Lee", "username": null, "last_inbound_at": "2026-11-30T17:04:11.000Z", "reply_window_until": "2026-12-01T17:04:11.000Z" },
    "messages": [
      { "message_id": "c3d5…", "conversation_id": "9e1d…", "direction": "out", "type": "text", "text": "Tuesday at 9 works. See you then!", "media": null, "source": "api", "sender_name": "Riley", "status": "sent", "reply_to_message_id": null, "created_at": "2026-11-30T17:06:40.000Z" },
      { "message_id": "b2c4…", "conversation_id": "9e1d…", "direction": "in", "type": "text", "text": "Can you come look at a slow drain this week?", "media": null, "source": null, "sender_name": null, "status": "received", "reply_to_message_id": null, "created_at": "2026-11-30T17:04:11.000Z" }
    ],
    "next_before": null
  }
}

Every message with the person on that Page or Instagram account, newest first, across their conversations. limit is 1–200 (50 by default); pass next_before as before for the next page (null: no more). Files get fresh links on every read. reply_window_until is null once the window has closed. A disconnected account's threads still read; another account's: 404 not_connected.

Deleting a person's data#

Send the person's id with the deletion request, with the account key:

{ "social": [{ "channel": "messenger", "id": "7104829375610245" }] }

Their Messenger or Instagram conversations, messages and files, their contact, and the webhook deliveries carrying their id go.