docs
/
AI skills

Live chat on the website

Put the chat widget on a site, decide who answers it (staff, an AI assistant, or both), set its look, greeting, hours, offline form and pre-chat questions, and answer chats from the Inbox. Also how to put the same chat on a page outside AppMint or in your own app.

A website chat is three records and a switch:

PieceWhere it livesWhat it does
Chat configchat_config recordLook, greeting, hours, offline form, pre-chat questions, which staff answer, which AI assistant answers.
App credentialan app user (user with userType: "app")The identity the widget uses to sign visitors in as guests. The widget is given its username (its App ID); the credential's sk works too (app-identity.ts appIdQuery).
The site's linksite.data.chatConfig = the config's sk, site.data.chatAppId = the credential's usernameWhich config and credential this site's widget uses.
The switch"live-chat" in site.data.featuresTurns the widget on for every page of the site.

The site loads the widget script https://web.appmint.space/chat-client/appmint-chat.js on every page while all of these are set (base-app app/[[...slug]]/page-client.tsx 23–31, 115–131; components/chat/appmint-chat.tsx). Visitors talk to the engine over a socket (/chat namespace). Nothing is published as a page: Live Chat has no address of its own (see Site page routing).

The widget signs in only on the websites its credential lists. It first signs in as the app with POST /profile/app/attest { appId, platform: "web", domain: <the page's host> }. The engine checks the host against the browser's Origin and the credential's Allowed domains (data.app.web.domains), and answers an app token. With that token as the bearer, POST /profile/guest/auth makes the visitor a guest (users.service.ts guestAuth; app-attestation.service.ts verify). A site that isn't listed shows the visitor "Live chat isn't set up for this website yet. Please contact us another way.", and the browser console names the reason (domain_not_allowed, web_not_configured). List every address the site answers on: its platform address and its custom domain (step 2). An older widget build that sends only the username is refused with 401 app_token_required; that needs the widget updated, not the config. A site whose chatAppId names an older System login made with an email (not userType: "app") can't sign in either: Site Config › Chat says so; pick an app credential.

Ask first

  • Who answers? Staff only, an AI assistant only, or the assistant first with staff behind it. For staff: whose emails. For an assistant: which one (or make one first, see AI assistant for chat or phone).
  • When? Always, or only on some days and hours. Outside those: show a "leave a message" form, or let people wait.
  • What must a visitor give before chatting? Email is always asked. Name, phone and a first message are optional extras.
  • The words: the greeting, two or three quick openers ("Where is my order?"), the offline message.
  • Who hears about a chat nobody picked up, and after how many minutes.
  • Any pages where chat must not show (checkout, a landing page).
  • Is it only this AppMint site, or also another website or their own app?

Steps

1. Chat Designer: the chat config

Find what exists first: find_records on chat_config. One config can serve several sites.

Create one with create_record (datatype: "chat_config"), or edit with update_record_partial (keys data.<field>). In the Studio: Chat Designer (/chat-designer).

FieldValueNotes
namee.g. website-chatLetters, digits, -, _ only.
templatedefault, modern, minimal, qaThe widget's layout.
defaultPath/ (welcome panel), /register, /chat, /chat-ai, /chat-agentWhich screen opens first.
logo, headerContentimage URL, rich textShown at the top of the panel.
chatBubblePositionright (default) or left
chatOpeners["Where is my order?", …]Quick buttons on the welcome panel.
greeting"Hi! How can I help?"Only used when ai is set: the assistant's first message to each new conversation. With ai set and no greeting, the assistant writes its own greeting, which is a paid AI run. Not in the Studio form; set it with update_record_partial data.greeting. (chat.gateway.ts 817–829)
statusonline or offlineoffline shows the offline form (if on) or nothing new; nobody is told.
offline{ showForm: true, message: "…" }The form outside hours. See step 5.
availability{ allTimes: true } (default), or { allTimes: false, workDays: ["Monday",…], officeHours: { startTime: "09:00", endTime: "17:00" }, blockedTime: [{ start, end }] }Read by the widget in the visitor's own clock and time zone, not the business's. blockedTime here is one-off date-times. The Studio form has no office-hours field; set it with update_record_partial. (chat-client utils/availability.ts)
registrationRequiredfalse (default) or trueSee the pre-chat table below.
registrationFields{ phone: true, comments: true }Only phone and comments are read. name and email are ignored.
allowAttachments, allowEmojis, showAgentstrue / false
agents[{ user: "<staff email>", screenName, tagLine, avatar }]Who is told a chat is waiting. Empty means every staff member who is online in chat. showAgents shows these names on the panel.
aithe AI assistant's skWho answers first. Leave empty for staff only. Use the sk, not the name (see AI assistant for chat or phone).
missedChat{ enabled: true, notifyEmail: "<address>", timeoutMinutes: 5 }Emails that address (or the business's own email if empty) when a chat waits that long with nobody picking it up. 1 to 1440 minutes, default 5, never sooner than 1 minute. Template chat-missed. (chat.service.ts 662–728)

What the visitor is asked before chatting (chat-client components/common/chat-form.tsx 23–57):

SettingNameEmailPhoneMessage
registrationRequired: falsenorequirednono
registrationRequired: truerequiredrequiredif registrationFields.phone (never required)if registrationFields.comments
Offline formrequiredrequiredshownshown

Hands on: the config's sk. Check: GET /chat/config/<sk> answers the record you saved. Without staff sign-in it answers the widget's view, which leaves out the staff accounts behind the agents and the missed-chat addresses.

2. Users & Groups: the app credential

The widget needs an app credential. Look for one first: Users & Groups › App credentials (/user-group?view=app-credentials), or find_records on user with data.userType: "app".

To make one: call_appengine POST /profile/app/register with { "appId": "<site>-chat", "appName": "<Site> Live Chat", "description": "Widget identity for live chat" }. It answers the credential with a secret, shown once. The widget doesn't use the secret; don't put it in a page.

Then list the site on it: App credentials › the credential › App identity › Allowed domains, or call_appengine PUT /profile/app/<credential sk>/identity with { "web": { "domains": ["<platform host>", "<custom domain>"] } } (ConfigAdmin; the list is replaced, so send the ones already there too). Each is the host as the browser shows it, with the port if it has one (app-identity.ts identityUpdate, domainAllowed).

Hands on: the credential's username (the appId you sent). Check: it is listed under App credentials, and its Allowed domains show every address of the site.

Read the site first (find_records on site). Then update_record_partial on the site:

  • data.chatConfig: the config's sk (step 1)
  • data.chatAppId: the credential's username (step 2)
  • data.features: the whole list as it is now, plus "live-chat". The field is replaced, so a list with only "live-chat" switches every other feature off.

In the Studio: Site Config › Chat has Chat settings (the config), Chat app credential, and a Set up chat button (Reconfigure chat once a config is linked). That wizard does steps 1 to 3 in one go: a config with defaults, an optional new AI assistant, a new or existing credential (the site's addresses are added to its Allowed domains when you finish), the site links and the live-chat switch (Studio welcome-screens/buttons/live-chat-setup-wizard.tsx).

Chat app credential lists only app credentials, as name (App ID). Under it, a box lists the websites the picked credential signs in on; when the site's host name or custom domain is missing it says "Not on — visitors there can't start a chat." with an Add this site button. Saving Site Config with a newly picked credential adds the site's addresses too. A chatAppId that isn't an app credential shows "“” is not an app credential, so the chat can't sign in." (Studio site-config-form.tsx, crm/chat/chat-app-websites.tsx).

Stop. Switching live-chat on puts the bubble on every page of the live site on its next load, and anyone can start a chat. Show the person the config and who will answer, and wait for a yes.

Hands on: the site's sk. Check: read the site back. chatConfig, chatAppId and features (with every feature it had before) are set.

4. Pages: hide it where it doesn't belong (only if asked)

On each page that must not show the bubble, add "chat" to data.hiddenControls (keep what is already in it) with update_record_partial. (base-app page-client.tsx 115–131)

Check: that page loads without the bubble; another page still has it.

5. Who answers, and what happens to a chat

How a visitor's message is routed (chat.gateway.ts 1235–1541):

ConfigFirst message goes toThen
no aithe queue. The visitor gets "You are in the queue…" with a position and a wait estimate (position ÷ online agents × 3 minutes).Staff in agents are told (queue-notification), or every online staff member if agents is empty. The visitor's position is re-sent every 15 seconds. AI employees that listen to the chat queue are woken too.
ai setthe assistant, which answers at once (streamed).It hands over to the queue when it uses its transfer tool (transfer_chat_to_agent), or when it fails: the visitor is told the assistant is unavailable and is queued, and the assistant's safety.escalationContact is told.

Answering, for staff:

  • Inbox › Live Chat (/inbox?tab=livechat) and Chat (/chat) are the same agent desk: waiting and active chats. Pick next takes the next waiting chat; the visitor sees " has joined the chat." Takeover takes a chat from the assistant or another agent, Transfer passes it to another agent with a note, End chat closes it.
  • Website chats are not in the Inbox's Conversations tab. That tab lists messages (email, SMS, social); chat messages are stored as chat_message (crm.service.ts ~931).
  • Once a person has picked a chat up, 4 minutes with no message from either side warns the visitor, and 5 minutes closes the chat (chat-presence.service.ts 844–847).
  • Closing can email the transcript (template chat-transcript) to an address. That is a real email.
  • The missed-chat email (step 1) goes out only while a chat waits unpicked.

Outside hours (availability) or with status: "offline", and offline.showForm: true, the visitor gets the offline form instead. It raises a support ticket (POST /crm/tickets/chat-request), handled as in Customer support ticket flow. With showForm: false, visitors can still chat and wait in the queue; nobody is told the business is closed.

Who the visitor becomes: guest sign-in finds the customer with that email, or creates one in group guest, with guestUser: true and the phone N/A if none was given (users.service.ts 757–795). So every chat leaves a contact in CRM.

Hands on: nothing new; this is how the config from step 1 behaves.

6. Check it on the site

Open a page of the live site in a private window. Then:

  1. The bubble shows, at the side you chose, with the openers.
  2. Start a chat as skilltest-chat-<you>@test.local. It must open the conversation, not "Live chat isn't set up for this website yet" (see the warning at the top).
  3. With no ai: the chat appears under Inbox › Live Chat as waiting. Pick next, reply, and the reply shows on the site. Close it without a transcript email.

Stop. With ai set, the test message runs the assistant: each message is paid AI use, and an assistant with send or booking tools can act for real. Ask before testing it.

Check: afterwards, delete the test customer and its chat_message records (find_records on chat_message with data.chatId containing the test email).

7. Another website or your own app (only if asked)

Another website (not AppMint): the Chat Designer's Embed Code tab gives the snippet. It is:

<link type="text/css" rel="stylesheet" href="https://web.appmint.space/chat-client/static/css/main.css">
<div id="appmint-chat-container"></div>
<script>
  function initializeChat() {
    AppmintChat.init({
      containerId: 'appmint-chat-container',
      orgId: '<org id>',
      configId: '<chat_config sk>',
      appId: '<app credential username>',
      theme: 'light',
      language: 'en'
    });
  }
</script>
<script src="https://web.appmint.space/chat-client/appmint-chat.js" onload="initializeChat()"></script>

Add that website's address to the credential's Allowed domains (step 2); the widget signs in only there. In the Studio, Chat Designer › Embed Code writes this snippet for the site's own credential (picked from chatAppId, else the first one) and, under the credential picker, lists its websites with a field to Add another (a full URL is cut down to its host).

Other init options the widget reads: apiHost (the engine's address, if not the default), defaultPath, mode (chat or qa), inline: true (fill the container instead of a floating bubble), className, and chatUser: { email, name, phone } (a visitor you already know; the form is skipped). The ids are not interchangeable: configId is the config's sk; appId is the credential's username or its sk. chatId and appKey, which older snippets carry, are ignored.

On an AppMint page don't paste this: inline <script> doesn't run in a page's HTML, and the site already loads the widget when Live Chat is on. See AppMint JS engine on a page.

Your own app (headless): connect with socket.io to <engine>/chat, transport websocket:

StepSend / receiveBody
Sign the app inPOST /profile/app/attest, header orgid{ appId, platform: "web", domain } → { token, expiresIn } (web pages; an app with its secret uses app/key, see App sign-in)
Sign the visitor inPOST /profile/guest/auth, headers orgid, Authorization: Bearer <app token>{ email, name, phone, message } → { token }
Connectio('<engine>/chat', { auth })auth: { token, orgId, configId, deviceId, context: { currentUrl } }
Connectedreceive authenticate{ chatSessionId, isGuest, config: { configId, ai, agents, status } }. Keep chatSessionId.
Sendemit chat-message{ message, chatSessionId } → ack { chatId, routedTo: "queued" | "agent" | … }
Waitingreceive queued, queue-update{ position, estimatedWaitSeconds, message }
Picked upreceive agent-assignedthe agent's name
Repliesreceive message (staff), chat-stream (assistant: chunks, then end)
Historyemit chat-history{ chatId, chatSessionId } → { history: [...] } (latest 100)
Endedreceive session-expiring, session-expired, chat-ended

A guest's conversation id is customer:<chatSessionId>:<email>; a signed-in customer's is customer::<email>. A guest session lasts 30 minutes without activity.

Hands on: the snippet or the app's connection details. Check: the same test as step 6, from that website or app.

When it's done

Tell the person:

  • which config the site uses, who answers (the assistant, which staff, or everyone online) and the hours;
  • what a visitor is asked before chatting, and what they see outside hours;
  • who gets the missed-chat email, after how long;
  • that chats are answered in Inbox › Live Chat (/inbox?tab=livechat), not in Conversations;
  • that every chat creates or reuses a customer record;
  • whether the test chat started, and which addresses are on the credential's Allowed domains.

Open the Chat Designer (/chat-designer).

What it can't do yet

  • Chat works only on the listed websites. A new domain for the site needs adding to Allowed domains (see the warning at the top).
  • A guest's history stays in their browser. A guest gets back only the chat whose session id their browser kept; signing in with the same email elsewhere starts a fresh chat with no history. A signed-in customer sees their own chats (chat.gateway.ts).
  • Hours use the visitor's clock. A visitor in another time zone sees the business as open or closed by their own local time.
  • The greeting needs an AI assistant. Without ai, nothing greets the visitor; use the openers and headerContent for words.
  • status: "offline" with no offline form still queues visitors with no warning that nobody is there.
  • No chat in Inbox › Conversations. Website chat has its own Live Chat tab.
  • No canned replies, ratings or chat routing rules beyond the agents list.
  • registrationFields.name and .email do nothing. Email is always asked; name only with registrationRequired.

Don'ts

  • Don't write data.features without the features already there.
  • Don't put the credential's secret in a page or snippet. The widget only needs the App ID.
  • Don't put the assistant's name in ai; use its sk.
  • Don't switch live-chat on without a yes. It is live on every page at once.
  • Don't send a transcript or turn on the missed-chat email to a real address while testing.
  • Don't test an AI-answered chat without saying it is paid AI use.
  • Don't say chat works until a test visitor has started a chat on the real site.