@dawntech/blip-tools 0.3.1 → 0.4.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/dist/exceptions/index.d.ts +5 -0
- package/dist/helpers/validate-instance.d.ts +1 -1
- package/dist/index.cjs +619 -0
- package/dist/index.d.ts +4 -110
- package/dist/{index.js → index.mjs} +423 -149
- package/dist/modules/blip-attendance.d.ts +11 -0
- package/dist/modules/blip-bucket.d.ts +3 -1
- package/dist/modules/blip-contact.d.ts +15 -0
- package/dist/modules/blip-context.d.ts +19 -0
- package/dist/modules/blip-dispatch.d.ts +63 -0
- package/dist/modules/blip-event.d.ts +12 -0
- package/dist/modules/blip-interaction.d.ts +13 -0
- package/dist/modules/blip-main.d.ts +25 -0
- package/dist/modules/blip-media.d.ts +3 -1
- package/dist/modules/blip-ticket.d.ts +12 -0
- package/dist/modules/blip-whatsapp.d.ts +10 -0
- package/dist/modules/index.d.ts +11 -0
- package/dist/types/attendance-hour-container.d.ts +25 -0
- package/dist/types/blip-constructor.d.ts +4 -0
- package/dist/types/blip.d.ts +26 -0
- package/dist/types/campaign-notification-status.d.ts +21 -0
- package/dist/types/campaign-notification.d.ts +14 -0
- package/dist/types/campaing-request.d.ts +26 -0
- package/dist/types/contact.d.ts +8 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/template.d.ts +18 -0
- package/dist/types/ticket-search-result.d.ts +6 -0
- package/dist/types/ticket.d.ts +17 -0
- package/package.json +20 -5
- package/dist/exceptions/blip-error.js +0 -7
- package/dist/helpers/encode-blip-params.js +0 -11
- package/dist/helpers/encode-strings.js +0 -3
- package/dist/helpers/format-template-params.js +0 -6
- package/dist/helpers/handle-error.js +0 -14
- package/dist/helpers/validate-instance.js +0 -9
- package/dist/helpers/validate-response.js +0 -6
- package/dist/modules/blip-bucket.js +0 -88
- package/dist/modules/blip-media.js +0 -55
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BlipConstructor } from '../types/blip-constructor
|
|
1
|
+
import { BlipConstructor } from '../types/blip-constructor';
|
|
2
2
|
export default function validateInstance(params: BlipConstructor): void;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
var axios = require('axios');
|
|
5
|
+
|
|
6
|
+
function encodeString(value) {
|
|
7
|
+
return String(value).replaceAll(' ', '%20');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function encodeBlipParams(params) {
|
|
11
|
+
//This function does not uses any of the standard methods of URI parsing because Blip does not follow any of them
|
|
12
|
+
const parsedParams = [];
|
|
13
|
+
for (const [key, value] of Object.entries(params)) {
|
|
14
|
+
if (value && key) {
|
|
15
|
+
parsedParams.push(`${encodeString(key)}=${encodeString(value)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return parsedParams.join('&');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class BlipError extends Error {
|
|
22
|
+
code;
|
|
23
|
+
constructor(message, code = 0) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.code = code;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function validateResponse(response) {
|
|
30
|
+
if (response.data.status === 'failure') {
|
|
31
|
+
throw new BlipError(response.data.reason.description, response.data.reason.code);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleError(error) {
|
|
36
|
+
if (error instanceof BlipError) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
if (error instanceof axios.AxiosError) {
|
|
40
|
+
if (error.response?.data.code) {
|
|
41
|
+
throw new BlipError(error.response?.data.description, error.response?.data.code);
|
|
42
|
+
}
|
|
43
|
+
throw new BlipError(error.message, 0);
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class BlipBucket {
|
|
49
|
+
api;
|
|
50
|
+
constructor(context) {
|
|
51
|
+
this.api = context.api;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
Stores JSON content in a bucket provided by Blip. The content can be updaded or retrieved using the same id used in the update.
|
|
55
|
+
You can optionally provide a expiration time (in milliseconds) to delete the document after a certain amount of time.
|
|
56
|
+
*/
|
|
57
|
+
async storeContentInBucket(id, content, opts) {
|
|
58
|
+
try {
|
|
59
|
+
let uri = `/buckets/${encodeString(id)}`;
|
|
60
|
+
const params = {};
|
|
61
|
+
if (opts?.expiresInMs) {
|
|
62
|
+
params.expiration = opts?.expiresInMs;
|
|
63
|
+
uri += `?${encodeBlipParams(params)}`;
|
|
64
|
+
}
|
|
65
|
+
const body = {
|
|
66
|
+
id: crypto.randomUUID(),
|
|
67
|
+
method: 'set',
|
|
68
|
+
type: 'application/json',
|
|
69
|
+
uri,
|
|
70
|
+
resource: content,
|
|
71
|
+
};
|
|
72
|
+
const response = await this.api.post('/commands', body);
|
|
73
|
+
validateResponse(response);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw handleError(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
Retrieves a document from the Blip bucket.
|
|
81
|
+
*/
|
|
82
|
+
async getContentFromBucket(id) {
|
|
83
|
+
try {
|
|
84
|
+
const body = {
|
|
85
|
+
id: crypto.randomUUID(),
|
|
86
|
+
method: 'get',
|
|
87
|
+
uri: `/buckets/${encodeString(id)}`,
|
|
88
|
+
};
|
|
89
|
+
const response = await this.api.post('/commands', body);
|
|
90
|
+
validateResponse(response);
|
|
91
|
+
return response.data.resource;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw handleError(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async getAllContentIdsFromBucket() {
|
|
98
|
+
try {
|
|
99
|
+
const body = {
|
|
100
|
+
id: crypto.randomUUID(),
|
|
101
|
+
method: 'get',
|
|
102
|
+
uri: `/buckets`,
|
|
103
|
+
};
|
|
104
|
+
const response = await this.api.post('/commands', body);
|
|
105
|
+
validateResponse(response);
|
|
106
|
+
return response.data.resource.items;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw handleError(error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
Deletes a JSON document from the Blip bucket.
|
|
114
|
+
*/
|
|
115
|
+
async deleteContentFromBucket(id) {
|
|
116
|
+
try {
|
|
117
|
+
const body = {
|
|
118
|
+
id: crypto.randomUUID(),
|
|
119
|
+
method: 'delete',
|
|
120
|
+
uri: `/buckets/${encodeString(id)}`,
|
|
121
|
+
to: 'postmaster@msging.net',
|
|
122
|
+
};
|
|
123
|
+
const response = await this.api.post('/commands', body);
|
|
124
|
+
validateResponse(response);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw handleError(error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
class BlipMedia {
|
|
133
|
+
api;
|
|
134
|
+
constructor(context) {
|
|
135
|
+
this.api = context.api;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Uploads an media file to Blip storage to be used later when sending messages
|
|
139
|
+
* @param content A Blob containing a image, PDF or video
|
|
140
|
+
* @returns A public URL
|
|
141
|
+
*/
|
|
142
|
+
async uploadMedia(content) {
|
|
143
|
+
try {
|
|
144
|
+
const response = await this.api.post('/commands', {
|
|
145
|
+
id: crypto.randomUUID(),
|
|
146
|
+
to: 'postmaster@media.msging.net',
|
|
147
|
+
method: 'get',
|
|
148
|
+
uri: '/upload-media-uri',
|
|
149
|
+
});
|
|
150
|
+
validateResponse(response);
|
|
151
|
+
const uploadResponse = await axios.post(response.data.resource, content, {
|
|
152
|
+
headers: { 'Content-Type': 'application/octet-stream' },
|
|
153
|
+
});
|
|
154
|
+
return uploadResponse.data.mediaUri;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
throw handleError(error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generates a new public URI to access blip chat media. Blip medias have expiration dates so you need to generate new ones to access the data.
|
|
162
|
+
* @param expiredMediaUri Blip media expired URI
|
|
163
|
+
* @returns A new public URI
|
|
164
|
+
*/
|
|
165
|
+
async refreshMediaUri(expiredMediaUri) {
|
|
166
|
+
try {
|
|
167
|
+
const response = await this.api.post('/commands', {
|
|
168
|
+
id: crypto.randomUUID(),
|
|
169
|
+
to: 'postmaster@media.msging.net',
|
|
170
|
+
method: 'set',
|
|
171
|
+
type: 'text/plain',
|
|
172
|
+
uri: '/refresh-media-uri',
|
|
173
|
+
resource: expiredMediaUri,
|
|
174
|
+
});
|
|
175
|
+
validateResponse(response);
|
|
176
|
+
return response.data.resource;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
throw handleError(error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
class BlipAttendance {
|
|
185
|
+
api;
|
|
186
|
+
constructor(context) {
|
|
187
|
+
this.api = context.api;
|
|
188
|
+
}
|
|
189
|
+
async getAttendanceHourContainer({ attendanceContainerId }) {
|
|
190
|
+
try {
|
|
191
|
+
const body = {
|
|
192
|
+
id: crypto.randomUUID(),
|
|
193
|
+
to: 'postmaster@desk.msging.net',
|
|
194
|
+
method: 'get',
|
|
195
|
+
uri: `/attendance-hour-container/${attendanceContainerId}`,
|
|
196
|
+
};
|
|
197
|
+
const response = await this.api.post('/commands', body);
|
|
198
|
+
validateResponse(response);
|
|
199
|
+
return response.data.resource;
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
throw handleError(error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
class BlipContact {
|
|
208
|
+
api;
|
|
209
|
+
constructor(context) {
|
|
210
|
+
this.api = context.api;
|
|
211
|
+
}
|
|
212
|
+
async update({ identity, contactData }) {
|
|
213
|
+
try {
|
|
214
|
+
const response = await this.api.post('/commands', {
|
|
215
|
+
id: crypto.randomUUID(),
|
|
216
|
+
to: 'postmaster@msging.net',
|
|
217
|
+
method: 'merge',
|
|
218
|
+
uri: '/contacts',
|
|
219
|
+
type: 'application/vnd.lime.contact+json',
|
|
220
|
+
resource: {
|
|
221
|
+
identity,
|
|
222
|
+
...contactData,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
validateResponse(response);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
handleError(error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async get({ identity }) {
|
|
232
|
+
try {
|
|
233
|
+
const response = await this.api.post('/commands', {
|
|
234
|
+
id: crypto.randomUUID(),
|
|
235
|
+
to: 'postmaster@crm.msging.net',
|
|
236
|
+
method: 'get',
|
|
237
|
+
uri: `/contacts/${identity}`,
|
|
238
|
+
});
|
|
239
|
+
validateResponse(response);
|
|
240
|
+
return response.data.resource;
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
throw handleError(error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
class BlipContext {
|
|
249
|
+
api;
|
|
250
|
+
constructor(context) {
|
|
251
|
+
this.api = context.api;
|
|
252
|
+
}
|
|
253
|
+
async getContextVariable({ identity, variableName }) {
|
|
254
|
+
try {
|
|
255
|
+
const response = await this.api.post('/commands', {
|
|
256
|
+
id: crypto.randomUUID(),
|
|
257
|
+
to: 'postmaster@msging.net',
|
|
258
|
+
method: 'get',
|
|
259
|
+
uri: `/contexts/${identity}/${variableName}`,
|
|
260
|
+
});
|
|
261
|
+
validateResponse(response);
|
|
262
|
+
return response.data.resource;
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
throw handleError(error);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async getAvailableContextVariables({ identity }) {
|
|
269
|
+
try {
|
|
270
|
+
const response = await this.api.post('/commands', {
|
|
271
|
+
id: crypto.randomUUID(),
|
|
272
|
+
to: 'postmaster@msging.net',
|
|
273
|
+
method: 'get',
|
|
274
|
+
uri: `/contexts/${identity}`,
|
|
275
|
+
});
|
|
276
|
+
validateResponse(response);
|
|
277
|
+
return response.data.resource;
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
throw handleError(error);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async setContextVariable({ value, variableName, identity, }) {
|
|
284
|
+
try {
|
|
285
|
+
const resourceType = typeof value === 'object' ? 'application/vnd.lime.contact+json' : 'text/plain';
|
|
286
|
+
const response = await this.api.post('/commands', {
|
|
287
|
+
id: crypto.randomUUID(),
|
|
288
|
+
method: 'set',
|
|
289
|
+
uri: `/contexts/${identity}/${variableName}`,
|
|
290
|
+
type: resourceType,
|
|
291
|
+
resource: value,
|
|
292
|
+
});
|
|
293
|
+
validateResponse(response);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
handleError(error);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function formatTemplateParams(params) {
|
|
302
|
+
return params.reduce((prev, current, index) => {
|
|
303
|
+
prev[index + 1] = current;
|
|
304
|
+
return prev;
|
|
305
|
+
}, {});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
class BlipDispatch {
|
|
309
|
+
api;
|
|
310
|
+
constructor(context) {
|
|
311
|
+
this.api = context.api;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
|
|
315
|
+
*/
|
|
316
|
+
async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params = [], }) {
|
|
317
|
+
const body = {
|
|
318
|
+
id: crypto.randomUUID(),
|
|
319
|
+
to: 'postmaster@activecampaign.msging.net',
|
|
320
|
+
method: 'set',
|
|
321
|
+
uri: '/campaign/full',
|
|
322
|
+
type: 'application/vnd.iris.activecampaign.full-campaign+json',
|
|
323
|
+
resource: {
|
|
324
|
+
campaign: {
|
|
325
|
+
name: campaignName,
|
|
326
|
+
campaignType: 'Individual',
|
|
327
|
+
masterState,
|
|
328
|
+
flowId,
|
|
329
|
+
stateId,
|
|
330
|
+
channelType,
|
|
331
|
+
},
|
|
332
|
+
audience: {
|
|
333
|
+
recipient: `+${phone}`,
|
|
334
|
+
},
|
|
335
|
+
message: {
|
|
336
|
+
messageTemplate: templateName,
|
|
337
|
+
channelType,
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
if (params.length > 0) {
|
|
342
|
+
body.resource.audience.messageParams = formatTemplateParams(params);
|
|
343
|
+
body.resource.message.messageParams = params.map((_param, index) => String(index + 1));
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const response = await this.api.post('/commands', body);
|
|
347
|
+
validateResponse(response);
|
|
348
|
+
return response.data.resource;
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
throw handleError(error);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async getCampaignNotificationStatus({ campaignNotificationId }) {
|
|
355
|
+
try {
|
|
356
|
+
const response = await this.api.post('/commands', {
|
|
357
|
+
id: crypto.randomUUID(),
|
|
358
|
+
to: 'postmaster@msging.net',
|
|
359
|
+
method: 'get',
|
|
360
|
+
uri: `/notifications?id=${campaignNotificationId}`,
|
|
361
|
+
});
|
|
362
|
+
validateResponse(response);
|
|
363
|
+
return response.data.resource.items;
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
throw handleError(error);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Sends a template-based message to an active user. For sending messages to clients who have never interacted or are inactive, use `sendTemplate` instead.
|
|
371
|
+
*/
|
|
372
|
+
async sendTemplateMessage({ identity, template, metadata, }) {
|
|
373
|
+
try {
|
|
374
|
+
const response = await this.api.post('/messages', {
|
|
375
|
+
id: crypto.randomUUID(),
|
|
376
|
+
to: identity,
|
|
377
|
+
type: 'application/json',
|
|
378
|
+
content: {
|
|
379
|
+
type: 'template',
|
|
380
|
+
template,
|
|
381
|
+
},
|
|
382
|
+
metadata,
|
|
383
|
+
});
|
|
384
|
+
validateResponse(response);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
handleError(error);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Sends a simple text message to an active user. For sending messages to clients who have never interacted or are inactive, use `sendTemplate` instead.
|
|
392
|
+
*/
|
|
393
|
+
async sendSimpleMessage({ identity, content, metadata }) {
|
|
394
|
+
try {
|
|
395
|
+
const response = await this.api.post('/messages', {
|
|
396
|
+
id: crypto.randomUUID(),
|
|
397
|
+
to: identity,
|
|
398
|
+
type: 'text/plain',
|
|
399
|
+
content,
|
|
400
|
+
metadata,
|
|
401
|
+
});
|
|
402
|
+
validateResponse(response);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
handleError(error);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Sends a text message to an active user with a midia. For sending messages to clients who have never interacted or are inactive, use `sendTemplate` instead.
|
|
410
|
+
*/
|
|
411
|
+
async sendMediaMessage({ identity, text, metadata, uri, type, title, aspectRatio = '1:1', size, previewUri, }) {
|
|
412
|
+
try {
|
|
413
|
+
const response = await this.api.post('/messages', {
|
|
414
|
+
id: crypto.randomUUID(),
|
|
415
|
+
to: identity,
|
|
416
|
+
type: 'application/vnd.lime.media-link+json',
|
|
417
|
+
content: {
|
|
418
|
+
text,
|
|
419
|
+
uri,
|
|
420
|
+
type,
|
|
421
|
+
title,
|
|
422
|
+
aspectRatio,
|
|
423
|
+
size,
|
|
424
|
+
previewUri,
|
|
425
|
+
},
|
|
426
|
+
metadata,
|
|
427
|
+
});
|
|
428
|
+
validateResponse(response);
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
handleError(error);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async sendMessageWithButtons({ identity, message, buttons, metadata, }) {
|
|
435
|
+
try {
|
|
436
|
+
const response = await this.api.post('/messages', {
|
|
437
|
+
id: crypto.randomUUID(),
|
|
438
|
+
to: identity,
|
|
439
|
+
type: 'application/vnd.lime.select+json',
|
|
440
|
+
content: {
|
|
441
|
+
scope: buttons.length <= 3 ? 'immediate' : null,
|
|
442
|
+
text: message,
|
|
443
|
+
options: buttons.map((button, index) => ({ order: index + 1, text: button })),
|
|
444
|
+
},
|
|
445
|
+
metadata,
|
|
446
|
+
});
|
|
447
|
+
validateResponse(response);
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
handleError(error);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
class BlipEvent {
|
|
456
|
+
api;
|
|
457
|
+
constructor(context) {
|
|
458
|
+
this.api = context.api;
|
|
459
|
+
}
|
|
460
|
+
async createTrackEvent({ category, action, identity }) {
|
|
461
|
+
try {
|
|
462
|
+
const body = {
|
|
463
|
+
id: crypto.randomUUID(),
|
|
464
|
+
to: 'postmaster@analytics.msging.net',
|
|
465
|
+
method: 'set',
|
|
466
|
+
type: 'application/vnd.iris.eventTrack+json',
|
|
467
|
+
uri: '/event-track',
|
|
468
|
+
resource: {
|
|
469
|
+
category,
|
|
470
|
+
action,
|
|
471
|
+
contact: identity ? { identity } : undefined,
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
const response = await this.api.post('/commands', body);
|
|
475
|
+
validateResponse(response);
|
|
476
|
+
}
|
|
477
|
+
catch (error) {
|
|
478
|
+
throw handleError(error);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
class BlipInteraction {
|
|
484
|
+
blipContext;
|
|
485
|
+
constructor(context) {
|
|
486
|
+
this.blipContext = context.blipContext;
|
|
487
|
+
}
|
|
488
|
+
async moveUser({ identity, botIdentity, botFlowId, botStateId, }) {
|
|
489
|
+
await Promise.all([
|
|
490
|
+
this.blipContext.setContextVariable({ identity, variableName: 'master-state', value: botIdentity }),
|
|
491
|
+
this.blipContext.setContextVariable({ identity, variableName: `stateid@${botFlowId}`, value: botStateId }),
|
|
492
|
+
]);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
class BlipTicket {
|
|
497
|
+
api;
|
|
498
|
+
constructor(context) {
|
|
499
|
+
this.api = context.api;
|
|
500
|
+
}
|
|
501
|
+
async search({ filter, skip, take }) {
|
|
502
|
+
try {
|
|
503
|
+
const params = {
|
|
504
|
+
$filter: filter,
|
|
505
|
+
$skip: skip,
|
|
506
|
+
$take: take,
|
|
507
|
+
};
|
|
508
|
+
const body = {
|
|
509
|
+
id: crypto.randomUUID(),
|
|
510
|
+
to: 'postmaster@desk.msging.net',
|
|
511
|
+
method: 'get',
|
|
512
|
+
uri: `/tickets?${encodeBlipParams(params)}`,
|
|
513
|
+
};
|
|
514
|
+
const response = await this.api.post('/commands', body);
|
|
515
|
+
validateResponse(response);
|
|
516
|
+
return response.data.resource.items;
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
throw handleError(error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
class BlipWhatsapp {
|
|
525
|
+
api;
|
|
526
|
+
constructor(context) {
|
|
527
|
+
this.api = context.api;
|
|
528
|
+
}
|
|
529
|
+
async getTemplates() {
|
|
530
|
+
try {
|
|
531
|
+
const response = await this.api.post('/commands', {
|
|
532
|
+
id: crypto.randomUUID(),
|
|
533
|
+
to: 'postmaster@wa.gw.msging.net',
|
|
534
|
+
method: 'get',
|
|
535
|
+
uri: '/message-templates',
|
|
536
|
+
});
|
|
537
|
+
validateResponse(response);
|
|
538
|
+
return response.data.resource.data;
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
throw handleError(error);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
async getIdentity(phone) {
|
|
545
|
+
try {
|
|
546
|
+
const response = await this.api.post('/commands', {
|
|
547
|
+
id: crypto.randomUUID(),
|
|
548
|
+
to: 'postmaster@wa.gw.msging.net',
|
|
549
|
+
method: 'get',
|
|
550
|
+
uri: `lime://wa.gw.msging.net/accounts/+${phone}`,
|
|
551
|
+
});
|
|
552
|
+
validateResponse(response);
|
|
553
|
+
return response.data.resource.identity;
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
throw handleError(error);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
562
|
+
__proto__: null,
|
|
563
|
+
BlipAttendance: BlipAttendance,
|
|
564
|
+
BlipBucket: BlipBucket,
|
|
565
|
+
BlipContact: BlipContact,
|
|
566
|
+
BlipContext: BlipContext,
|
|
567
|
+
BlipDispatch: BlipDispatch,
|
|
568
|
+
BlipEvent: BlipEvent,
|
|
569
|
+
BlipInteraction: BlipInteraction,
|
|
570
|
+
BlipMedia: BlipMedia,
|
|
571
|
+
BlipTicket: BlipTicket,
|
|
572
|
+
BlipWhatsapp: BlipWhatsapp
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
function validateInstance(params) {
|
|
576
|
+
if (!params.contract) {
|
|
577
|
+
throw new BlipError('A contract must be specified.');
|
|
578
|
+
}
|
|
579
|
+
if (!params.authToken) {
|
|
580
|
+
throw new BlipError('An authToken must be provided.');
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
class Blip {
|
|
585
|
+
api;
|
|
586
|
+
bucket;
|
|
587
|
+
media;
|
|
588
|
+
attendance;
|
|
589
|
+
contact;
|
|
590
|
+
context;
|
|
591
|
+
dispatch;
|
|
592
|
+
event;
|
|
593
|
+
interaction;
|
|
594
|
+
ticket;
|
|
595
|
+
whatsapp;
|
|
596
|
+
constructor(params) {
|
|
597
|
+
validateInstance(params);
|
|
598
|
+
this.api = axios.create({
|
|
599
|
+
baseURL: `https://${params.contract}.http.msging.net`,
|
|
600
|
+
headers: {
|
|
601
|
+
Authorization: `Key ${params.authToken.replace('Key ', '')}`,
|
|
602
|
+
},
|
|
603
|
+
timeout: 30000,
|
|
604
|
+
});
|
|
605
|
+
this.bucket = new BlipBucket({ api: this.api });
|
|
606
|
+
this.media = new BlipMedia({ api: this.api });
|
|
607
|
+
this.attendance = new BlipAttendance({ api: this.api });
|
|
608
|
+
this.context = new BlipContext({ api: this.api });
|
|
609
|
+
this.contact = new BlipContact({ api: this.api });
|
|
610
|
+
this.dispatch = new BlipDispatch({ api: this.api });
|
|
611
|
+
this.event = new BlipEvent({ api: this.api });
|
|
612
|
+
this.interaction = new BlipInteraction({ blipContext: this.context });
|
|
613
|
+
this.ticket = new BlipTicket({ api: this.api });
|
|
614
|
+
this.whatsapp = new BlipWhatsapp({ api: this.api });
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
exports.Blip = Blip;
|
|
619
|
+
exports.Modules = index;
|