Embed a chat

POST
Embed a chat

/accounts/{id}/embed  ·  needs embed  ·  LinkedIn and Telegram

Returns a link for an <iframe> on your own site: the account's conversations, with reading and sending, drawn the way the channel draws them: LinkedIn's look for a LinkedIn account, and Telegram's (chat list, bubbles, forum topics, files and reactions) for a Telegram account. The link's address names its channel (/embed/linkedin/… or /embed/telegram/…); use whatever the API returned. Ask for it from your server, so the API key never reaches a browser, and hand the browser only the link.

  • One account, one site. The link opens only the account it was made for, and only inside the origin you name (https://app.yourcompany.com — https, no path, no wildcard; http://localhost:… works while you build). Any other site that frames it is refused by the browser.
  • Short-lived. It expires after expiresInSeconds — an hour by default, at most a day — and sooner if the key that made it is revoked. Make a fresh one each time you show the chat.
  • It is a secret. Anyone holding the link can read and send until it expires, so don't log it or put it in a page other people can read. It is a one-time-per-page-view credential, not a permanent address.
  • Sends are real. A message or file written in the frame is sent from the account and uses a credit, exactly as in the dashboard. Add ?theme=dark or ?theme=light to the link to choose the look.
  • Updates. The frame has no live push yet. A Telegram chat checks every ten seconds; LinkedIn's about every two minutes, because each refresh is a real page load there. Messages you send show up at once.

The frame tells your page when it is ready and when the link has expired, with postMessage to your origin only. Other channels return 422 unsupported_operation; check capabilities.embed on the account.

# 1. On your server — never in the browser, the API key must stay secret
curl -X POST https://messengeragent.dev/api/v1/accounts/ACCOUNT_ID/embed \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "origin": "https://app.yourcompany.com", "expiresInSeconds": 3600 }'
#   → 201
#   {
#     "url": "https://…/embed/linkedin/emb_CfDJ8…",
#     "expiresAt": "2026-10-07T13:00:00Z",
#     "origin": "https://app.yourcompany.com"
#   }

# 2. In your page, give the browser only that URL (a Telegram account's link is …/embed/telegram/emb_…)
<iframe src="https://…/embed/linkedin/emb_CfDJ8…" title="Chat"
        style="width:100%;height:640px;border:0" allow="clipboard-write"></iframe>

// 3. Optional: hear what the chat tells your page (frameUrl is the link from step 1)
window.addEventListener('message', (e) => {
  if (e.origin !== new URL(frameUrl).origin || e.data?.source !== 'agent-messenger') return
  if (e.data.type === 'expired') reloadWithAFreshLink()   // ask your server for a new link
})