@subiz/widget-v4 4.1.142 → 4.1.144

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.
Files changed (62) hide show
  1. package/README.md +5 -1
  2. package/compiled_src/bot.js +1 -2
  3. package/compiled_src/call/call.js +1 -2
  4. package/compiled_src/chatbox/Event.js +1 -2
  5. package/compiled_src/chatbox/Widget.js +3 -4
  6. package/compiled_src/chatbox/main.js +1 -2
  7. package/compiled_src/contact/contact.js +1 -2
  8. package/compiled_src/form/FormPage.js +1 -2
  9. package/compiled_src/form/index.js +1 -2
  10. package/compiled_src/form.js +1 -2
  11. package/compiled_src/notif/notif.js +1 -2
  12. package/compiled_src/order/icon.js +1 -2
  13. package/compiled_src/order/index.js +1 -2
  14. package/compiled_src/order/order.js +1 -2
  15. package/compiled_src/plugin.js +1 -2
  16. package/compiled_src/popup/popup.js +1 -2
  17. package/compiled_src/store/store.js +1255 -0
  18. package/compiled_src/util/campaign.js +88 -0
  19. package/compiled_src/util/common.js +1294 -0
  20. package/compiled_src/util/common.test.js +496 -0
  21. package/compiled_src/util/extractor.test.js +299 -0
  22. package/compiled_src/util/gate.js +38 -0
  23. package/compiled_src/util/gate.test.js +18 -0
  24. package/compiled_src/util/index.js +19 -0
  25. package/compiled_src/util/mutex.js +31 -0
  26. package/compiled_src/util/op.js +55 -0
  27. package/compiled_src/util/pubsub.js +29 -0
  28. package/compiled_src/util/pubsub.test.js +35 -0
  29. package/dist/196d3465f26.278.js +1 -0
  30. package/dist/196d3465f26.339.js +1 -0
  31. package/dist/196d3465f26.app.js +1 -0
  32. package/dist/196d3465f26.form.html +1 -0
  33. package/dist/196d3465f26.form.js +1 -0
  34. package/dist/{1967c022bc1.index.html → 196d3465f26.index.html} +15 -1
  35. package/dist/{1967c022bc1.library.html → 196d3465f26.library.html} +15 -1
  36. package/dist/196d3465f26.library.js +1 -0
  37. package/dist/{1967c022bc1.preview.html → 196d3465f26.preview.html} +1 -1
  38. package/dist/196d3465f26.preview.js +1 -0
  39. package/dist/196d3465f26.webview.js +1 -0
  40. package/dist/278.js +81 -70
  41. package/dist/HASH +1 -1
  42. package/dist/assets/img/stars_v2.79cf728.png +0 -0
  43. package/dist/screenshoot.js +317 -118
  44. package/index.html +14 -0
  45. package/package.json +10 -10
  46. package/src/chatbox/Widget.js +2 -2
  47. package/src/store/store.js +1 -1
  48. package/dist/1967c022bc1.278.js +0 -1
  49. package/dist/1967c022bc1.app.js +0 -1
  50. package/dist/1967c022bc1.form.html +0 -1
  51. package/dist/1967c022bc1.form.js +0 -1
  52. package/dist/1967c022bc1.library.js +0 -1
  53. package/dist/1967c022bc1.preview.js +0 -1
  54. package/dist/1967c022bc1.webview.js +0 -1
  55. /package/dist/{1967c022bc1.127.js → 196d3465f26.127.js} +0 -0
  56. /package/dist/{1967c022bc1.132.js → 196d3465f26.132.js} +0 -0
  57. /package/dist/{1967c022bc1.185.js → 196d3465f26.185.js} +0 -0
  58. /package/dist/{1967c022bc1.27.js → 196d3465f26.27.js} +0 -0
  59. /package/dist/{1967c022bc1.459.js → 196d3465f26.459.js} +0 -0
  60. /package/dist/{1967c022bc1.490.js → 196d3465f26.490.js} +0 -0
  61. /package/dist/{1967c022bc1.74.js → 196d3465f26.74.js} +0 -0
  62. /package/dist/{1967c022bc1.997.js → 196d3465f26.997.js} +0 -0
@@ -0,0 +1,496 @@
1
+ "use strict";
2
+
3
+ const test = require('tape');
4
+ const util = require('./common.js');
5
+ test('util.getNotiDescription', t => {
6
+ var tcs = [{
7
+ desc: 'not a message sent',
8
+ event: {
9
+ type: 'conversation_updated'
10
+ },
11
+ text: ''
12
+ }, {
13
+ desc: 'an email',
14
+ event: {
15
+ type: 'message_sent',
16
+ data: {
17
+ message: {
18
+ fields: [{
19
+ key: 'from',
20
+ value: '"thanh"'
21
+ }, {
22
+ key: 'to',
23
+ value: '"van"'
24
+ }]
25
+ }
26
+ }
27
+ },
28
+ text: 'sent an email'
29
+ }, {
30
+ desc: 'empty msg',
31
+ event: {},
32
+ text: ''
33
+ }, {
34
+ desc: 'markdown',
35
+ event: {
36
+ type: 'message_sent',
37
+ data: {
38
+ message: {
39
+ format: 'markdown',
40
+ text: 'xin chao'
41
+ }
42
+ }
43
+ },
44
+ text: 'sent a message'
45
+ }, {
46
+ desc: 'html',
47
+ event: {
48
+ type: 'message_sent',
49
+ data: {
50
+ message: {
51
+ format: 'html',
52
+ text: '<b>xin chao</b>'
53
+ }
54
+ }
55
+ },
56
+ text: 'sent a message'
57
+ }, {
58
+ desc: 'multiple attachemnts',
59
+ event: {
60
+ type: 'message_sent',
61
+ data: {
62
+ message: {
63
+ attachments: [{}, {}, {}]
64
+ }
65
+ }
66
+ },
67
+ text: 'sent a message with 3 attachments'
68
+ }, {
69
+ desc: 'text with attachment',
70
+ event: {
71
+ type: 'message_sent',
72
+ data: {
73
+ message: {
74
+ type: 'text',
75
+ text: 'xin chao',
76
+ attachments: [{}]
77
+ }
78
+ }
79
+ },
80
+ text: 'sent a message with 1 attachments'
81
+ }, {
82
+ desc: '1 attachment no type',
83
+ event: {
84
+ type: 'message_sent',
85
+ data: {
86
+ message: {
87
+ attachments: [{}]
88
+ }
89
+ }
90
+ },
91
+ text: 'sent an attachment'
92
+ }, {
93
+ desc: 'audio ',
94
+ event: {
95
+ type: 'message_sent',
96
+ data: {
97
+ message: {
98
+ attachments: [{
99
+ mimetype: 'audio/mp3'
100
+ }]
101
+ }
102
+ }
103
+ },
104
+ text: 'sent an audio'
105
+ }, {
106
+ desc: 'video',
107
+ event: {
108
+ type: 'message_sent',
109
+ data: {
110
+ message: {
111
+ attachments: [{
112
+ mimetype: 'video/ogg'
113
+ }]
114
+ }
115
+ }
116
+ },
117
+ text: 'sent a video'
118
+ }, {
119
+ desc: 'image',
120
+ event: {
121
+ type: 'message_sent',
122
+ data: {
123
+ message: {
124
+ attachments: [{
125
+ mimetype: 'image/jpeg'
126
+ }]
127
+ }
128
+ }
129
+ },
130
+ text: 'sent a picture'
131
+ }];
132
+ tcs.map(tc => {
133
+ var out = util.getNotiDescription(tc.event);
134
+ t.equal(out, tc.text);
135
+ });
136
+ t.end();
137
+ });
138
+ test('util.randomString', t => {
139
+ t.equal(10, util.randomString(10).length);
140
+ t.equal(11, util.randomString(11).length);
141
+ t.equal(12, util.randomString(12).length);
142
+ t.end();
143
+ });
144
+ test('convert message event first msg send', t => {
145
+ var events = [{
146
+ by: {
147
+ id: 1
148
+ },
149
+ type: 'message_sent',
150
+ created: 1100
151
+ }, {
152
+ by: {
153
+ id: 1
154
+ },
155
+ type: 'message_sent',
156
+ created: 1200
157
+ }, {
158
+ by: {
159
+ id: 1
160
+ },
161
+ type: 'message_sent',
162
+ created: 1300
163
+ }];
164
+ var expect = [{
165
+ by: {
166
+ id: 1
167
+ },
168
+ type: 'message_sent',
169
+ created: 1100,
170
+ mode: 'lead',
171
+ show_time: true
172
+ }, {
173
+ by: {
174
+ id: 1
175
+ },
176
+ type: 'message_sent',
177
+ created: 1200,
178
+ mode: 'follow',
179
+ show_time: false
180
+ }, {
181
+ by: {
182
+ id: 1
183
+ },
184
+ type: 'message_sent',
185
+ created: 1300,
186
+ mode: 'follow',
187
+ show_time: false
188
+ }];
189
+ util.convertMessageEvent(events, 0);
190
+ util.convertMessageEvent(events, 1);
191
+ util.convertMessageEvent(events, 2);
192
+ t.equal(JSON.stringify(events), JSON.stringify(expect));
193
+ t.end();
194
+ });
195
+ test('convert message event message tag', t => {
196
+ var events = [{
197
+ type: 'conversation_state_updated'
198
+ }, {
199
+ type: 'conversation_tagged'
200
+ }, {
201
+ type: 'conversation_tagged'
202
+ }, {
203
+ type: 'conversation_tagged'
204
+ }, {
205
+ type: 'conversation_state_updated'
206
+ }];
207
+ var expect = [{
208
+ type: 'conversation_state_updated'
209
+ }, {
210
+ type: 'conversation_tagged',
211
+ mode: 'hide'
212
+ }, {
213
+ type: 'conversation_tagged',
214
+ mode: 'hide'
215
+ }, {
216
+ type: 'conversation_tagged',
217
+ mode: 'combine'
218
+ }, {
219
+ type: 'conversation_state_updated'
220
+ }];
221
+ events.map((_, i) => util.convertMessageEvent(events, i));
222
+ t.equal(JSON.stringify(events), JSON.stringify(expect));
223
+ var events = [{
224
+ type: 'conversation_tagged'
225
+ }, {
226
+ type: 'conversation_tagged'
227
+ }, {
228
+ type: 'conversation_tagged'
229
+ }];
230
+ var expect = [{
231
+ type: 'conversation_tagged',
232
+ mode: 'hide'
233
+ }, {
234
+ type: 'conversation_tagged',
235
+ mode: 'hide'
236
+ }, {
237
+ type: 'conversation_tagged',
238
+ mode: 'combine'
239
+ }];
240
+ events.map((_, i) => util.convertMessageEvent(events, i));
241
+ t.end();
242
+ });
243
+ test('convert message event message tag, msg_sent mixup', t => {
244
+ var events = [{
245
+ type: 'conversation_state_updated'
246
+ }, {
247
+ type: 'conversation_tagged'
248
+ }, {
249
+ by: {
250
+ id: 1
251
+ },
252
+ type: 'message_sent'
253
+ }, {
254
+ by: {
255
+ id: 2
256
+ },
257
+ type: 'message_sent'
258
+ }, {
259
+ type: 'conversation_tagged'
260
+ }, {
261
+ type: 'conversation_tagged'
262
+ }, {
263
+ type: 'conversation_state_updated'
264
+ }];
265
+ var expect = [{
266
+ type: 'conversation_state_updated'
267
+ }, {
268
+ type: 'conversation_tagged',
269
+ mode: 'combine'
270
+ }, {
271
+ by: {
272
+ id: 1
273
+ },
274
+ type: 'message_sent',
275
+ mode: 'lead',
276
+ show_time: false
277
+ }, {
278
+ by: {
279
+ id: 2
280
+ },
281
+ type: 'message_sent',
282
+ mode: 'lead',
283
+ show_time: false
284
+ }, {
285
+ type: 'conversation_tagged',
286
+ mode: 'hide'
287
+ }, {
288
+ type: 'conversation_tagged',
289
+ mode: 'combine'
290
+ }, {
291
+ type: 'conversation_state_updated'
292
+ }];
293
+ events.map((_, i) => util.convertMessageEvent(events, i));
294
+ t.equal(JSON.stringify(events), JSON.stringify(expect));
295
+ t.end();
296
+ });
297
+ test('test insert message', t => {
298
+ var events = [{
299
+ type: 'conversation_state_updated'
300
+ }, {
301
+ id: 1,
302
+ type: 'conversation_tagged'
303
+ }, {
304
+ by: {
305
+ id: 1
306
+ },
307
+ type: 'message_sent'
308
+ }, {
309
+ by: {
310
+ id: 2
311
+ },
312
+ type: 'message_sent'
313
+ }, {
314
+ type: 'conversation_tagged'
315
+ }, {
316
+ type: 'conversation_tagged'
317
+ }, {
318
+ type: 'conversation_state_updated'
319
+ }];
320
+ events.map((_, i) => util.convertMessageEvent(events, i));
321
+ events.splice(2, 0, {
322
+ id: 2,
323
+ type: 'conversation_tagged'
324
+ });
325
+ util.convertUpdatedOrDeletedMessageEvent(events, 2);
326
+ var expect = [{
327
+ type: 'conversation_state_updated'
328
+ }, {
329
+ id: 1,
330
+ type: 'conversation_tagged',
331
+ mode: 'hide'
332
+ }, {
333
+ id: 2,
334
+ type: 'conversation_tagged',
335
+ mode: 'combine'
336
+ }, {
337
+ by: {
338
+ id: 1
339
+ },
340
+ type: 'message_sent',
341
+ mode: 'lead',
342
+ show_time: false
343
+ }, {
344
+ by: {
345
+ id: 2
346
+ },
347
+ type: 'message_sent',
348
+ mode: 'lead',
349
+ show_time: false
350
+ }, {
351
+ type: 'conversation_tagged',
352
+ mode: 'hide'
353
+ }, {
354
+ type: 'conversation_tagged',
355
+ mode: 'combine'
356
+ }, {
357
+ type: 'conversation_state_updated'
358
+ }];
359
+ t.equal(JSON.stringify(events), JSON.stringify(expect));
360
+ t.end();
361
+ });
362
+ test('mapizeDeep a map', t => {
363
+ var topicM = {
364
+ '0': {
365
+ topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxnairroppcktrg',
366
+ read: false,
367
+ updated: 1570586074000
368
+ },
369
+ '1': {
370
+ topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxmkozwryrgjvag',
371
+ read: false,
372
+ updated: 1570551305000
373
+ },
374
+ '2': {
375
+ topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlvkqgspihkfzsnm',
376
+ read: false,
377
+ updated: 1570289320000
378
+ }
379
+ };
380
+ var out = util.mapizeDeep(topicM, 'topic');
381
+ topicM['0'].topic = 't3';
382
+ t.deepEqual(out, {
383
+ 'account.acqcsmrppbftadjzxnvo.conversation.csqlxnairroppcktrg': {
384
+ topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxnairroppcktrg',
385
+ read: false,
386
+ updated: 1570586074000
387
+ },
388
+ 'account.acqcsmrppbftadjzxnvo.conversation.csqlxmkozwryrgjvag': {
389
+ topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxmkozwryrgjvag',
390
+ read: false,
391
+ updated: 1570551305000
392
+ },
393
+ 'account.acqcsmrppbftadjzxnvo.conversation.csqlvkqgspihkfzsnm': {
394
+ topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlvkqgspihkfzsnm',
395
+ read: false,
396
+ updated: 1570289320000
397
+ }
398
+ });
399
+ t.end();
400
+ });
401
+ test('mapize a map', t => {
402
+ var topicM = {
403
+ '0': {
404
+ topic: 't1',
405
+ updated: 157
406
+ },
407
+ '1': {
408
+ topic: 't2',
409
+ updated: 158
410
+ }
411
+ };
412
+ var out = util.mapize(topicM, 'topic');
413
+ t.deepEqual(out, {
414
+ t1: {
415
+ topic: 't1',
416
+ updated: 157
417
+ },
418
+ t2: {
419
+ topic: 't2',
420
+ updated: 158
421
+ }
422
+ });
423
+ t.end();
424
+ });
425
+ test('mapize', t => {
426
+ var arr = [{
427
+ id: 0,
428
+ value: 0
429
+ }, {
430
+ id: 1,
431
+ value: 1
432
+ }, {
433
+ id: 2,
434
+ value: 2
435
+ }, {
436
+ id: 3,
437
+ value: 3
438
+ }, {
439
+ id: 4,
440
+ value: 4
441
+ }];
442
+ var m = util.mapize(arr, 'id');
443
+ for (var i = 0; i < arr.length; i++) {
444
+ t.equal(m[i], arr[i]);
445
+ }
446
+ t.end();
447
+ });
448
+ test('convo id from topic', t => {
449
+ t.equal('csqldpucwamyuaetjf', util.convoIdFromTopic('account.acqcsmrppbftadjzxnvo.conversation.csqldpucwamyuaetjf'));
450
+ t.end();
451
+ });
452
+ test('user of convo', t => {
453
+ var convo = {
454
+ id: 'csqlmhetrpccwprnms',
455
+ account_id: 'acqcsmrppbftadjzxnvo',
456
+ created: 1568970100964184000,
457
+ members: [{
458
+ type: 'bot',
459
+ id: 'agqhgvgtbwhsbolwtp',
460
+ name: 'Automation bot',
461
+ membership: 'active'
462
+ }, {
463
+ type: 'user',
464
+ id: 'usqlmfpdhxmajzggsjosw',
465
+ name: '',
466
+ membership: 'active'
467
+ }, {
468
+ type: 'agent',
469
+ id: 'agqcsmrppbfqstjwen',
470
+ name: 'Thành',
471
+ membership: 'active'
472
+ }, {
473
+ type: 'user',
474
+ id: 'usqlmfpdhxmajzgasdf',
475
+ name: '',
476
+ membership: 'active'
477
+ }, {
478
+ type: 'agent',
479
+ id: 'agqczwdrggvdnlbuom',
480
+ name: 'THanh',
481
+ membership: 'observer'
482
+ }],
483
+ ended: 1569004072969908700,
484
+ state: 'ended',
485
+ accepted: 1568970101938098700,
486
+ actived: 1568974069989570300,
487
+ response_sec: 0,
488
+ first_message: 'sdfg',
489
+ subject: 'sdfg'
490
+ };
491
+ var users = util.usersOfConvo(convo);
492
+ t.equal(users.length, 2);
493
+ t.equal(users[0], 'usqlmfpdhxmajzggsjosw');
494
+ t.equal(users[1], 'usqlmfpdhxmajzgasdf');
495
+ t.end();
496
+ });