-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZwermAPI.js
798 lines (737 loc) · 24.5 KB
/
ZwermAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
'use strict';
/** @type {AxiosStatic} */
const axios = require('axios').default;
const qs = require('qs');
/**
*
*/
class ZwermAPI {
/**
*
* @param {!string} apiUrl
* @param {?string} apiToken
*/
constructor(apiUrl, apiToken) {
/**
*
* @type {!string}
* @private
*/
this._apiUrl = apiUrl;
/**
*
* @type {?string}
* @private
*/
this._apiToken = apiToken;
}
// region getter constants
// region routes
/**
* @return {Zwerm.DISABLED_ROUTING}
* @static
*/
static get DISABLED_ROUTING() {
return '/dev/null';
}
/**
* @return {Zwerm.ROUTE_DELIMITER}
* @static
*/
static get ROUTE_DELIMITER() {
return '/';
}
// endregion
// region event constants
// region system events
// region connect events
/**
* @return {Zwerm.Events.UNKNOWN_MESSAGE}
* @static
*/
static get UNKNOWN_MESSAGE_EVENT() {
return 'zwerm.unknown';
}
/**
* @return {Zwerm.Events.ENGINE_ERROR}
* @static
*/
static get ENGINE_ERROR_EVENT() {
return 'zwerm.engines.error';
}
/**
* @return {Zwerm.Events.CHANNEL_ERROR}
* @static
*/
static get CHANNEL_ERROR_EVENT() {
return 'zwerm.channels.error';
}
// endregion
// region user events
/**
* @return {Zwerm.Events.NEW_USER}
* @static
*/
static get NEW_USER_EVENT() {
return 'zwerm.users.new';
}
/**
* @return {Zwerm.Events.UPDATE_USER_ROUTE}
* @static
*/
static get UPDATE_USER_ROUTE_EVENT() {
return 'zwerm.users.route.update';
}
// endregion
// region conversation events
/**
* @return {Zwerm.Events.NEW_CONVERSATION}
* @static
*
* @deprecated in favor of {@link NEW_CONVERSATION_EVENT}
*/
static get NEW_CONVESRATION_EVENT() {
return ZwermAPI.NEW_CONVERSATION_EVENT;
}
/**
* @return {Zwerm.Events.NEW_CONVERSATION}
* @static
*/
static get NEW_CONVERSATION_EVENT() {
return 'zwerm.conversations.new';
}
/**
* @return {Zwerm.Events.UPDATE_CONVERSATION_ROUTE}
* @static
*/
static get UPDATE_CONVERSATION_ROUTE_EVENT() {
return 'zwerm.conversations.route.update';
}
/**
* @return {Zwerm.Events.CONVERSATION_SENTIMENT_NEGATIVE}
* @static
*/
static get CONVERSATION_SENTIMENT_NEGATIVE_EVENT() {
return 'zwerm.conversations.sentiment.negative';
}
// endregion
// endregion
// region conversational events
// region welcome events
/**
* @return {Zwerm.Events.WELCOME}
* @static
*/
static get WELCOME_EVENT() {
return 'zwerm.welcome';
}
/**
* @return {Zwerm.Events.WELCOME_BACK}
* @static
*/
static get WELCOME_BACK_EVENT() {
return 'zwerm.welcome-back';
}
// endregion
// region timer events
/**
* @return {Zwerm.Events.TIMER_START}
* @static
*/
static get TIMER_START_EVENT() {
return 'zwerm.timer.start';
}
/**
* @return {Zwerm.Events.TIMER_CANCEL}
* @static
*/
static get TIMER_CANCEL_EVENT() {
return 'zwerm.timer.cancel';
}
// endregion
// endregion
// endregion
// endregion
// region getters & setters
// region apiUrl (get & set)
/**
*
* @return {!string}
*/
get apiUrl() {
return this._apiUrl;
}
/**
*
* @param {!string} apiUrl
*/
set apiUrl(apiUrl) {
this._apiUrl = apiUrl;
}
// endregion
// region apiToken (get & set)
/**
*
* @return {?string}
*/
get apiToken() {
return this._apiToken;
}
/**
*
* @param {?string} apiToken
*/
set apiToken(apiToken) {
this._apiToken = apiToken;
}
// endregion
/**
*
* @return {AxiosInstance}
* @private
*/
get _zwermRequest() {
return axios.create({
baseURL: this._apiUrl,
headers: {
Authorization: `Bearer ${this._apiToken}`,
'X-Clacks-Overhead': 'GNU Terry Pratchett'
}
});
}
// endregion
// region configuration
/**
*
* @param {string} apiUrl
* @param {string} apiToken
*
* @return {ZwermAPI}
*/
use({ apiUrl = this.apiUrl, apiToken = this.apiToken } = {}) {
this.apiUrl = apiUrl;
this.apiToken = apiToken;
return this;
}
/**
* Sets the api url in a chain-able manner
*
* @param {string} apiUrl
*
* @return {ZwermAPI}
*/
useUrl(apiUrl) {
this.apiUrl = apiUrl;
return this;
}
/**
* Sets the api token in a chain-able manner
*
* @param {string} apiToken
*
* @return {ZwermAPI}
*/
useToken(apiToken) {
this.apiToken = apiToken;
return this;
}
//endregion
// region bots
// region bot users
/**
*
* @param {string} teamSlug
* @param {string} botId
* @param {?number} [limit]
* @param {Zwerm.API.SortOrder} [sort='desc']
*
* @return {Promise<Zwerm.API.DynamoResult<Zwerm.Database.EvaluatedUserKeys, Zwerm.Database.UserEntry>>}
*/
listBotUsers(teamSlug, botId, { limit, sort = 'desc' } = {}) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users`, { params: { limit, sort } })
.then(response => response.data);
}
/**
* Filter users of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {Zwerm.API.DynamoFilter<Zwerm.Database.UserEntry>} filterObj
* @param {?number} [limit]
* @param {Zwerm.API.SortOrder} [sort='desc']
*
* @return {Promise<Zwerm.API.DynamoResult<Zwerm.Database.EvaluatedUserKeys, Zwerm.Database.UserEntry>>}
*/
filterBotUsers(teamSlug, botId, filterObj, { limit, sort = 'desc' } = {}) {
return this._zwermRequest.post(`bots/${teamSlug}/${botId}/users/filter`, filterObj, { params: { limit, sort } })
.then(response => response.data);
}
/**
* Get a single user of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
*
* @return {Promise<Zwerm.Database.UserEntry>}
*/
getBotUser(teamSlug, botId, userId) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}`)
.then(response => response.data['Item']);
}
/**
* Get the markup for the a user of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
*
* @return {Promise<Zwerm.Database.UserMarkup>}
*/
getBotUserMarkup(teamSlug, botId, userId) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}/markup`)
.then(response => response.data);
}
/**
* Update the markup for the a user of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
*
* @return {Promise<Zwerm.Database.UserMarkup>}
*/
updateBotUserMarkup(teamSlug, botId, userId) {
return this._zwermRequest.put(`bots/${teamSlug}/${botId}/users/${userId}/markup`)
.then(response => response.data);
}
/**
* Get the markup for the a user of a bot. Force update if no data is returned.
* We recommend this method as the most efficient way to retrieve user markup data unless the most up to data is needed.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
*
* @return {Promise<Zwerm.Database.UserMarkup>}
*/
getOrUpdateBotUserMarkup(teamSlug, botId, userId) {
return this.getBotUserMarkup(teamSlug, botId, userId)
.then(markup => {
if (!markup || Object.keys(markup).length === 0) {
return this.updateBotUserMarkup(teamSlug, botId, userId);
}
return markup;
});
}
// endregion
// region bot conversations
/**
* Filters conversations of a specific user of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {Zwerm.API.DynamoFilter<Zwerm.Database.ConversationEntry>} filterObj
* @param {?number} [limit]
* @param {Zwerm.API.SortOrder} [sort='desc']
*
* @return {Promise<Zwerm.API.DynamoResult<null, Zwerm.Database.ConversationEntry>>}
*/
filterBotUserConversations(teamSlug, botId, userId, filterObj, { limit, sort = 'desc' } = {}) {
return this._zwermRequest.post(`bots/${teamSlug}/${botId}/users/${userId}/conversations/filter`, filterObj, { params: { limit, sort } })
.then(response => response.data);
}
/**
* Lists conversations of a specific bot user.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {?number} [limit]
* @param {Zwerm.API.SortOrder} [sort='desc']
*
* @return {Promise<Zwerm.API.DynamoResult<null, Zwerm.Database.TransactionEntry>>}
*/
listBotUserConversations(teamSlug, botId, userId, { limit, sort = 'desc' } = {}) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}/conversations`, { params: { limit, sort } })
.then(response => response.data);
}
/**
* Get a single conversation of a user of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {string} conversationId
*
* @return {Promise<Zwerm.Database.ConversationEntry>}
*/
getBotUserConversation(teamSlug, botId, userId, conversationId) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}/conversations/${conversationId}`)
.then(response => response.data['Item']);
}
// endregion
// region bot transactions
/**
* Filters transactions of a specific user of a bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {Zwerm.API.DynamoFilter<Zwerm.Database.TransactionEntry>} filterObj
* @param {?number} [limit]
* @param {Zwerm.API.SortOrder} [sort='desc']
*
* @return {Promise<Zwerm.API.DynamoResult<Zwerm.Database.EvaluatedTransactionKeys, Zwerm.Database.TransactionEntry>>}
*/
filterBotUserTransactions(teamSlug, botId, userId, filterObj, { limit, sort = 'desc' } = {}) {
return this._zwermRequest.post(`bots/${teamSlug}/${botId}/users/${userId}/transactions/filter`, filterObj, { params: { limit, sort } })
.then(response => response.data);
}
/**
* Lists transactions of a specific bot user.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {?number} [limit]
* @param {Zwerm.API.SortOrder} [sort='desc']
*
* @return {Promise<Zwerm.API.DynamoResult<Zwerm.Database.EvaluatedTransactionKeys, Zwerm.Database.TransactionEntry>>}
*/
listBotUserTransactions(teamSlug, botId, userId, { limit, sort = 'desc' } = {}) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}/transactions`, { params: { limit, sort } })
.then(response => response.data);
}
// endregion
// region list bots
/**
* List your bots.
*
* @return {Promise<{ bots: Array<Zwerm.API.BotInfo> }>}
*/
listUserBots() {
return this._zwermRequest.get('/user/bots')
.then(response => response.data);
}
/**
* List your bots.
*
* @param {string} teamSlug
*
* @return {Promise<Zwerm.API.Team>}
*/
listTeamBots(teamSlug) {
return this._zwermRequest.get(`/teams/${teamSlug}/bots`)
.then(response => response.data);
}
// todo: createBot(botDetails)
/**
* @param {string} teamSlug
* @param {string} botId
*
* @return {Promise<Zwerm.API.BotInfo>}
*/
getSingleBot(teamSlug, botId) {
return this._zwermRequest.get(`/bots/${teamSlug}/${botId}`)
.then(response => response.data);
}
/**
*
* @return {Promise<{ bots: Array<Zwerm.API.BotInfo>, config: BotsSchema.Bots }>}
*/
listAllBots() {
return this._zwermRequest.get('/bots')
.then(response => response.data);
}
// endregion
// endregion
// region bot routing
// region user routing
/**
* Gets the current route of the given user for the given bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
*
* @return {Promise<string>}
*/
getCurrentRouteForUser(teamSlug, botId, userId) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}/route`)
.then(response => response.data['route']);
}
/**
* Puts the given route as the current route of the given user for the given bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {string} route
*
* @return {Promise<string>}
*/
putCurrentRouteForUser(teamSlug, botId, userId, route) {
return this._zwermRequest.put(`bots/${teamSlug}/${botId}/users/${userId}/route`, { route })
.then(response => response.data['route']);
}
/**
* Deletes the current route of the given user for the given bot.
*
* This will restore the routing back to it's original, default value.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
*
* @return {Promise<string>}
*/
deleteCurrentRouteForUser(teamSlug, botId, userId) {
return this._zwermRequest.delete(`bots/${teamSlug}/${botId}/users/${userId}/route`)
.then(response => response.data);
}
// endregion
// region conversation routing
/**
* Gets the current route of the given conversation for the given user of the given bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {string} conversationId
*
* @return {Promise<string>}
*/
getCurrentRouteForConversation(teamSlug, botId, userId, conversationId) {
return this._zwermRequest.get(`bots/${teamSlug}/${botId}/users/${userId}/conversations/${conversationId}/route`)
.then(response => response.data['route']);
}
/**
* Puts the given route as the current route of the given conversation for the given user for the given bot.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {string} conversationId
* @param {string} route
*
* @return {Promise<string>}
*/
putCurrentRouteForCoversation(teamSlug, botId, userId, conversationId, route) {
return this._zwermRequest.put(`bots/${teamSlug}/${botId}/users/${userId}/conversations/${conversationId}/route`, { route })
.then(response => response.data['route']);
}
/**
* Deletes the current route of the given conversation for the given user for the given bot.
*
* This will restore the routing back to it's original, default value.
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {string} conversationId
*
* @return {Promise<string>}
*/
deleteCurrentRouteForCoversation(teamSlug, botId, userId, conversationId) {
return this._zwermRequest.delete(`bots/${teamSlug}/${botId}/users/${userId}/conversations/${conversationId}/route`)
.then(response => response.data);
}
// endregion
// endregion
// region metrics
/**
* Request a set of metrics for a bot.
*
* @example <caption>Request the same metric multiple times with different configurations.</caption>
* zwerm.getBotMetrics('my-team', 'my-bot',
* {activeUsers: {interval: '1d', start: '2018-04-01T00:00:00.000Z', end: '2018-05-01T00:00:00.000Z'}},
* {activeUsers: {start: '2018-04-01T00:00:00.000Z', end: '2018-04-02T00:00:00.000Z'}}
* ).then(console.log);
*
* @param {string} teamSlug
* @param {string} botId
* @param {Object<string, Object<string, string>>} [metrics=[]]
*
* @return {Promise<AxiosResponse<Object>>}
*/
getBotMetrics(teamSlug, botId, ...metrics) {
let index = 0;
const keys = {};
const options = {};
// For all requested metric objects
metrics.forEach(metric => {
// go through all keys (they can have more than one, event though it is not recommended)
Object.keys(metric).forEach(key => {
// store the metric key name with the matching index
keys[index] = key;
// go through all the options
Object.keys(metric[key]).forEach(option => {
// store the option with the matching index
options[option] = options[option] || {};
options[option][index] = metric[key][option];
});
// up the index for the next round.
index++;
});
});
return this._zwermRequest
.get(`metrics/${teamSlug}/${botId}`, {
params: Object.assign(options, { metrics: keys }),
// we need to use a serializer that converts the objects to arrays, instead of encoding them
paramsSerializer: params => qs.stringify(params, { encode: false })
})
.then(response => response.data);
}
// endregion
// region teams
/**
* List your teams
*
* @return {Promise<Zwerm.API.Team>}
*/
listUserTeams() {
return this._zwermRequest.get('/user/teams')
.then(response => response.data);
}
// endregion
// region authenticated user
/**
* Get the authenticated user.
*
* @return {Promise<Zwerm.API.User>}
*/
getUser() {
return this._zwermRequest.get('/user')
.then(response => response.data);
}
/**
* Update the authenticated user.
*
* @param {Zwerm.API.PartialUser} partialUser
*
* @return {Promise<Zwerm.API.User>}
*/
updateUser(partialUser) {
return this._zwermRequest.patch('/user', partialUser)
.then(response => response.data);
}
// endregion
// region send letter
/**
*
* @param {string} teamSlug
* @param {string} botId
* @param {string} userId
* @param {string} conversationId
* @param {string} channelId
* @param {StaMP.Protocol.Letter} letter
*
* @return {Promise}
*/
postLetter(teamSlug, botId, userId, conversationId, channelId, letter) {
return this._zwermRequest.post(`bots/${teamSlug}/${botId}/users/${userId}/conversations/${conversationId}/transaction`, {
channelId,
letter
})
.then(response => response.data);
}
// endregion
// region event sending
/**
* Posts an event to Zwerm, where it'll be logged, and be routed onto the appropriate engine.
*
* If no `conversationId` is given, the event will be sent directly to the user,
* meaning that the most current conversation for the user in question will be used,
* with one being created if there isn't a current conversation.
*
* @param {string} teamSlug the team that owns the bot that the event is being in regards to.
* @param {string} botId the id of the bot that the event is being sent in regards to.
* @param {string} userId the id of the user that the event is being sent in regards to.
* @param {string} event the name of the event.
* @param {Object} payload the payload of the event. This cannot be more than 5 levels deep.
* @param {string} [conversationId] the id of the conversation that the event is being sent in regards to.
* @param {string} [channelId] id of the channel to scope this event as coming from.
* @param {string} [route] the engine route to send this event down.
* @param {number} [value] a conversion value.
* @param {string} [timestamp] ISO Datetime for when the event should get triggered
* @param {string} [query] Fallback query to be used with partially supported engines.
*
* @return {Promise}
*
* @see postEventToUser postEventToUser method
* @see postEventToConversation postEventToConversation method
*/
postEvent(teamSlug, botId, userId, event, payload, { conversationId, channelId, route, value, timestamp, query }) {
if (conversationId) {
return this.postEventToConversation(teamSlug, botId, userId, conversationId, event, payload, {
channelId,
route,
value,
timestamp,
query
});
}
return this.postEventToUser(teamSlug, botId, userId, event, payload, { channelId, route, value, timestamp, query });
}
/**
* Posts an event to Zwerm, where it'll be logged, and be routed onto the appropriate engine.
*
* @param {string} teamSlug the team that owns the bot that the event is being in regards to.
* @param {string} botId the id of the bot that the event is being sent in regards to.
* @param {string} userId the id of the user that the event is being sent in regards to.
* @param {string} event the name of the event.
* @param {Object} payload the payload of the event. This cannot be more than 5 objects deep.
* @param {string} [channelId] id of the channel to scope this event as coming from.
* @param {string} [route] the engine route to send this event down.
* @param {number} [value] a conversion value.
* @param {string} [timestamp] ISO Datetime for when the event should get triggered
* @param {string} [query] Fallback query to be used with partially supported engines.
*
* @return {Promise}
*/
postEventToUser(teamSlug, botId, userId, event, payload, { channelId, route, value, timestamp, query }) {
return this._zwermRequest.post(`bots/${teamSlug}/${botId}/users/${userId}/event`, {
event,
payload,
channelId,
route,
value,
timestamp,
query
})
.then(response => response.data);
}
/**
* Posts an event to Zwerm, where it'll be logged, and be routed onto the appropriate engine.
*
* @param {string} teamSlug the team that owns the bot that the event is being in regards to.
* @param {string} botId the id of the bot that the event is being sent in regards to.
* @param {string} userId the id of the user that the event is being sent in regards to.
* @param {string} conversationId the id of the conversation that the event is being sent in regards to.
* @param {string} event the name of the event.
* @param {Object} payload the payload of the event. This cannot be more than 5 objects deep.
* @param {string} [channelId] id of the channel to scope this event as coming from.
* @param {string} [route] the engine route to send this event down.
* @param {number} [value] a conversion value.
* @param {string} [timestamp] ISO Datetime for when the event should get triggered
* @param {string} [query] Fallback query to be used with partially supported engines.
*
* @return {Promise}
*/
postEventToConversation(teamSlug, botId, userId, conversationId, event, payload, { channelId, route, value, timestamp, query }) {
return this._zwermRequest.post(`bots/${teamSlug}/${botId}/users/${userId}/conversations/${conversationId}/event`, {
event,
payload,
channelId,
route,
value,
timestamp,
query
})
.then(response => response.data);
}
// endregion
}
module.exports = ZwermAPI;