@unboundcx/sdk 4.13.25 → 4.13.27
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/package.json +1 -1
- package/services/webchat.js +120 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.27",
|
|
4
4
|
"description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/services/webchat.js
CHANGED
|
@@ -164,9 +164,129 @@ export class WebchatWidgetsService {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
export class WebchatConversationMessagesService {
|
|
168
|
+
constructor(sdk) {
|
|
169
|
+
this.sdk = sdk;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* List messages for a webchat conversation (agent view).
|
|
174
|
+
* @param {string} widgetId
|
|
175
|
+
* @param {string} engagementSessionId
|
|
176
|
+
* @param {Object} [options]
|
|
177
|
+
* @param {string} [options.before] - cursor: return messages created before this
|
|
178
|
+
* @param {number} [options.limit]
|
|
179
|
+
* @returns {Promise<Array<Object>>}
|
|
180
|
+
*/
|
|
181
|
+
async list(widgetId, engagementSessionId, options = {}) {
|
|
182
|
+
this.sdk.validateParams(
|
|
183
|
+
{ widgetId, engagementSessionId },
|
|
184
|
+
{
|
|
185
|
+
widgetId: { type: 'string', required: true },
|
|
186
|
+
engagementSessionId: { type: 'string', required: true },
|
|
187
|
+
},
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const { before, limit } = options;
|
|
191
|
+
|
|
192
|
+
return internalRequest(
|
|
193
|
+
this.sdk,
|
|
194
|
+
`/webchat/widgets/${widgetId}/conversations/${engagementSessionId}/messages`,
|
|
195
|
+
'GET',
|
|
196
|
+
{ query: { before, limit } },
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Send a message into a webchat conversation as an agent.
|
|
202
|
+
* @param {string} widgetId
|
|
203
|
+
* @param {string} engagementSessionId
|
|
204
|
+
* @param {Object} options
|
|
205
|
+
* @param {string} options.message
|
|
206
|
+
* @param {Object} [options.media]
|
|
207
|
+
* @returns {Promise<Object>}
|
|
208
|
+
*/
|
|
209
|
+
async send(widgetId, engagementSessionId, options) {
|
|
210
|
+
this.sdk.validateParams(
|
|
211
|
+
{
|
|
212
|
+
widgetId,
|
|
213
|
+
engagementSessionId,
|
|
214
|
+
message: options?.message,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
widgetId: { type: 'string', required: true },
|
|
218
|
+
engagementSessionId: { type: 'string', required: true },
|
|
219
|
+
message: { type: 'string', required: true },
|
|
220
|
+
},
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const params = { body: { ...options } };
|
|
224
|
+
|
|
225
|
+
return internalRequest(
|
|
226
|
+
this.sdk,
|
|
227
|
+
`/webchat/widgets/${widgetId}/conversations/${engagementSessionId}/messages`,
|
|
228
|
+
'POST',
|
|
229
|
+
params,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export class WebchatConversationsService {
|
|
235
|
+
constructor(sdk) {
|
|
236
|
+
this.sdk = sdk;
|
|
237
|
+
this.messages = new WebchatConversationMessagesService(sdk);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Send a typing indicator into a webchat conversation as an agent.
|
|
242
|
+
* @param {string} widgetId
|
|
243
|
+
* @param {string} engagementSessionId
|
|
244
|
+
* @param {boolean} isTyping
|
|
245
|
+
* @returns {Promise<Object>}
|
|
246
|
+
*/
|
|
247
|
+
async typing(widgetId, engagementSessionId, isTyping) {
|
|
248
|
+
this.sdk.validateParams(
|
|
249
|
+
{ widgetId, engagementSessionId },
|
|
250
|
+
{
|
|
251
|
+
widgetId: { type: 'string', required: true },
|
|
252
|
+
engagementSessionId: { type: 'string', required: true },
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const params = { body: { isTyping: isTyping !== false } };
|
|
257
|
+
|
|
258
|
+
return internalRequest(
|
|
259
|
+
this.sdk,
|
|
260
|
+
`/webchat/widgets/${widgetId}/conversations/${engagementSessionId}/typing`,
|
|
261
|
+
'POST',
|
|
262
|
+
params,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Look up a webchat conversation by engagementSessionId -- resolves the
|
|
268
|
+
* widgetId + verified-visitor badge data for the agent thread.
|
|
269
|
+
* @param {string} engagementSessionId
|
|
270
|
+
* @returns {Promise<Object>}
|
|
271
|
+
*/
|
|
272
|
+
async get(engagementSessionId) {
|
|
273
|
+
this.sdk.validateParams(
|
|
274
|
+
{ engagementSessionId },
|
|
275
|
+
{ engagementSessionId: { type: 'string', required: true } },
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
return internalRequest(
|
|
279
|
+
this.sdk,
|
|
280
|
+
`/webchat/widgets/conversations/${engagementSessionId}`,
|
|
281
|
+
'GET',
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
167
286
|
export class WebchatService {
|
|
168
287
|
constructor(sdk) {
|
|
169
288
|
this.sdk = sdk;
|
|
170
289
|
this.widgets = new WebchatWidgetsService(sdk);
|
|
290
|
+
this.conversations = new WebchatConversationsService(sdk);
|
|
171
291
|
}
|
|
172
292
|
}
|