@onedeskpro/chatbot-core 0.2.0 → 0.3.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/README.md +26 -6
- package/dist/index.cjs +253 -41
- package/dist/index.d.cts +125 -2
- package/dist/index.d.ts +125 -2
- package/dist/index.iife.js +253 -41
- package/dist/index.js +1347 -462
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -28,7 +28,23 @@ await chatbot.init({
|
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
`init`
|
|
31
|
+
`init` connects to the Onedesk Pro API and adds the widget to the page once the agent can reply. Only `apiKey` is required — use the publishable workspace API key, never a server secret.
|
|
32
|
+
|
|
33
|
+
### When the widget appears
|
|
34
|
+
|
|
35
|
+
Nothing is added to the page straight away. `init` first checks that the Onedesk Pro server is reachable and that the agent is ready to reply, and the launcher appears only once both hold and a returning visitor's identity has been checked:
|
|
36
|
+
|
|
37
|
+
| Situation | `blockReason` | What happens |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| Ready | `null` | The launcher appears (and the panel opens, with `autoOpen`). |
|
|
40
|
+
| The server cannot be reached, times out, or answers with a 5xx | `server-unavailable` | Stays hidden and checks again after 5, 15, 30 and 60 seconds, then gives up until the next page load. |
|
|
41
|
+
| The agent has no system prompt or no knowledge base | `no-prompt`, `no-collections` | Stays hidden. |
|
|
42
|
+
| The platform's AI models are not configured | `ai-unavailable` | Stays hidden. |
|
|
43
|
+
| The workspace has used its AI token budget | `no-credits` | Stays hidden. |
|
|
44
|
+
| No agent is assigned to the Website channel | `no-agent` | Stays hidden. |
|
|
45
|
+
| The API key is rejected or the site's origin is not allowed | `null`, with `error` set | Stays hidden. |
|
|
46
|
+
|
|
47
|
+
`init` resolves after the first check, and the `ready` event fires once the outcome is settled: when the widget appears, when a configuration problem rules it out, or when the last retry fails. A custom UI built on the state can show `blockReason` to explain why chat is unavailable.
|
|
32
48
|
|
|
33
49
|
### Visitor identification
|
|
34
50
|
|
|
@@ -81,6 +97,8 @@ The IIFE build exposes a `window.OnedeskProChatbot` global:
|
|
|
81
97
|
| `init(options)` | Mounts the widget and loads remote config. Returns a promise. |
|
|
82
98
|
| `submitIdentify({ name, phone, email? })` | Identifies the visitor and unlocks the chat. Returns a promise. |
|
|
83
99
|
| `sendMessage(text)` | Sends a message and, in `ai` mode, appends the reply. Returns a promise that rejects if the visitor has not identified. |
|
|
100
|
+
| `sendAttachments(files, text?)` | Sends up to 10 files (10 MB each) as one media message, with `text` as the caption. Each file is uploaded through the API first; the message sits in `messages` with `pending: true` and local previews until then. Rejects if the visitor has not identified; a file over the limits sets `error` instead. |
|
|
101
|
+
| `sendVoice(recording)` | Sends a voice note. `recording` is `{ blob, mimeType?, durationSeconds }`, as `VoiceRecorder` produces; it is re-encoded as mono WAV with a waveform where Web Audio allows, uploaded, and stored as a `voice` message. Rejects if the visitor has not identified. |
|
|
84
102
|
| `requestHuman()` | Escalates the conversation to a human agent. Does nothing unless the mode is `ai` and a conversation has started. Returns a promise. |
|
|
85
103
|
| `open()` / `close()` / `toggle()` | Control widget visibility. |
|
|
86
104
|
| `resetSession()` | Clears a `closed` conversation so the visitor can start a new one. Does nothing in any other mode. |
|
|
@@ -111,10 +129,10 @@ The IIFE build exposes a `window.OnedeskProChatbot` global:
|
|
|
111
129
|
| --- | --- | --- |
|
|
112
130
|
| `isOpen` | `boolean` | The panel is showing. |
|
|
113
131
|
| `isLoading` | `boolean` | A send, identify, or human request is in flight. |
|
|
114
|
-
| `isReady` | `boolean` |
|
|
132
|
+
| `isReady` | `boolean` | The server answered and the agent can reply; the widget is on the page. |
|
|
115
133
|
| `needsIdentify` | `boolean` | The visitor has not identified yet. |
|
|
116
|
-
| `blockReason` | `ChatbotBlockReason` | Why the agent cannot answer, or `null`. |
|
|
117
|
-
| `messages` | `ChatMessage[]` | The conversation so far. `message.type` is `'human'`, `'ai'`, or `'agent'`. |
|
|
134
|
+
| `blockReason` | `ChatbotBlockReason` | Why the agent cannot answer, or `null`. See [When the widget appears](#when-the-widget-appears). |
|
|
135
|
+
| `messages` | `ChatMessage[]` | The conversation so far. `message.type` is `'human'`, `'ai'`, or `'agent'`. A media message carries `message.attachments` (`type`, `url`, `fileName`, `size`) and `pending: true` while its files upload. |
|
|
118
136
|
| `visitorToken` | `string \| null` | The identified visitor's token. |
|
|
119
137
|
| `visitorName` | `string \| null` | The identified visitor's name. |
|
|
120
138
|
| `mode` | `ChatbotTicketMode` | `'ai'`, `'waiting'`, `'human'`, or `'closed'`. |
|
|
@@ -126,7 +144,7 @@ The IIFE build exposes a `window.OnedeskProChatbot` global:
|
|
|
126
144
|
| --- | --- | --- |
|
|
127
145
|
| `message` | `ChatMessage` | A message is added — visitor, AI, and human agent alike. |
|
|
128
146
|
| `state-change` | `ChatbotState` | Any state changes, including `isLoading` while a reply is in flight. |
|
|
129
|
-
| `ready` | — |
|
|
147
|
+
| `ready` | — | The readiness check settled: the widget appeared, or it will not (see `blockReason` and `error`). |
|
|
130
148
|
| `open` / `close` | — | The panel is shown or hidden. |
|
|
131
149
|
| `ticket-status` | `TicketStatusData` | The mode changed — on restore, after a send, or pushed live. |
|
|
132
150
|
| `human-requested` | — | `requestHuman()` succeeded. |
|
|
@@ -142,7 +160,9 @@ off(); // unsubscribe
|
|
|
142
160
|
|
|
143
161
|
## Also exported
|
|
144
162
|
|
|
145
|
-
`ApiClient`, `SdkSocket`, `resolveSdkSocketUrl`, `EventEmitter`, `SessionManager`, `isChatbotRequestError`, `DEFAULT_API_BASE_URL`, `DEFAULT_REQUEST_TIMEOUT_MS`, the `ChatbotRequestError` and `
|
|
163
|
+
`ApiClient`, `SdkSocket`, `resolveSdkSocketUrl`, `EventEmitter`, `SessionManager`, `VoiceRecorder`, `isChatbotRequestError`, `DEFAULT_API_BASE_URL`, `DEFAULT_REQUEST_TIMEOUT_MS`, `SDK_UPLOAD_MAX_BYTES`, `SDK_CHAT_MAX_ATTACHMENTS`, `VOICE_MAX_DURATION_SECONDS`, the `ChatbotRequestError`, `SdkSocketConnectOptions`, `VoiceRecorderSnapshot` and `VoiceRecorderState` types, and every type from `@onedeskpro/chatbot-types`.
|
|
164
|
+
|
|
165
|
+
`VoiceRecorder` records with `MediaRecorder` for custom UIs: `new VoiceRecorder(onChange)`, then `start()`, `stop()` (resolves with the recording to pass to `sendVoice`), `cancel()`, and `destroy()`. `onChange` receives `{ state, elapsedSeconds, level, result }`. Recording stops on its own at `VOICE_MAX_DURATION_SECONDS` (5 minutes).
|
|
146
166
|
|
|
147
167
|
`SessionManager` is deprecated. It is now the visitor token store and is kept only so existing imports keep resolving.
|
|
148
168
|
|