A fully standalone chat component for NethVoice: one-to-one and group chats, attachments, voice notes, reactions, replies and notifications.
It runs in NethVoice CTI, in NethLink and in any web page, and talks to the per-tenant XMPP server of ns8-nethvoice with the user's CTI token.
Available as component on npm
Available as widget on jsDelivr
npm install @nethesis/chat-islandimport { ChatIsland } from '@nethesis/chat-island'
import '@nethesis/chat-island/dist/index.css'
<ChatIsland dataConfig={btoa(`${ctiHost}:${username}:${ctiToken}`)} serviceWorker="/chat-island-sw.js" />| Prop | Default | |
|---|---|---|
dataConfig |
Base64 of <cti_host>:<cti_username>:<cti_token> |
|
theme |
host's dark class |
light, dark or system |
position |
bottom-right |
bottom-left, top-right or top-left; with onDragStart, panels open away from that corner |
serviceWorker |
URL of chat-island-sw.js on the host: notifications with the tab closed |
|
notifications |
click |
auto asks for permission once online |
newChatButton |
true |
the new chat button while there are no chats; false when the host has its own list (a + under the heads stays) |
maxHeads |
5 |
chat heads in the dock; the others wait behind a +N bubble |
sound |
true |
chime for a message not in view |
headless |
false |
connected but invisible: events only, no sound, notifications, push or read receipts |
drag / onDragStart |
true |
off, or the host moves its own window (NethLink) |
nativeTooltips |
false |
the browser's tooltips for the heads' names, for a host window sized to the dock (NethLink) |
accent |
'emerald' |
the host's accent color, 'emerald' (CTI), 'blue' (NethLink) or 'orange' (WebTop) |
language |
browser | 'it' or 'en', as in phone-island; strings in src/locales/{en,it}.json |
pinnable |
false |
the host has a side rail and panel the chat can be pinned to (see below) |
moveTo |
{ host, label }: the other app the chat windows can move to (NethLink and the CTI), a Move to item in each chat's menu |
The expand button in a chat's header doubles its width (one and a half times its height), within the viewport: a host whose window follows the island, like NethLink, lifts that cap with --ci-max-w / --ci-max-h on .chat-island-root.
With pinnable the chat menu offers Pin to side panel: the host mounts two slots and announces them with chat-island-rail-target and chat-island-pin-target { el } (again on every chat-island-status, since the island may come up later). While the rail slot is there nothing floats: the chat heads render in it (no X: the panel's X takes a chat out and shows the next one) and the open conversation, or the new chat panel, fills the panel slot. chat-island-window { open, picker } tells the host when to show or hide its panel, chat-island-pin { pinned } when the person pins or unpins; the host keeps that choice.
A group's owner changes its picture, name and members from the chat menu (Group settings); each change is a quiet line in the group (no body: no push, no unread) that every member's client refreshes on.
contactsFromOperators(operators, avatars, me) turns the CTI operators into the contacts the island takes with chat-island-contacts. My own entry stays out of the list: it tells the island my presence, and in DND no chat sounds or notifies.
The widget works in any HTML page, CMS or server-rendered application, without React. You need:
- the CDN CSS file;
- the CDN JavaScript bundle;
- an element with class
chat-islandand a Base64 config token indata-config; - optionally, a script of yours that sends commands and listens to the island's browser events.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nethesis/chat-island@latest/dist-widget/index.widget.css" />
</head>
<body>
<div class="chat-island" data-config="YOUR_BASE64_CONFIG_TOKEN" data-theme="system"></div>
<script src="https://cdn.jsdelivr.net/npm/@nethesis/chat-island@latest/dist-widget/index.widget.js"></script>
<script>
window.addEventListener('chat-island-unread', (e) => (document.title = `(${e.detail.total}) My page`))
// open the chat with an operator
window.dispatchEvent(new CustomEvent('chat-island-open', { detail: { username: 'mario' } }))
</script>
</body>
</html>The widget mounts on the .chat-island elements present when its script runs. Attributes:
| Attribute | |
|---|---|
data-config |
Base64 config token (required) |
data-theme |
light, dark or system |
data-position |
bottom-right or bottom-left |
data-service-worker |
URL of chat-island-sw.js, served by your site (same origin) |
data-notifications |
auto to ask for permission once online |
data-new-chat-button |
false to hide the new chat button |
data-pinnable |
true: the host has a rail and a panel to pin the chat to |
data-language |
it or en |
data-max-heads |
chat heads in the dock |
data-density |
compact: about 20% less spacing (font sizes stay), for a host in compact view |
data-accent |
blue or orange: the host's accent color, as the accent prop |
<cti_host>:<cti_username>:<cti_token>
The CTI token comes from the NethVoice middleware login:
TOKEN=$(curl -s -X POST https://cti.example.com/api/login \
-H 'Content-Type: application/json' -d '{"username":"mario","password":"..."}' | jq -r .token)
echo -n "cti.example.com:mario:$TOKEN" | base64 -w0The chat must be on in NethVoice and the user's CTI profile must have the Chat permission. With two-factor authentication, use a token from a QR code login.
A complete example page is in widget-example/; the live demo is index.html.
| Event | Direction | Detail |
|---|---|---|
chat-island-open |
in | { username, search? } operator or group address; search: { query, id? } opens it on a search, at that message; a headless island with moveTo opens it in the other app while that is connected, else moves the chats back here |
chat-island-search |
in | { query } search every conversation's archive (two characters at least) |
chat-island-search-results |
out | { query, results } messages containing it, newest first: { peer, id, ts, body, nick? } |
chat-island-close |
in | |
chat-island-new |
in | open the new chat panel |
chat-island-delete |
in | { username } purge a conversation, leave or destroy a group |
chat-island-send |
in | { username, text } send a text to an operator or group |
chat-island-group-create |
in | { name, members } create a group with these usernames and open it |
chat-island-guest-invite |
in | { id?, name, members? } a chat with people outside: a group with these usernames (or just me) opened to guests; answered by chat-island-guest-link |
chat-island-contacts |
in | { contacts } names, avatars, presence, number; an entry without avatar keeps the known one. Until a host sends it, the island reads the CTI presence again every 30s |
chat-island-conversations-request |
in | ask for the list |
chat-island-theme-change |
in | { theme } light, dark or system, remembered |
chat-island-rail-target |
in | { el } the host's rail slot for the heads while pinned; null to unpin |
chat-island-pin-target |
in | { el } the host's panel for the open conversation while pinned |
chat-island-logout |
in | the host is logging out: push for this browser is dropped, then chat-island-logged-out; wait for it before ending the session |
chat-island-move |
in | { host, open? } move the chat windows to cti or nethlink, opening open there |
chat-island-conversations |
out | { conversations, ready } newest first; ready once groups and recent messages are loaded |
chat-island-unread |
out | { total } |
chat-island-message |
out | every new message |
chat-island-status |
out | { status } connecting, online, offline, error, unauthorized |
chat-island-error |
out | { scope, message } |
chat-island-push |
out | { enabled } |
chat-island-logged-out |
out | answer to chat-island-logout |
chat-island-call |
out | { username, number } |
chat-island-pin |
out | { pinned } the person asked to pin to, or unpin from, the host's panel |
chat-island-window |
out | { open, picker } what a pinned host should show: a conversation, the picker or nothing |
chat-island-host |
out | { host } where the person keeps the chat windows while NethLink runs: nethlink (default) or cti; on start and on every move, from any of their clients |
chat-island-chat-users |
out | { users } the operators whose CTI profile has the chat, on start and every two minutes: the host hides its chat buttons on the others. Not sent when the server cannot tell: then everyone keeps the chat. In the island those colleagues are not offered for a new chat or a group, and a chat with one of them is read-only (nochat in chat-island-conversations) |
chat-island-guest-link |
out | { id, room, link, expires } the invite link of a chat-island-guest-invite (shown only now: the server keeps its hash), or { id, error } |
chat-island-notify |
out | { peer, name, body, kind, author, text, attachment, avatar, ts } message not in view |
An app with its own users (WebTop, an intranet) embeds the widget and builds its view on the events:
- log the user in on the CTI (
/api/login, or a QR code token with two-factor authentication) and pass<cti_host>:<username>:<token>asdata-config; - on
chat-island-statusunauthorized, log in again and set the new token indata-config: the island reconnects in place; - keep its conversation list with
chat-island-conversations-request/chat-island-conversations, badges withchat-island-unread; - drive the island with
chat-island-open,chat-island-close,chat-island-send,chat-island-group-create,chat-island-delete;newChatButton: falsehides the island's entry point while there are no chats (the+under the heads stays); - serve
chat-island-sw.jsfrom its own origin for notifications with the tab closed.
const send = (name, detail) => window.dispatchEvent(new CustomEvent(name, { detail }))
window.addEventListener('chat-island-conversations', (e) => render(e.detail.conversations))
send('chat-island-conversations-request')
send('chat-island-group-create', { name: 'Support', members: ['mario', 'anna'] })
send('chat-island-send', { username: 'mario', text: 'Ciao!' })index.html is published on GitHub Pages by .github/workflows/pages.yml at every push to main, with the widget built from the same commit. It logs in with NethVoice credentials (or a token), mounts the widget and shows its events.
npm install
npm run build:widget
python3 -m http.server # then open http://localhost:8000/npm install
npm run dev
npm run build && npm run build:widgetRelease with npm run publish:patch (or :minor, :major): it checks the version is free on npm, type checks, commits and tags vX.Y.Z, and pushes. The tag publishes the package to npm; jsDelivr serves the widget from it.