@zoomrx/zena-chatbot-client 1.0.3 → 1.0.5
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 +53 -0
- package/dist/zena-chatbot-client.iife.js +5842 -5687
- package/dist/zena-chatbot-client.iife.js.map +1 -1
- package/dist/zena-chatbot-client.js +254 -252
- package/dist/zena-chatbot-client.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,6 +115,8 @@ All of these can alternatively be passed via `get-config` (see Events below). Wh
|
|
|
115
115
|
|---|---|---|
|
|
116
116
|
| `get-config` | `{ resolve }` | Fired once on init. Call `resolve(config)` to provide sensitive credentials. See below. |
|
|
117
117
|
| `before-send` | `{ message, resolve }` | Fired before each message is sent. Call `resolve(data)` with any extra data to merge into the request. |
|
|
118
|
+
| `get-available-surveys` | `{ resolve }` | Fired once when the chat is first opened. Call `resolve(ids)` with the user's available survey IDs so the widget can skip its own fetch. See below. |
|
|
119
|
+
| `sentry-additionaldata` | `{ event, resolve }` | Fired before an error is sent to Sentry. Call `resolve(context)` with `{ tags, extra }` to enrich it, or `resolve(null)` to send it unchanged. See below. |
|
|
118
120
|
| `stuck-survey-selected` | `{ survey }` | Fire-and-forget. Fired when the user selects a survey from a stuck-survey dropdown, before the support ticket is created. |
|
|
119
121
|
|
|
120
122
|
#### `get-config`
|
|
@@ -159,6 +161,57 @@ chatbot.on('before-send', ({ message, resolve }) => {
|
|
|
159
161
|
});
|
|
160
162
|
```
|
|
161
163
|
|
|
164
|
+
#### `get-available-surveys`
|
|
165
|
+
|
|
166
|
+
Fired **once, when the chat is first opened** (not on mount), so the widget can
|
|
167
|
+
learn which surveys the user currently has available — needed to answer
|
|
168
|
+
"is this survey still available?" prompts. Asking lazily at open time means the
|
|
169
|
+
host's survey list has finished loading, avoiding the staleness of a value
|
|
170
|
+
frozen at connect.
|
|
171
|
+
|
|
172
|
+
Call `resolve` with an array of survey IDs (numbers or strings). Resolve `null`
|
|
173
|
+
(or an empty array) if the host has no list to share — the widget then falls
|
|
174
|
+
back to fetching `users/get_surveys` itself. If the host does not answer within
|
|
175
|
+
~1.5 seconds, the widget assumes no list and fetches.
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
chatbot.on('get-available-surveys', ({ resolve }) => {
|
|
179
|
+
// Host already has the user's surveys loaded — hand over the IDs.
|
|
180
|
+
resolve(surveys.map(s => s.survey?.id).filter(Boolean));
|
|
181
|
+
// ...or, when the host has no such list (e.g. inside a survey):
|
|
182
|
+
// resolve(null);
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
When the host supplies IDs this way (or via the `available-survey-ids`
|
|
187
|
+
attribute / `availableSurveyIds` config), the widget makes **no**
|
|
188
|
+
`users/get_surveys` call.
|
|
189
|
+
|
|
190
|
+
#### `sentry-additionaldata`
|
|
191
|
+
|
|
192
|
+
Fired **before each error is sent to Sentry**, letting the host attach its own
|
|
193
|
+
context. The component's `@sentry/browser` captures every error on the page —
|
|
194
|
+
including the host's own unhandled rejections — so a host typically filters by
|
|
195
|
+
origin and only enriches its own errors.
|
|
196
|
+
|
|
197
|
+
The payload is `{ event, resolve }`, where `event` is the Sentry `ErrorEvent`
|
|
198
|
+
about to be sent. Call `resolve({ tags, extra })` to merge in context, or
|
|
199
|
+
`resolve(null)` to send the event unchanged. If the host does not answer within
|
|
200
|
+
the timeout, the event is sent with no extra data.
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
chatbot.on('sentry-additionaldata', ({ event, resolve }) => {
|
|
204
|
+
// Inspect event (e.g. by stack-frame origin) to decide whether it's yours
|
|
205
|
+
const isMine = event?.exception?.values?.[0]?.stacktrace?.frames
|
|
206
|
+
?.some(f => (f.filename || '').includes('/my-app/'));
|
|
207
|
+
if (!isMine) return resolve(null);
|
|
208
|
+
resolve({
|
|
209
|
+
tags: { module: 'survey' },
|
|
210
|
+
extra: { responseId: 123 },
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
162
215
|
#### `stuck-survey-selected`
|
|
163
216
|
|
|
164
217
|
Fired when the user picks a survey from a `stuck_survey_dropdown` response. Fires **before** the support-ticket API call — the host receives it even if ticket creation subsequently fails.
|