@memori.ai/memori-api-client 0.2.1 → 0.3.1

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 (37) hide show
  1. package/README.md +1 -1
  2. package/dist/apiFetcher.d.ts +1 -0
  3. package/dist/backend/consumptionLogs.d.ts +40 -0
  4. package/dist/backend/memori.d.ts +11 -0
  5. package/dist/backend/notifications.d.ts +20 -0
  6. package/dist/backend.d.ts +42 -0
  7. package/dist/engine/chatLogs.d.ts +31 -0
  8. package/dist/engine/customDictionary.d.ts +47 -0
  9. package/dist/engine/dialog.d.ts +3 -9
  10. package/dist/engine/importExport.d.ts +39 -14
  11. package/dist/engine/intents.d.ts +36 -11
  12. package/dist/engine/nlp.d.ts +42 -1
  13. package/dist/engine/stats.d.ts +68 -1
  14. package/dist/engine.d.ts +174 -38
  15. package/dist/index.d.ts +216 -38
  16. package/dist/memori-api-client.cjs.development.js +702 -67
  17. package/dist/memori-api-client.cjs.development.js.map +1 -1
  18. package/dist/memori-api-client.cjs.production.min.js +1 -1
  19. package/dist/memori-api-client.cjs.production.min.js.map +1 -1
  20. package/dist/memori-api-client.esm.js +702 -67
  21. package/dist/memori-api-client.esm.js.map +1 -1
  22. package/dist/types.d.ts +318 -1
  23. package/package.json +1 -1
  24. package/src/apiFetcher.ts +2 -1
  25. package/src/backend/consumptionLogs.ts +79 -0
  26. package/src/backend/memori.ts +20 -0
  27. package/src/backend/notifications.ts +24 -0
  28. package/src/backend.ts +6 -0
  29. package/src/engine/chatLogs.ts +63 -0
  30. package/src/engine/customDictionary.ts +85 -0
  31. package/src/engine/dialog.ts +3 -3
  32. package/src/engine/importExport.ts +56 -16
  33. package/src/engine/intents.ts +58 -21
  34. package/src/engine/nlp.ts +78 -1
  35. package/src/engine/stats.ts +117 -1
  36. package/src/engine.ts +6 -0
  37. package/src/types.ts +327 -1
package/dist/types.d.ts CHANGED
@@ -46,16 +46,21 @@ export declare type Memori = {
46
46
  culture?: string;
47
47
  publishedInTheMetaverse?: boolean;
48
48
  metaverseEnvironment?: string;
49
+ exposed?: boolean;
49
50
  properties?: {
50
51
  [key: string]: string;
51
52
  };
52
53
  creationTimestamp?: string;
53
54
  lastChangeTimestamp?: string;
55
+ blockedUntil?: string;
54
56
  integrations?: Integration[];
55
57
  sentInvitations?: Invitation[];
56
58
  receivedInvitations?: Invitation[];
57
59
  categories?: string[];
58
60
  ownerUserName?: string;
61
+ gamificationLevel?: GamificationLevel;
62
+ contentQualityIndex?: number;
63
+ contentQualityIndexTimestamp?: string;
59
64
  };
60
65
  export declare type Venue = {
61
66
  placeName: string;
@@ -63,6 +68,29 @@ export declare type Venue = {
63
68
  longitude: number;
64
69
  uncertainty?: number;
65
70
  };
71
+ export declare type NotificationPrefs = {
72
+ /**
73
+ * @type {string='None'}
74
+ * minLength: 1
75
+ * Periodicity of chat log extraction (hourly, daily, weekly or none).
76
+ * When chat log extraction is enabled (i.e. not None) chats performed on Memori owned or managed by the User
77
+ * will be periodically collected and sent via e-mail.
78
+ */
79
+ chatLogExtractionPeriod?: 'None' | 'Hourly' | 'Daily' | 'Weekly';
80
+ /**
81
+ * @type {number=5}
82
+ * Minimum lines for an extracted chat to be sent via e-mail to the User.
83
+ * If 0 no filter is applied.
84
+ * Default is 5.
85
+ */
86
+ chatLogExtractionMinLines?: number;
87
+ /**
88
+ * @type {string=}
89
+ * Memori ID to which these preferences apply to.
90
+ * If Null these preferences have default value and apply to all Memori objects not specified with other preferences.
91
+ */
92
+ memoriID?: string;
93
+ };
66
94
  export declare type User = {
67
95
  tenant?: string;
68
96
  userID?: string;
@@ -78,12 +106,18 @@ export declare type User = {
78
106
  maxMemori?: number;
79
107
  canCreateMemori?: boolean;
80
108
  canAccessAPI?: boolean;
109
+ canRunSnippets?: boolean;
81
110
  canEditIntegrations?: boolean;
82
111
  canEditDynamicIntents?: boolean;
83
112
  canEditMemoriChaining?: boolean;
84
113
  maxFreeSessions?: number;
114
+ nonFreeSessionCost?: number;
85
115
  creationTimestamp?: string;
86
116
  lastChangeTimestamp?: string;
117
+ referral?: string;
118
+ couponCode?: string;
119
+ paying?: boolean;
120
+ notificationPrefs?: NotificationPrefs[];
87
121
  };
88
122
  export declare type IntegrationResource = {
89
123
  name: string;
@@ -160,6 +194,7 @@ export declare type Tenant = {
160
194
  usersCanEditMemoriChaining?: boolean;
161
195
  maxFreeSessions?: number;
162
196
  maxFreeSessionsPerUser?: number;
197
+ nonFreeSessionCost?: number;
163
198
  };
164
199
  export declare type OpenSession = {
165
200
  memoriID: string;
@@ -212,7 +247,7 @@ export declare type GamificationLevel = {
212
247
  points: number;
213
248
  badge: string;
214
249
  pointsForCurrentBadge: number;
215
- nextBadge: {
250
+ nextBadge?: {
216
251
  points: number;
217
252
  badge: string;
218
253
  };
@@ -404,7 +439,289 @@ export declare type UnansweredQuestion = {
404
439
  };
405
440
  export declare type Message = {
406
441
  text: string;
442
+ translatedText?: string;
407
443
  fromUser?: boolean;
408
444
  media?: Medium[];
409
445
  initial?: boolean;
446
+ timestamp?: string;
447
+ contextVars?: {
448
+ [key: string]: string;
449
+ };
450
+ };
451
+ export declare type ConsumptionLog = {
452
+ consumptionLogID: string;
453
+ from: string;
454
+ to: string;
455
+ type: 'Daily' | 'Monthly';
456
+ userID?: string;
457
+ memoriID?: string;
458
+ totalSessions: number;
459
+ validSessions: number;
460
+ };
461
+ export declare type Notification = {
462
+ notificationID: string;
463
+ timestamp: string;
464
+ severity: 'INFO' | 'WARN' | 'ALERT';
465
+ texts: {
466
+ 'it-IT': string;
467
+ 'en-US': string;
468
+ [lang: string]: string;
469
+ };
470
+ };
471
+ export declare type ChatMedium = {
472
+ /**
473
+ * URL of the Medium. If specified, the Content property is Null.
474
+ */
475
+ url?: string;
476
+ /**
477
+ * Content of the Medium. If specified, the URL property is Null.
478
+ */
479
+ content?: string;
480
+ /**
481
+ * MIME type of the Medium.
482
+ */
483
+ mimeType: string;
484
+ /**
485
+ * Title of the Medium.
486
+ */
487
+ title?: string;
488
+ /**
489
+ * Key-value pairs for additional structured content storage.
490
+ */
491
+ properties?: {
492
+ [key: string]: string;
493
+ };
494
+ };
495
+ export declare type ChatLogLine = {
496
+ /**
497
+ * @type {string}
498
+ * Timestamp UTC of the line.
499
+ */
500
+ timestamp: string;
501
+ /**
502
+ * @type {boolean}
503
+ * If True the line is the text from a Text Entered Event. If False the line is Dialog State Machine emission.
504
+ */
505
+ inbound: boolean;
506
+ /**
507
+ * @type {string}
508
+ * Text of the line.
509
+ */
510
+ text: string;
511
+ /**
512
+ * Media attached with the Dialog State Machine emission, if present. Empty if the line is inbound.
513
+ */
514
+ media?: ChatMedium[];
515
+ /**
516
+ * Dialog State Machine context variables after the emission, if present. Empty if the line is inbound.
517
+ */
518
+ contextVars?: {
519
+ [key: string]: string;
520
+ };
521
+ };
522
+ export declare type ChatLog = {
523
+ /**
524
+ * @param {string}
525
+ * Chat Log object ID.
526
+ */
527
+ chatLogID: string;
528
+ /**
529
+ * @type {string}
530
+ * Timestamp UTC of the chat log creation.
531
+ */
532
+ timestamp: string;
533
+ /**
534
+ * @type {string}
535
+ * ID of the related Memori object in the Engine.
536
+ * Relates to Memori.engineMemoriID
537
+ */
538
+ memoriID: string;
539
+ /**
540
+ * @type {string}
541
+ * ID of the related session.
542
+ */
543
+ sessionID: string;
544
+ /**
545
+ * @type {?string}
546
+ * Tag of the Person object authenticated in the session. Null if the chat was performed by anonymous.
547
+ */
548
+ receiverTag?: string;
549
+ /**
550
+ * List of Chat Line objects of this chat.
551
+ */
552
+ lines: ChatLogLine[];
553
+ };
554
+ export declare type Utterance = {
555
+ /**
556
+ * Utterance object ID.
557
+ */
558
+ utteranceID?: string;
559
+ /**
560
+ * Accepted Utterance object for its corresponding intent,
561
+ * i.e. the text sentece that can be used to express the intent.
562
+ * An Utterance may include variable parts in the sentence by the use of one or more slots.
563
+ * Slots are specified using the syntax {slot}, where "slot" is the slot name.
564
+ * If present, their value is part of the IntentWebHookRequest passed to the web hook.
565
+ * Each slot can be present only once in the sentence, and must have been previously defined with a Intent Slot object.
566
+ * A special slot is the {date} slot, which represents a period of time such as "today", "yesterday", "last week", "next month" etc.
567
+ * Its values is passed in the IntentWebHookRequest as the BeginUTC and EndUTC properties.
568
+ */
569
+ text: string;
570
+ /**
571
+ * Timestamp of creation.
572
+ * Always present when reading/receiving an object,
573
+ * ignored when writing/sending an object.
574
+ */
575
+ creationTimestamp?: string;
576
+ /**
577
+ * ID of the session that created this object.
578
+ */
579
+ creationSessionID?: string;
580
+ /**
581
+ * Timestamp of latest change.
582
+ * Always present when reading/receiving an object,
583
+ * ignored when writing/sending an object.
584
+ */
585
+ lastChangeTimestamp?: string;
586
+ /**
587
+ * ID of the latest session that changed this object.
588
+ */
589
+ lastChangeSessionID?: string;
590
+ };
591
+ export declare type Intent = {
592
+ /**
593
+ * Intent object ID.
594
+ */
595
+ intentID?: string;
596
+ /**
597
+ * Memory type, e.g. Internal or WebHook.
598
+ * Internal intents are a limited subset implemented internally,
599
+ * while WebHook intents perform an external HTTP POST call to the specified web hook,
600
+ * passing an IntentWebHookRequest and expecting an IntentWebHookRespose in response.
601
+ * When updating an existing intent, this property is ignored.
602
+ */
603
+ intentType?: 'Internal' | 'WebHook';
604
+ /**
605
+ * Name of the Intent object.
606
+ * It is part of the IntentWebHookRequest request passed to the web hook.
607
+ */
608
+ name: string;
609
+ /**
610
+ * List of accepted Utterance objects for this Intent,
611
+ * i.e. the list of text senteces that can be used to express the intent.
612
+ * Utterances may include variable parts in the sentence by the use of one or more slots.
613
+ * Slots are specified using the syntax {slot}, where "slot" is the slot name.
614
+ * If present, their value is part of the IntentWebHookRequest passed to the web hook.
615
+ * Each slot can be present only once in the sentence, and must have been previously defined with a Intent Slot object.
616
+ * A special slot is the {date} slot, which represents a period of time such as "today", "yesterday", "last week", "next month" etc.
617
+ * Its values is passed in the IntentWebHookRequest as the BeginUTC and EndUTC properties.
618
+ */
619
+ utterances: Utterance[];
620
+ /**
621
+ * If True this Intent may be executed to serve a Timeout event in R1 state.
622
+ * In this case the utterance is null.
623
+ * In case more than one Intent have this flag set, a random one is picked.
624
+ */
625
+ timeoutIntent?: boolean;
626
+ /**
627
+ * HTTP URL of the web hook to be called when the intent is recognized.
628
+ * If the intent is of Internal type, it is ignored.
629
+ */
630
+ webHook?: string;
631
+ /**
632
+ * Time to cache the intent response, expressed in minutes.
633
+ * May be fractional. A minimum of 0.1 minutes (i.e. 6 seconds) is always applied.
634
+ * A cached intent response is used only when the a subsequent intent request matches exactly the original request.
635
+ * See also RequestValidityMinutes in WebHookRequest.
636
+ */
637
+ validityMinutes?: number;
638
+ /**
639
+ * Timestamp of creation.
640
+ * Always present when reading/receiving an object,
641
+ * ignored when writing/sending an object.
642
+ */
643
+ creationTimestamp?: string;
644
+ /**
645
+ * ID of the session that created this object.
646
+ */
647
+ creationSessionID?: string;
648
+ /**
649
+ * Timestamp of latest change.
650
+ * Always present when reading/receiving an object,
651
+ * ignored when writing/sending an object.
652
+ */
653
+ lastChangeTimestamp?: string;
654
+ /**
655
+ * ID of the latest session that changed this object.
656
+ */
657
+ lastChangeSessionID?: string;
658
+ };
659
+ export declare type IntentSlot = {
660
+ /**
661
+ * Intent Slot object ID.
662
+ */
663
+ intentSlotID?: string;
664
+ /**
665
+ * Name of the Intent Slot object.
666
+ * It is part of the SlotWebHookRequest request passed to the web hook.
667
+ */
668
+ name: string;
669
+ /**
670
+ * List of possible values of the slot.
671
+ * A slot may be composed of fixed values in this property,
672
+ * dynamic values fetched from the web hook, or a combination of both.
673
+ * Each value is considered only onces (duplicate values are ignored).
674
+ */
675
+ values?: string[];
676
+ /**
677
+ * HTTP URL of the web hook to be called when the slot values must be fetched.
678
+ * May be null if the slot is composed only of fixed values in the Values property.
679
+ * If specified, the web hook is called periodically with an HTTP POST call,
680
+ * passing a SlotWebHookRequest and expecting a SlotWebHookRespose in response.
681
+ * Periodicity is determined by the ValidityMinutes property.
682
+ */
683
+ webHook?: string;
684
+ /**
685
+ * Time to cache the slot values, expressed in minutes.
686
+ * May be fractional. A minimum of 0.5 minutes (i.e. 30 seconds) is always applied.
687
+ * See also RequestValidityMinutes in WebHookRequest.
688
+ */
689
+ validityMinutes?: number;
690
+ /**
691
+ * Timestamp of creation.
692
+ * Always present when reading/receiving an object,
693
+ * ignored when writing/sending an object.
694
+ */
695
+ creationTimestamp?: string;
696
+ /**
697
+ * ID of the session that created this object.
698
+ */
699
+ creationSessionID?: string;
700
+ /**
701
+ * Timestamp of latest change.
702
+ * Always present when reading/receiving an object,
703
+ * ignored when writing/sending an object.
704
+ */
705
+ lastChangeTimestamp?: string;
706
+ /**
707
+ * ID of the latest session that changed this object.
708
+ */
709
+ lastChangeSessionID?: string;
710
+ };
711
+ export declare type CustomWord = {
712
+ customWordID: string;
713
+ word: string;
714
+ /**
715
+ * Definition of the Custom Word, in terms of sums and subtractions of existing words or custom words.
716
+ * The syntax for a Custom Word definition is as follows: word1 [+-] word2 [+-] word3...
717
+ * If the operator is omitted it is assumed to be the last specified from the left, and if no operator has been specified it is assumed to be the sum.
718
+ * E.g.:
719
+ * - alpha beta gamma is equivalent to alpha + beta + gamma
720
+ * - alpha beta - gamma deta is equivalent to alpha + beta - gamma - delta
721
+ */
722
+ definition: string;
723
+ creationTimestamp: string;
724
+ creationSessionID: string;
725
+ lastChangeTimestamp: string;
726
+ lastChangeSessionID: string;
410
727
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.1",
2
+ "version": "0.3.1",
3
3
  "main": "dist/index.js",
4
4
  "typings": "dist/index.d.ts",
5
5
  "files": [
package/src/apiFetcher.ts CHANGED
@@ -7,6 +7,7 @@ export const apiFetcher = (
7
7
  method?: string;
8
8
  body?: object;
9
9
  headers?: object;
10
+ text?: boolean;
10
11
  }
11
12
  ) =>
12
13
  fetch(`${opts.apiUrl}${path}`, {
@@ -19,4 +20,4 @@ export const apiFetcher = (
19
20
  'Content-Type': 'application/json',
20
21
  ...opts?.headers,
21
22
  },
22
- }).then(res => res.json());
23
+ }).then(res => (opts?.text ? res.text() : res.json()));
@@ -0,0 +1,79 @@
1
+ import { ResponseSpec, ConsumptionLog } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ export default (apiUrl: string) => ({
5
+ /**
6
+ * Gets the Consumption Log objects for a specific Tenant in a specific date interval.
7
+ * @param {string} authToken - The login token
8
+ * @param {string} tenantID - The name of the tenant
9
+ * @param {string} type - Type of consumption (i.e. granularity), it may either be Daily or Monthly
10
+ * @param {string=} dateFrom - The optional begin of the date interval, in UTC time, in the format yyyyMMdd
11
+ * @param {string=} dateTo - The optional end of the date interval, in UTC time, in the format yyyyMMdd
12
+ * @returns The list of Consumption Logs objects.
13
+ */
14
+ getTenantConsumptionLogs: (
15
+ authToken: string,
16
+ tenantID: string,
17
+ type: 'Daily' | 'Monthly',
18
+ dateFrom?: string,
19
+ dateTo?: string
20
+ ) =>
21
+ apiFetcher(
22
+ `/TenantConsumptionLogs/${authToken}/${tenantID}/${type}${
23
+ dateFrom ? `/${dateFrom}` : ''
24
+ }${dateFrom && dateTo ? `/${dateTo}` : ''}`,
25
+ {
26
+ apiUrl,
27
+ }
28
+ ) as Promise<ResponseSpec & { consumptionLogs: ConsumptionLog[] }>,
29
+
30
+ /**
31
+ * Gets the Consumption Log objects for a specific User in a specific date interval.
32
+ * @param {string} authToken - The login token
33
+ * @param {string} userID - The ID of the User object
34
+ * @param {string} type - Type of consumption (i.e. granularity), it may either be Daily or Monthly
35
+ * @param {string=} dateFrom - The optional begin of the date interval, in UTC time, in the format yyyyMMdd
36
+ * @param {string=} dateTo - The optional end of the date interval, in UTC time, in the format yyyyMMdd
37
+ * @returns The list of Consumption Logs objects.
38
+ */
39
+ getUserConsumptionLogs: (
40
+ authToken: string,
41
+ userID: string,
42
+ type: 'Daily' | 'Monthly',
43
+ dateFrom?: string,
44
+ dateTo?: string
45
+ ) =>
46
+ apiFetcher(
47
+ `/UserConsumptionLogs/${authToken}/${userID}/${type}${
48
+ dateFrom ? `/${dateFrom}` : ''
49
+ }${dateFrom && dateTo ? `/${dateTo}` : ''}`,
50
+ {
51
+ apiUrl,
52
+ }
53
+ ) as Promise<ResponseSpec & { consumptionLogs: ConsumptionLog[] }>,
54
+
55
+ /**
56
+ * Gets the Consumption Log objects for a specific Memori in a specific date interval.
57
+ * @param {string} authToken - The login token
58
+ * @param {string} memoriID - The ID of the Memori object
59
+ * @param {string} type - Type of consumption (i.e. granularity), it may either be Daily or Monthly
60
+ * @param {string=} dateFrom - The optional begin of the date interval, in UTC time, in the format yyyyMMdd
61
+ * @param {string=} dateTo - The optional end of the date interval, in UTC time, in the format yyyyMMdd
62
+ * @returns The list of Consumption Logs objects.
63
+ */
64
+ getMemoriConsumptionLogs: (
65
+ authToken: string,
66
+ memoriID: string,
67
+ type: 'Daily' | 'Monthly',
68
+ dateFrom?: string,
69
+ dateTo?: string
70
+ ) =>
71
+ apiFetcher(
72
+ `/MemoriConsumptionLogs/${authToken}/${memoriID}/${type}${
73
+ dateFrom ? `/${dateFrom}` : ''
74
+ }${dateFrom && dateTo ? `/${dateTo}` : ''}`,
75
+ {
76
+ apiUrl,
77
+ }
78
+ ) as Promise<ResponseSpec & { consumptionLogs: ConsumptionLog[] }>,
79
+ });
@@ -223,4 +223,24 @@ export default (apiUrl: string) => ({
223
223
  validSessions: number;
224
224
  }
225
225
  >,
226
+
227
+ /**
228
+ * Transfers an existing Memori object to another User.
229
+ * The new owner must be specified by either a OwnerUserID or a OwnerUserName-OwnerTenantName pair.
230
+ * The OwnerUserName may also specify a user e-mail.
231
+ * @param {string} authToken - The login token
232
+ * @param {Memori} memori - The Memori object
233
+ */
234
+ transferMemori: (
235
+ authToken: string,
236
+ memori: Memori & {
237
+ ownerTenantName: string;
238
+ ownerUserName: string;
239
+ }
240
+ ) =>
241
+ apiFetcher(`/TransferMemori/${authToken}`, {
242
+ apiUrl,
243
+ body: memori,
244
+ method: 'POST',
245
+ }) as Promise<ResponseSpec>,
226
246
  });
@@ -0,0 +1,24 @@
1
+ import { ResponseSpec, Notification } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ export default (apiUrl: string) => ({
5
+ /**
6
+ * Gets the Notification objects available for a specific Tenant.
7
+ * @param {string} tenantID - The name of the tenant
8
+ * @returns The list of Notification objects.
9
+ */
10
+ getTenantNotifications: (tenantID: string) =>
11
+ apiFetcher(`/TenantNotifications/${tenantID}`, {
12
+ apiUrl,
13
+ }) as Promise<ResponseSpec & { notifications: Notification[] }>,
14
+
15
+ /**
16
+ * Gets the Notification objects available for a specific User.
17
+ * @param {string} authToken - The login token
18
+ * @returns The list of Notification objects.
19
+ */
20
+ getUserNotifications: (authToken: string) =>
21
+ apiFetcher(`/UserNotifications/${authToken}`, {
22
+ apiUrl,
23
+ }) as Promise<ResponseSpec & { notifications: Notification[] }>,
24
+ });
package/src/backend.ts CHANGED
@@ -3,6 +3,8 @@ import user from './backend/user';
3
3
  import integration from './backend/integration';
4
4
  import asset from './backend/asset';
5
5
  import invitation from './backend/invitation';
6
+ import consumptionLogs from './backend/consumptionLogs';
7
+ import notifications from './backend/notifications';
6
8
 
7
9
  const backendAPI = (apiUrl: string) => ({
8
10
  asset: asset(apiUrl),
@@ -10,11 +12,15 @@ const backendAPI = (apiUrl: string) => ({
10
12
  user: user(apiUrl),
11
13
  integration: integration(apiUrl),
12
14
  invitation: invitation(apiUrl),
15
+ consumptionLogs: consumptionLogs(apiUrl),
16
+ notifications: notifications(apiUrl),
13
17
  ...asset(apiUrl),
14
18
  ...memori(apiUrl),
15
19
  ...user(apiUrl),
16
20
  ...integration(apiUrl),
17
21
  ...invitation(apiUrl),
22
+ ...consumptionLogs(apiUrl),
23
+ ...notifications(apiUrl),
18
24
  });
19
25
 
20
26
  export default backendAPI;
@@ -0,0 +1,63 @@
1
+ import { ChatLog, ResponseSpec } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /*************************
5
+ * *
6
+ * ChatLogs *
7
+ * *
8
+ *************************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Gets the Chat Log objects for the Memori of the current session in a specific date interval.
13
+ * @param {string} sessionId The session ID
14
+ * @param {?string} dateFrom The optional begin of the date interval, in UTC time, in the format yyyyMMddHHmmssfff
15
+ * @param {?string} dateTo The optional end of the date interval, in UTC time, in the format yyyyMMddHHmmssfff
16
+ */
17
+ getChatLogs: async (sessionId: string, dateFrom?: string, dateTo?: string) =>
18
+ apiFetcher(
19
+ `/ChatLogs/${sessionId}${dateFrom ? `/${dateFrom}` : ''}${
20
+ dateFrom && dateTo ? `/${dateTo}` : ''
21
+ }`,
22
+ {
23
+ method: 'GET',
24
+ apiUrl,
25
+ }
26
+ ) as Promise<
27
+ ResponseSpec & {
28
+ chatLogs: ChatLog[];
29
+ }
30
+ >,
31
+
32
+ /**
33
+ * Removes all Chat Log objects in a specific date internval.
34
+ * @param {string} sessionId The session ID
35
+ * @param {?string} dateFrom The optional begin of the date interval, in UTC time, in the format yyyyMMddHHmmssfff
36
+ * @param {?string} dateTo The optional end of the date interval, in UTC time, in the format yyyyMMddHHmmssfff
37
+ */
38
+ deleteChatLogs: async (
39
+ sessionId: string,
40
+ dateFrom?: string,
41
+ dateTo?: string
42
+ ) =>
43
+ apiFetcher(
44
+ `/ChatLogs/${sessionId}${dateFrom ? `/${dateFrom}` : ''}${
45
+ dateFrom && dateTo ? `/${dateTo}` : ''
46
+ }`,
47
+ {
48
+ method: 'DELETE',
49
+ apiUrl,
50
+ }
51
+ ) as Promise<ResponseSpec>,
52
+
53
+ /**
54
+ * Removes an existing Chat Log object.
55
+ * @param {string} sessionId The session ID
56
+ * @param {string} chatLogId The Chat Log object ID
57
+ */
58
+ deleteChatLog: async (sessionId: string, chatLogId: string) =>
59
+ apiFetcher(`/ChatLog/${sessionId}/${chatLogId}`, {
60
+ method: 'DELETE',
61
+ apiUrl,
62
+ }) as Promise<ResponseSpec>,
63
+ });
@@ -0,0 +1,85 @@
1
+ import { ResponseSpec, CustomWord } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /****************************
5
+ * *
6
+ * CustomDictionary *
7
+ * *
8
+ ****************************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Lists all Custom Words.
13
+ * @param {string} sessionId The session ID
14
+ */
15
+ getCustomWords: async (sessionId: string) =>
16
+ apiFetcher(`/CustomWords/${sessionId}`, {
17
+ method: 'GET',
18
+ apiUrl,
19
+ }) as Promise<
20
+ ResponseSpec & {
21
+ customWords: CustomWord[];
22
+ }
23
+ >,
24
+
25
+ /**
26
+ * Gets the details of a Custom Word object.
27
+ * @param {string} sessionId The session ID
28
+ * @param {string} customWordID The Custom Word object ID
29
+ */
30
+ getCustomWord: async (sessionId: string, customWordID: string) =>
31
+ apiFetcher(`/CustomWord/${sessionId}/${customWordID}`, {
32
+ method: 'GET',
33
+ apiUrl,
34
+ }) as Promise<
35
+ ResponseSpec & {
36
+ customWord: CustomWord;
37
+ }
38
+ >,
39
+
40
+ /**
41
+ * Removes an existing Custom Word object.
42
+ * @param {string} sessionId The session ID
43
+ * @param {string} key The key of the Custom Word
44
+ */
45
+ deleteCustomWord: async (sessionId: string, key: string) =>
46
+ apiFetcher(`/CustomWord/${sessionId}/${key}`, {
47
+ method: 'DELETE',
48
+ apiUrl,
49
+ }) as Promise<ResponseSpec>,
50
+
51
+ /**
52
+ * Adds a new Custom Word object.
53
+ * @param {string} sessionId The session ID
54
+ * @param {CustomWord} customWord Custom Word
55
+ */
56
+ postCustomWord: async (
57
+ sessionId: string,
58
+ customWord: Pick<CustomWord, 'word'> & Pick<CustomWord, 'definition'>
59
+ ) =>
60
+ apiFetcher(`/CustomWord/${sessionId}`, {
61
+ method: 'POST',
62
+ apiUrl,
63
+ body: customWord,
64
+ }) as Promise<
65
+ ResponseSpec & {
66
+ customWord: CustomWord;
67
+ }
68
+ >,
69
+
70
+ /**
71
+ * Updates an existing Custom Word object.
72
+ * Only the Definition field is considered for update. To change the Word field a new Custom Word must be added and the existing must be removed.
73
+ * @param {string} sessionId The session ID
74
+ * @param {CustomWord} customWord Custom Word
75
+ */
76
+ patchCustomWord: async (
77
+ sessionId: string,
78
+ customWord: Partial<CustomWord> & { customWordID: string }
79
+ ) =>
80
+ apiFetcher(`/CustomWord/${sessionId}/${customWord.customWordID}`, {
81
+ method: 'PATCH',
82
+ apiUrl,
83
+ body: customWord,
84
+ }) as Promise<ResponseSpec>,
85
+ });