Skip to content

API guide

Embedding

Put the LexoConnect webphone inside your own product with an iframe or the JavaScript SDK, add click-to-call buttons, build your own phone UI on LexoConnect's WebRTC service, and embed the chat widget.

How embedding is secured#

The browser never sees an API key. Instead:

  1. Your server asks LexoConnect for a short-lived webphone token for one user: POST /webphone/tokens with an API key that has the webphone scope.
  2. Your page gives the token to the LexoConnect iframe or SDK, which exchanges it for that user's phone session.
  3. The token works once and expires after 5 minutes by default (30 seconds to 1 hour, ttlSec).

A company admin lists the websites that may embed the phone in Admin → Developer → Webphone embed (allowed origins, for example https://crm.example.com). Other origins are refused.

curl -X POST "$LEXO_URL/api/v1/webphone/tokens" \
  -H "Authorization: Bearer $LEXO_API_KEY" -H "Content-Type: application/json" \
  -d '{"userId": "0b7e5d1c-2a3f-4e6d-8c9b-1a2b3c4d5e6f", "ttlSec": 300}'

The answer has token (ncwp_…), expiresAt, a ready embedUrl and the sdkUrl.

Option 1: the iframe#

HTML
<iframe id="lexo-phone" src="https://telco.lexogenix.com/embed/phone?token=TOKEN"
        allow="microphone; autoplay" style="width:360px;height:560px;border:0"></iframe>
<script>
  const LEXO = "https://telco.lexogenix.com";
  const phone = document.getElementById("lexo-phone").contentWindow;

  window.addEventListener("message", (e) => {
    if (e.origin !== LEXO || e.data?.source !== "novawebphone") return;
    // e.data.type: ready | registered | incoming | connected | ended | error
    console.log(e.data.type, e.data);
  });

  // Commands: dial, answer, hangup
  function dial(number) { phone.postMessage({ source: "novawebphone", type: "dial", number }, LEXO); }
  function answer() { phone.postMessage({ source: "novawebphone", type: "answer" }, LEXO); }
  function hangup() { phone.postMessage({ source: "novawebphone", type: "hangup" }, LEXO); }
</script>

The iframe shows a complete phone with a dial pad, the incoming call screen and the in-call controls. Messages use source: "novawebphone"; the name stays the same for compatibility.

Option 2: the JavaScript SDK#

The SDK gives you the same phone as an object with events, so you can draw your own buttons:

HTML
<div id="phone"></div>
<button id="call">Call Grace</button>
<script src="https://telco.lexogenix.com/sdk/webphone.js"></script>
<script>
  async function start() {
    const { token } = await (await fetch("/api/lexo-phone-token")).json(); // your server, see above
    const phone = NovaWebphone.init({ token, container: "#phone" });

    phone.on("incoming", ({ call }) => showScreenPop(call.remoteNumber));
    phone.on("connected", ({ call }) => console.log("Talking to", call.remoteNumber));
    phone.on("ended", ({ call }) => console.log("Ended:", call.endReason));
    phone.on("error", ({ message }) => console.error(message));

    document.querySelector("#call").onclick = () => phone.dial("+12125550123");
  }
  start();
</script>

Methods: dial(number), answer(callId?), hangup(callId?). Events (each listener gets one object): ready {user}, registered {user}, registration {state}, incoming / connected / ended {call} (with id, remoteNumber, answeredAt, endReason, …), calls {calls} and error {message}. The global keeps its original name NovaWebphone so that existing pages keep working. Ask for a new token when the page loads again; each token works once.

Click-to-call buttons#

There are two ways to put "Call" buttons next to phone numbers in your product:

ApproachWhen to use it
In the page: dial(number) on the embedded iframe or SDK phoneThe user works in your web app with the LexoConnect phone embedded. The call starts on their browser phone at once.
From your server: POST /calls/originateThe user's phone is elsewhere (a desk phone, the LexoConnect app, a softphone). LexoConnect rings that phone first, then dials the customer. See Calls.

Build your own phone UI#

For full control, write your own WebRTC client and use LexoConnect's SIP over WebSocket service. Exchange a webphone token for SIP credentials (no API key; the token is the credential and works once):

curl
curl -X POST "$LEXO_URL/api/v1/webphone/session" \
  -H "Content-Type: application/json" -H "Origin: https://crm.example.com" \
  -d '{"token": "ncwp_..."}'

The answer:

JSON
{
  "sip": {
    "wsUri": "wss://telco.lexogenix.com:8443",
    "sipUri": "sip:150@acme.sip.example.com",
    "authUser": "150",
    "password": "…",
    "domain": "acme.sip.example.com",
    "displayName": "Ana Agent",
    "iceServers": [{ "urls": "stun:…" }]
  },
  "user": { "id": "…", "name": "Ana Agent", "extension": "150" },
  "tenant": { "id": "…", "name": "Acme Inc" },
  "allowedOrigins": ["https://crm.example.com"],
  "expiresAt": "2026-11-13T18:00:00Z"
}

Register with any SIP-over-WebSocket library, for example SIP.js:

JavaScript
import { UserAgent, Registerer, Inviter } from "sip.js";

const { sip } = await (await fetch(`${LEXO}/api/v1/webphone/session`, {
  method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token }),
})).json();

const ua = new UserAgent({
  uri: UserAgent.makeURI(sip.sipUri),
  transportOptions: { server: sip.wsUri },
  authorizationUsername: sip.authUser,
  authorizationPassword: sip.password,
  displayName: sip.displayName,
  sessionDescriptionHandlerFactoryOptions: { peerConnectionConfiguration: { iceServers: sip.iceServers } },
});
await ua.start();
await new Registerer(ua).register();

// Outbound call: dial the number at the company's SIP domain.
const target = UserAgent.makeURI(`sip:+12125550123@${sip.domain}`);
await new Inviter(ua, target).invite();

All company rules apply to calls from your client (caller ID, routing, recording, billing). Calls of the user ring your client like any other phone of that user, and appear in call history and webhooks as usual. Before the credentials expire (expiresAt), mint a new token and register again.

Website chat widget#

When the company has connected a Web chat channel, paste its snippet on the website. Chats arrive in LexoConnect's inbox as conversations (see Messaging) and send the message.received webhook.

HTML
<script src="https://telco.lexogenix.com/widget.js" data-key="CHANNEL_KEY" async></script>

The admin copies the snippet, with the right data-key, from the Web chat channel's settings in LexoConnect.

Single sign-on#

LexoConnect does not offer SAML or OpenID Connect sign-in for embedded use. Map your users to LexoConnect users once (by email or extension, from GET /users) and mint webphone tokens for them on your server; your own login stays the only login your users see.

Embedding · API guide · LexoConnect