@cognitiv-traits/traitos-ui 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +109 -2
- package/dist/traitos-ui.global.js +4462 -0
- package/dist/traitos-ui.global.min.js +247 -0
- package/package.json +32 -4
- package/src/browser.js +8 -0
- package/src/core/api.js +24 -0
- package/src/core/callLog.js +27 -0
- package/src/core/dialerPrefs.js +33 -0
- package/src/core/dialpad.js +74 -0
- package/src/core/flowBuilderController.js +115 -0
- package/src/core/flowModel.js +112 -0
- package/src/core/history.js +24 -0
- package/src/core/settingsController.js +95 -0
- package/src/core/settingsSections.js +199 -0
- package/src/core/softphoneController.js +233 -0
- package/src/core/softphoneState.js +44 -0
- package/src/core/sound.js +101 -0
- package/src/core/strings.js +38 -0
- package/src/core/telnyxAdapter.js +38 -0
- package/src/core/tokenManager.js +67 -0
- package/src/core/widgetState.js +53 -0
- package/src/elements/base.js +74 -0
- package/src/elements/dialerWidget.js +139 -0
- package/src/elements/flowBuilder.js +158 -0
- package/src/elements/keypad.js +74 -0
- package/src/elements/phoneBase.js +172 -0
- package/src/elements/settings.js +184 -0
- package/src/elements/softphone.js +101 -0
- package/src/elements/soundOptions.js +39 -0
- package/src/html.js +24 -0
- package/src/index.js +36 -0
- package/src/theme.js +63 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog — @cognitiv-traits/traitos-ui
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
Peer dependency is now `@cognitiv-traits/traitos-sdk ^0.7.0`.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **`<traitos-dialer-widget>`**: a call icon with a popover (header bar), a floating bubble (`position`) or an embedded open panel (`inline`). Keypad, per-channel call buttons, a compact in-call bar that stays visible while closed, recent calls with redial, a missed-call badge, an `icon` slot, `open()` / `close()` / `toggle()` / `dial()`, Escape and outside-click to close.
|
|
9
|
+
- **Keypad** (`<traitos-keypad>`, and inside the softphone with `allow-dial`): 12 keys, phone-only input, backspace, Enter to call, 7+ digit rule, a call button per enabled channel (`caps`), cancelable `traitos-call` event.
|
|
10
|
+
- **Softphone**: hold, send keypad tones, "call ended" and "missed call" notices, a placing-a-call state, microphone-blocked message, connection warning, local recent-calls log.
|
|
11
|
+
- **Dialer settings section** (`<traitos-settings sections="dialer">`): lines, outbound call mode (real endpoint), and browser-local ring timeout / ringing channels / caller-ID line.
|
|
12
|
+
- **i18n**: every string in one object (`strings` property, `setDefaultStrings`). **Dark mode** (`prefers-color-scheme`, `theme` attribute), 44px touch targets, live regions, reduced-motion.
|
|
13
|
+
- **Sounds**: DTMF key tones or clicks, ringtone, end-of-call beep, spoken digits with a selectable voice and speed, volume; a Sound panel in the widget and softphone (saved per browser).
|
|
14
|
+
- **Recent calls** merge the server's `GET /calls` with the browser's own log.
|
|
15
|
+
- `telnyxAdapter` passes `hold` and `dtmf` through.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- The registration heartbeat kept running after the connection closed (and after a failed start), so a dead browser kept being "rung".
|
|
19
|
+
- Going online twice added every adapter handler twice (double call events).
|
|
20
|
+
- An expired token during the heartbeat was swallowed; the softphone now ends the session with "session expired". Three failed renewals show a warning.
|
|
21
|
+
- Stopping while still connecting could leave the phone online; a failed start left the socket open.
|
|
22
|
+
- Mute toggled with no call; dialing twice quickly placed two calls; `numbers` set after start was ignored.
|
|
23
|
+
- `aria-pressed` rendered empty when false (the escaper dropped `false`).
|
|
24
|
+
- Settings: a second Save while saving, an edit while saving, and a slow load for a previous agent overwriting the current one.
|
|
25
|
+
- Softphone element `numbers` setter now applies after the controller exists.
|
package/README.md
CHANGED
|
@@ -1,3 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cognitiv-traits/traitos-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drop-in TraitOS screens as framework-free web components: a **browser softphone** with keypad, a **dialer widget** for your header bar, **settings forms** (human handoff, approval rules, usage and spend cap) and a **visual call-flow builder**. They use the [SDK](../sdk) and need no build step.
|
|
4
|
+
|
|
5
|
+
Never give a page your API key. Your server creates a short-lived [browser token](https://os.cognitivtraits.us/api/authentication#browser-tokens) and the page renews it with `TokenManager`.
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<traitos-softphone allow-dial></traitos-softphone>
|
|
9
|
+
<traitos-settings agent-id="agent_123" sections="handoff,usage"></traitos-settings>
|
|
10
|
+
<traitos-flow-builder phone-number-id="pn_123"></traitos-flow-builder>
|
|
11
|
+
|
|
12
|
+
<script src="https://unpkg.com/@cognitiv-traits/traitos-ui/dist/traitos-ui.global.min.js"></script>
|
|
13
|
+
<script>
|
|
14
|
+
const { TraitOSClient } = TraitOS, { TokenManager, telnyxAdapter } = TraitOSUI;
|
|
15
|
+
const client = new TraitOSClient({ baseUrl: 'https://os.cognitivtraits.us' });
|
|
16
|
+
// Your backend calls auth.createBrowserToken({ scopes: ['softphone', 'settings', 'events'] }) with its API key
|
|
17
|
+
await new TokenManager(client, () => fetch('/my-backend/traitos-token').then((r) => r.json())).start();
|
|
18
|
+
|
|
19
|
+
for (const el of document.querySelectorAll('traitos-settings, traitos-flow-builder, traitos-softphone')) el.client = client;
|
|
20
|
+
document.querySelector('traitos-softphone').adapter = telnyxAdapter(TelnyxRTC, { remoteElement: document.querySelector('audio') });
|
|
21
|
+
document.querySelector('traitos-flow-builder').agents = [{ id: 'agent_123', name: 'Ava' }];
|
|
22
|
+
</script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
| Element | Token scope | Events |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| `<traitos-dialer-widget>` (`position`, `inline`, `theme`, `live-events`, `auto-start`) | `softphone` (+ `events` for `live-events`) | `traitos-call`, `traitos-state`, `traitos-toggle`, `traitos-error` |
|
|
28
|
+
| `<traitos-keypad>` (`whatsapp-calling`, `phone-calling`) | none (it only fires an event) | `traitos-call` |
|
|
29
|
+
| `<traitos-softphone>` (`allow-dial`, `live-events`, `auto-start`, `theme`) | `softphone` (+ `events` for `live-events`) | `traitos-state`, `traitos-call`, `traitos-error` |
|
|
30
|
+
| `<traitos-settings>` (`agent-id`, `sections`) | `settings` | `traitos-saved`, `traitos-error` |
|
|
31
|
+
| `<traitos-flow-builder>` (`phone-number-id`; properties `agents`, `team`) | `settings` | `traitos-saved`, `traitos-error` |
|
|
32
|
+
|
|
33
|
+
The softphone's WebRTC is an adapter you pass in (`telnyxAdapter` wraps the `TelnyxRTC` class you load), so this package has no vendor dependency.
|
|
34
|
+
|
|
35
|
+
## Dialer: keypad, header widget, in-call controls
|
|
36
|
+
|
|
37
|
+
`<traitos-dialer-widget>` is a call icon that opens a small panel with a keypad, per-channel call buttons, a compact in-call bar and recent calls. `<traitos-softphone allow-dial>` shows the same keypad in a full card. Both take `client` and `adapter` the same way.
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<!-- a header bar: the panel opens below the icon -->
|
|
41
|
+
<traitos-dialer-widget id="phone">
|
|
42
|
+
<span slot="icon" class="material-icons">call</span> <!-- optional: your own icon -->
|
|
43
|
+
</traitos-dialer-widget>
|
|
44
|
+
|
|
45
|
+
<traitos-dialer-widget position="bottom-right"></traitos-dialer-widget> <!-- floating bubble: bottom-right|bottom-left|top-right|top-left -->
|
|
46
|
+
<traitos-dialer-widget inline></traitos-dialer-widget> <!-- the panel, always open, inside a page section -->
|
|
47
|
+
|
|
48
|
+
<script>
|
|
49
|
+
const phone = document.getElementById('phone');
|
|
50
|
+
phone.client = client; // a TraitOSClient with a `softphone` browser token
|
|
51
|
+
phone.adapter = telnyxAdapter(TelnyxRTC, { remoteElement: audioEl });
|
|
52
|
+
phone.caps = { whatsappCallingEnabled: true, phoneCallingEnabled: true }; // only enabled channels get a button
|
|
53
|
+
phone.addEventListener('traitos-call', (e) => console.log(e.detail)); // { number: '18765550101', channel: 'whatsapp' | 'phone' }
|
|
54
|
+
</script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- **Keypad**: 12 keys (hold `0` for `+`), a number box that only accepts phone characters, backspace, Enter to call. A call needs **7 or more digits** (country code included); `traitos-call` carries digits only. Enter calls on WhatsApp when it is enabled, otherwise on phone.
|
|
58
|
+
- **`traitos-call` is cancelable.** If you do not `preventDefault()`, a **phone** call is placed for you (`calls.create({ channel: 'phone', to, agentSipUsername })`, bridged to this softphone). A **WhatsApp** call needs credentials, so set `el.whatsapp = { from, sipHostname, sipPassword, ... }`; without it the widget fires the event and shows "WhatsApp calling is not set up". Or call `preventDefault()` and place any call yourself.
|
|
59
|
+
- **`caps`**: set it, or leave it out and the element reads the workspace's phone lines (`GET /telephony/numbers`, allowed for `softphone` and `settings` browser tokens on a server with the dialer scopes) and falls back to phone-only if that fails.
|
|
60
|
+
- **In a call**: mute, hold and send keypad tones (when your adapter's call object has `hold(on)` / `dtmf(digit)`; `telnyxAdapter` does), a timer, and "Call ended" / "Missed call" notices. Ringing and connecting have their own states, a blocked microphone gets its own message, and an expired token ends the session with a clear error instead of silently stopping.
|
|
61
|
+
- **Recent calls**: the server's list (`GET /calls`, newest first) merged with the calls this browser handled (kept in `localStorage`), shown once each, with one-click redial and a badge for missed calls. If the token or server cannot list calls, the browser's own log still shows.
|
|
62
|
+
- **Sounds**: real DTMF key tones (or a click), a ringtone while a call rings, an end-of-call beep, and optional spoken digits in a voice you pick from the browser's installed voices. A "Sound" button in the panel opens volume, key sound, ringtone, voice and speed; choices are saved in this browser. `el.sound.update({ enabled: false })` turns sounds off from code. Browsers only allow audio after the user has clicked or typed on the page, so a ringtone for the very first call may stay silent until then.
|
|
63
|
+
- **Widget API**: `open()`, `close()`, `toggle()`, `dial(number, channel)`, `isOpen`; events `traitos-toggle` `{open}`, `traitos-state`, `traitos-error`. It closes on Escape (focus returns to the icon) and on an outside click, is a non-modal `dialog`, and never traps focus or blocks the page.
|
|
64
|
+
- **Words**: `el.strings = { call: ... }` per element, or `TraitOSUI.setDefaultStrings({...})` for the page; `TraitOSUI.DEFAULT_STRINGS` lists every key.
|
|
65
|
+
- **Dialer settings**: `<traitos-settings sections="dialer">` shows your phone lines, the outbound mode (`direct` / `agent-first`, admin only) and, saved in this browser, the ring timeout, which channels ring this browser and the caller-ID line. (A `settings` browser token can read and change these; changing the outbound mode still needs it to be minted by an admin.)
|
|
66
|
+
|
|
67
|
+
### AngularJS (1.x)
|
|
68
|
+
|
|
69
|
+
AngularJS binds attributes, not properties, on custom elements, so a three-line directive hands over the objects and turns events back into callbacks:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
angular.module('app').directive('tosPhone', function () {
|
|
73
|
+
return {
|
|
74
|
+
restrict: 'A',
|
|
75
|
+
scope: { client: '<', adapter: '<', caps: '<', whatsapp: '<', onCall: '&' },
|
|
76
|
+
link: function (scope, el) {
|
|
77
|
+
var w = el[0];
|
|
78
|
+
['client', 'adapter', 'caps', 'whatsapp'].forEach(function (k) { scope.$watch(k, function (v) { if (v) w[k] = v; }); });
|
|
79
|
+
w.addEventListener('traitos-call', function (e) { scope.$applyAsync(function () { scope.onCall({ number: e.detail.number, channel: e.detail.channel }); }); });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```html
|
|
86
|
+
<!-- header phone menu -->
|
|
87
|
+
<traitos-dialer-widget tos-phone client="vm.client" adapter="vm.adapter" caps="vm.voiceCaps"
|
|
88
|
+
on-call="vm.dialFromPad(number, channel)">
|
|
89
|
+
<i slot="icon" class="material-icons">call</i>
|
|
90
|
+
</traitos-dialer-widget>
|
|
91
|
+
|
|
92
|
+
<!-- a page section -->
|
|
93
|
+
<traitos-dialer-widget inline tos-phone client="vm.client" adapter="vm.adapter" caps="vm.voiceCaps" on-call="vm.dialFromPad(number, channel)"></traitos-dialer-widget>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`caps` must be a stable object (not a new one on every digest). If your handler places the call itself, add `e.preventDefault()` in the listener.
|
|
97
|
+
|
|
98
|
+
## Theming
|
|
99
|
+
|
|
100
|
+
Set CSS custom properties from outside: `--traitos-accent`, `--traitos-bg`, `--traitos-text`, `--traitos-muted`, `--traitos-line`, `--traitos-key-bg`, `--traitos-ok`, `--traitos-warn`, `--traitos-danger`, `--traitos-whatsapp`, `--traitos-phone`, `--traitos-radius`, `--traitos-font`, `--traitos-z` (floating widget). Dark mode follows `prefers-color-scheme`; force it with `theme="dark"` or `theme="light"`. Your variables win in both modes. Touch targets are at least 44px, focus rings are always visible, call state is announced through live regions, and animation stops under `prefers-reduced-motion`.
|
|
101
|
+
|
|
102
|
+
## Use the logic without the elements
|
|
103
|
+
|
|
104
|
+
Everything the elements do lives in plain controllers: `SoftphoneController`, `createDialpad`, `CallLog`, `SettingsController`, `FlowBuilderController`, and the pure flow model (`addRoute`, `validateFlow`, `describeFlow`, ...). Render them with React, Vue or anything else, and subscribe with `controller.subscribe(fn)`.
|
|
105
|
+
|
|
106
|
+
## Safety
|
|
107
|
+
|
|
108
|
+
Text from customers (caller names, labels, errors) is escaped by default; nothing is inserted as markup. Saving a flow changes how live calls are answered, so the builder asks the server to validate first and only saves valid flows.
|
|
109
|
+
|
|
110
|
+
Apache-2.0
|