@onedeskpro/chatbot-core 0.3.1 → 0.5.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 +8 -5
- package/dist/index.cjs +59 -27
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.iife.js +59 -27
- package/dist/index.js +475 -332
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -71,9 +71,9 @@ Every conversation runs in one of four modes, exposed as `getState().mode`:
|
|
|
71
71
|
| `ai` | The AI agent is answering. This is the default. |
|
|
72
72
|
| `waiting` | A human was requested and no agent has picked the conversation up yet. |
|
|
73
73
|
| `human` | A human agent is replying. Their messages arrive live with `type: 'agent'`. |
|
|
74
|
-
| `closed` | The conversation was closed. Sending is disabled until `resetSession()`. |
|
|
74
|
+
| `closed` | The conversation was closed. Sending is disabled until `startNewConversation()` or `resetSession()`. |
|
|
75
75
|
|
|
76
|
-
The widget shows a "Request human agent" control once a conversation has started, and a banner for the `waiting`, `human`, and `closed` modes. From your own UI call `requestHuman()`. The mode also changes on its own — when the AI escalates, an agent takes over, hands back to the AI, or closes the conversation — so follow the `ticket-status` or `state-change` event rather than assuming the result of your own call.
|
|
76
|
+
The widget shows a "Request human agent" control once a conversation has started, and a banner for the `waiting`, `human`, and `closed` modes. While `waiting`, the banner has a **Cancel request** button that hands the conversation back to the AI. The header's **New conversation** button ends the current conversation in any mode, after a confirmation unless it is already closed. From your own UI call `requestHuman()`, `cancelHumanRequest()`, and `startNewConversation()`. The mode also changes on its own — when the AI escalates, an agent takes over, hands back to the AI, or closes the conversation — so follow the `ticket-status` or `state-change` event rather than assuming the result of your own call.
|
|
77
77
|
|
|
78
78
|
### Script tag / CDN
|
|
79
79
|
|
|
@@ -100,6 +100,8 @@ The IIFE build exposes a `window.OnedeskProChatbot` global:
|
|
|
100
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
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. |
|
|
102
102
|
| `requestHuman()` | Escalates the conversation to a human agent. Does nothing unless the mode is `ai` and a conversation has started. Returns a promise. |
|
|
103
|
+
| `cancelHumanRequest()` | Withdraws a pending human request so the AI answers again. Does nothing unless the mode is `waiting`. If an agent accepted the conversation in the meantime, the mode moves to `human` instead. Returns a promise. |
|
|
104
|
+
| `startNewConversation()` | Ends the current conversation in any mode and starts a fresh one: the API closes the open ticket and gives the AI a new memory, then `messages` is cleared and the mode returns to `ai`. Returns a promise. |
|
|
103
105
|
| `open()` / `close()` / `toggle()` | Control widget visibility. |
|
|
104
106
|
| `resetSession()` | Clears a `closed` conversation so the visitor can start a new one. Does nothing in any other mode. |
|
|
105
107
|
| `getState()` | Returns a readonly `ChatbotState` snapshot. |
|
|
@@ -128,7 +130,7 @@ The IIFE build exposes a `window.OnedeskProChatbot` global:
|
|
|
128
130
|
| Field | Type | Meaning |
|
|
129
131
|
| --- | --- | --- |
|
|
130
132
|
| `isOpen` | `boolean` | The panel is showing. |
|
|
131
|
-
| `isLoading` | `boolean` | A send, identify,
|
|
133
|
+
| `isLoading` | `boolean` | A send, identify, human request, cancel, or new conversation is in flight. |
|
|
132
134
|
| `isReady` | `boolean` | The server answered and the agent can reply; the widget is on the page. |
|
|
133
135
|
| `needsIdentify` | `boolean` | The visitor has not identified yet. |
|
|
134
136
|
| `blockReason` | `ChatbotBlockReason` | Why the agent cannot answer, or `null`. See [When the widget appears](#when-the-widget-appears). |
|
|
@@ -148,8 +150,9 @@ The IIFE build exposes a `window.OnedeskProChatbot` global:
|
|
|
148
150
|
| `open` / `close` | — | The panel is shown or hidden. |
|
|
149
151
|
| `ticket-status` | `TicketStatusData` | The mode changed — on restore, after a send, or pushed live. |
|
|
150
152
|
| `human-requested` | — | `requestHuman()` succeeded. |
|
|
151
|
-
| `
|
|
152
|
-
| `
|
|
153
|
+
| `human-request-cancelled` | — | `cancelHumanRequest()` handed the conversation back to the AI. |
|
|
154
|
+
| `error` | `Error` | A send, identify, human request, cancel, or new conversation failed (including on timeout), or the live connection could not be established. |
|
|
155
|
+
| `session-reset` | — | The chat was cleared for a new conversation (`startNewConversation()` or `resetSession()`). |
|
|
153
156
|
|
|
154
157
|
Prefer `state-change` when you are mirroring state into your own UI — it is the only event that covers every transition.
|
|
155
158
|
|