@servicetitan/titan-chatbot-api 4.1.1 → 4.2.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/api-client/__mocks__/chatbot-api-client.mock.d.ts +2 -0
  3. package/dist/api-client/__mocks__/chatbot-api-client.mock.d.ts.map +1 -1
  4. package/dist/api-client/__mocks__/chatbot-api-client.mock.js +12 -0
  5. package/dist/api-client/__mocks__/chatbot-api-client.mock.js.map +1 -1
  6. package/dist/api-client/base/chatbot-api-client.d.ts +2 -0
  7. package/dist/api-client/base/chatbot-api-client.d.ts.map +1 -1
  8. package/dist/api-client/help-center/chatbot-api-client.d.ts +2 -0
  9. package/dist/api-client/help-center/chatbot-api-client.d.ts.map +1 -1
  10. package/dist/api-client/help-center/chatbot-api-client.js +13 -0
  11. package/dist/api-client/help-center/chatbot-api-client.js.map +1 -1
  12. package/dist/api-client/models/index.d.ts +1 -1
  13. package/dist/api-client/models/index.d.ts.map +1 -1
  14. package/dist/api-client/models/index.js +1 -1
  15. package/dist/api-client/models/index.js.map +1 -1
  16. package/dist/api-client/titan-chat/chatbot-api-client.d.ts +2 -0
  17. package/dist/api-client/titan-chat/chatbot-api-client.d.ts.map +1 -1
  18. package/dist/api-client/titan-chat/chatbot-api-client.js +6 -0
  19. package/dist/api-client/titan-chat/chatbot-api-client.js.map +1 -1
  20. package/dist/api-client/titan-chat/native-client.d.ts +147 -4
  21. package/dist/api-client/titan-chat/native-client.d.ts.map +1 -1
  22. package/dist/api-client/titan-chat/native-client.js +341 -0
  23. package/dist/api-client/titan-chat/native-client.js.map +1 -1
  24. package/dist/stores/__tests__/chatbot-ui-backend.store.test.js +10 -2
  25. package/dist/stores/__tests__/chatbot-ui-backend.store.test.js.map +1 -1
  26. package/dist/stores/__tests__/chatbot-ui.store.test.js +1 -1
  27. package/dist/stores/__tests__/chatbot-ui.store.test.js.map +1 -1
  28. package/dist/stores/chatbot-ui-backend.store.d.ts +2 -0
  29. package/dist/stores/chatbot-ui-backend.store.d.ts.map +1 -1
  30. package/dist/stores/chatbot-ui-backend.store.js +10 -1
  31. package/dist/stores/chatbot-ui-backend.store.js.map +1 -1
  32. package/dist/stores/chatbot-ui.store.d.ts +2 -2
  33. package/dist/stores/chatbot-ui.store.d.ts.map +1 -1
  34. package/dist/stores/chatbot-ui.store.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/api-client/__mocks__/chatbot-api-client.mock.ts +2 -0
  37. package/src/api-client/base/chatbot-api-client.ts +6 -0
  38. package/src/api-client/help-center/chatbot-api-client.ts +16 -0
  39. package/src/api-client/models/index.ts +2 -0
  40. package/src/api-client/titan-chat/chatbot-api-client.ts +8 -0
  41. package/src/api-client/titan-chat/native-client.ts +307 -4
  42. package/src/stores/__tests__/chatbot-ui-backend.store.test.ts +10 -2
  43. package/src/stores/__tests__/chatbot-ui.store.test.ts +1 -1
  44. package/src/stores/chatbot-ui-backend.store.ts +18 -7
  45. package/src/stores/chatbot-ui.store.ts +2 -2
  46. package/tsconfig.tsbuildinfo +1 -1
@@ -312,17 +312,142 @@ export class Client {
312
312
  }
313
313
  return Promise.resolve<Session>(null as any);
314
314
  }
315
+
316
+ /**
317
+ * @param start (optional)
318
+ * @param end (optional)
319
+ * @param x_Client_ID (optional)
320
+ * @return Success
321
+ */
322
+ transcripts(start: Date | undefined, end: Date | undefined, version: string, x_Client_ID: any | undefined, signal?: AbortSignal): Promise<ExportHistoryMessage[]> {
323
+ let url_ = this.baseUrl + "/api/v{version}/transcripts?";
324
+ if (version === undefined || version === null)
325
+ throw new Error("The parameter 'version' must be defined.");
326
+ url_ = url_.replace("{version}", encodeURIComponent("" + version));
327
+ if (start === null)
328
+ throw new Error("The parameter 'start' cannot be null.");
329
+ else if (start !== undefined)
330
+ url_ += "start=" + encodeURIComponent(start ? "" + start.toISOString() : "") + "&";
331
+ if (end === null)
332
+ throw new Error("The parameter 'end' cannot be null.");
333
+ else if (end !== undefined)
334
+ url_ += "end=" + encodeURIComponent(end ? "" + end.toISOString() : "") + "&";
335
+ url_ = url_.replace(/[?&]$/, "");
336
+
337
+ let options_: RequestInit = {
338
+ method: "GET",
339
+ signal,
340
+ headers: {
341
+ "X-Client-ID": x_Client_ID !== undefined && x_Client_ID !== null ? "" + x_Client_ID : "",
342
+ "Accept": "text/plain"
343
+ }
344
+ };
345
+
346
+ return this.http.fetch(url_, options_).then((_response: Response) => {
347
+ return this.processTranscripts(_response);
348
+ });
349
+ }
350
+
351
+ protected processTranscripts(response: Response): Promise<ExportHistoryMessage[]> {
352
+ const status = response.status;
353
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
354
+ if (status === 200) {
355
+ return response.text().then((_responseText) => {
356
+ let result200: any = null;
357
+ let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
358
+ if (Array.isArray(resultData200)) {
359
+ result200 = [] as any;
360
+ for (let item of resultData200)
361
+ result200!.push(ExportHistoryMessage.fromJS(item));
362
+ }
363
+ else {
364
+ result200 = <any>null;
365
+ }
366
+ return result200;
367
+ });
368
+ } else if (status !== 200 && status !== 204) {
369
+ return response.text().then((_responseText) => {
370
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
371
+ });
372
+ }
373
+ return Promise.resolve<ExportHistoryMessage[]>(null as any);
374
+ }
375
+
376
+ /**
377
+ * @param sessionId (optional)
378
+ * @param x_Client_ID (optional)
379
+ * @return Success
380
+ */
381
+ summary(sessionId: number | undefined, version: string, x_Client_ID: any | undefined, signal?: AbortSignal): Promise<string> {
382
+ let url_ = this.baseUrl + "/api/v{version}/transcripts/summary?";
383
+ if (version === undefined || version === null)
384
+ throw new Error("The parameter 'version' must be defined.");
385
+ url_ = url_.replace("{version}", encodeURIComponent("" + version));
386
+ if (sessionId === null)
387
+ throw new Error("The parameter 'sessionId' cannot be null.");
388
+ else if (sessionId !== undefined)
389
+ url_ += "sessionId=" + encodeURIComponent("" + sessionId) + "&";
390
+ url_ = url_.replace(/[?&]$/, "");
391
+
392
+ let options_: RequestInit = {
393
+ method: "GET",
394
+ signal,
395
+ headers: {
396
+ "X-Client-ID": x_Client_ID !== undefined && x_Client_ID !== null ? "" + x_Client_ID : "",
397
+ "Accept": "text/plain"
398
+ }
399
+ };
400
+
401
+ return this.http.fetch(url_, options_).then((_response: Response) => {
402
+ return this.processSummary(_response);
403
+ });
404
+ }
405
+
406
+ protected processSummary(response: Response): Promise<string> {
407
+ const status = response.status;
408
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
409
+ if (status === 200) {
410
+ return response.text().then((_responseText) => {
411
+ let result200: any = null;
412
+ let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
413
+ result200 = resultData200 !== undefined ? resultData200 : <any>null;
414
+
415
+ return result200;
416
+ });
417
+ } else if (status !== 200 && status !== 204) {
418
+ return response.text().then((_responseText) => {
419
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
420
+ });
421
+ }
422
+ return Promise.resolve<string>(null as any);
423
+ }
315
424
  }
316
425
 
426
+ /** Chatbot response message. */
317
427
  export class BotMessage implements IBotMessage {
318
- id!: number;
319
- sessionId!: number;
428
+ /** Primary key. */
429
+ id?: number;
430
+ /** Session ID. Required in multi-turn conversations after the session is created. */
431
+ sessionId?: number | undefined;
432
+ timeStamp?: Date;
433
+ /** Chatbot answer. */
320
434
  answer!: string;
435
+ /** Ordered list of relevant Knowledge Base links. */
321
436
  scoredUrls?: ScoredUrl[] | undefined;
437
+ /** A value indicating one of the conditions:
438
+ - N - "none" or "normal", a successful response
439
+ - A - "agent", user wants to talk to a support agent
440
+ - C - "conversation", user attempted to continue a conversation in a single-turn message
441
+ - OI - "offensive input"
442
+ Client may handle these conditions in different ways. */
322
443
  guardFlag!: string;
444
+ /** Whether the answer is guardrailed, meaning TitanChatbot.Host.API.Models.BotMessage.GuardFlag is anything but "N". */
323
445
  isGuardrailed!: boolean;
446
+ /** Chatbot version number. */
324
447
  botVersion?: string | undefined;
448
+ /** AI model version. */
325
449
  modelVersion?: string | undefined;
450
+ /** Various metadata for diagnostics purposes. */
326
451
  meta?: any | undefined;
327
452
 
328
453
  constructor(data?: IBotMessage) {
@@ -338,6 +463,7 @@ export class BotMessage implements IBotMessage {
338
463
  if (_data) {
339
464
  this.id = _data["id"];
340
465
  this.sessionId = _data["sessionId"];
466
+ this.timeStamp = _data["timeStamp"] ? new Date(_data["timeStamp"].toString()) : <any>undefined;
341
467
  this.answer = _data["answer"];
342
468
  if (Array.isArray(_data["scoredUrls"])) {
343
469
  this.scoredUrls = [] as any;
@@ -363,6 +489,7 @@ export class BotMessage implements IBotMessage {
363
489
  data = typeof data === 'object' ? data : {};
364
490
  data["id"] = this.id;
365
491
  data["sessionId"] = this.sessionId;
492
+ data["timeStamp"] = this.timeStamp ? this.timeStamp.toISOString() : <any>undefined;
366
493
  data["answer"] = this.answer;
367
494
  if (Array.isArray(this.scoredUrls)) {
368
495
  data["scoredUrls"] = [];
@@ -378,15 +505,31 @@ export class BotMessage implements IBotMessage {
378
505
  }
379
506
  }
380
507
 
508
+ /** Chatbot response message. */
381
509
  export interface IBotMessage {
382
- id: number;
383
- sessionId: number;
510
+ /** Primary key. */
511
+ id?: number;
512
+ /** Session ID. Required in multi-turn conversations after the session is created. */
513
+ sessionId?: number | undefined;
514
+ timeStamp?: Date;
515
+ /** Chatbot answer. */
384
516
  answer: string;
517
+ /** Ordered list of relevant Knowledge Base links. */
385
518
  scoredUrls?: ScoredUrl[] | undefined;
519
+ /** A value indicating one of the conditions:
520
+ - N - "none" or "normal", a successful response
521
+ - A - "agent", user wants to talk to a support agent
522
+ - C - "conversation", user attempted to continue a conversation in a single-turn message
523
+ - OI - "offensive input"
524
+ Client may handle these conditions in different ways. */
386
525
  guardFlag: string;
526
+ /** Whether the answer is guardrailed, meaning TitanChatbot.Host.API.Models.BotMessage.GuardFlag is anything but "N". */
387
527
  isGuardrailed: boolean;
528
+ /** Chatbot version number. */
388
529
  botVersion?: string | undefined;
530
+ /** AI model version. */
389
531
  modelVersion?: string | undefined;
532
+ /** Various metadata for diagnostics purposes. */
390
533
  meta?: any | undefined;
391
534
  }
392
535
 
@@ -395,11 +538,125 @@ export enum Experience {
395
538
  MultiTurn = 2,
396
539
  }
397
540
 
541
+ export class ExportHistoryMessage implements IExportHistoryMessage {
542
+ /** Primary key. */
543
+ id?: number;
544
+ /** Session ID. Required in multi-turn conversations after the session is created. */
545
+ sessionId?: number | undefined;
546
+ timeStamp?: Date;
547
+ userId?: number;
548
+ sessionStartTime?: Date;
549
+ sessionEndTime?: Date | undefined;
550
+ userName?: string | undefined;
551
+ userEmail?: string | undefined;
552
+ question?: string | undefined;
553
+ answer?: string | undefined;
554
+ messageType?: string | undefined;
555
+ salesforceCaseId?: string | undefined;
556
+ guardFlag?: string | undefined;
557
+ isGuardrailed?: boolean;
558
+ botVersion?: string | undefined;
559
+ metadata?: any | undefined;
560
+ feedback?: Feedback;
561
+ sessionFeedback?: Feedback;
562
+
563
+ constructor(data?: IExportHistoryMessage) {
564
+ if (data) {
565
+ for (var property in data) {
566
+ if (data.hasOwnProperty(property))
567
+ (<any>this)[property] = (<any>data)[property];
568
+ }
569
+ }
570
+ }
571
+
572
+ init(_data?: any) {
573
+ if (_data) {
574
+ this.id = _data["id"];
575
+ this.sessionId = _data["sessionId"];
576
+ this.timeStamp = _data["timeStamp"] ? new Date(_data["timeStamp"].toString()) : <any>undefined;
577
+ this.userId = _data["userId"];
578
+ this.sessionStartTime = _data["sessionStartTime"] ? new Date(_data["sessionStartTime"].toString()) : <any>undefined;
579
+ this.sessionEndTime = _data["sessionEndTime"] ? new Date(_data["sessionEndTime"].toString()) : <any>undefined;
580
+ this.userName = _data["userName"];
581
+ this.userEmail = _data["userEmail"];
582
+ this.question = _data["question"];
583
+ this.answer = _data["answer"];
584
+ this.messageType = _data["messageType"];
585
+ this.salesforceCaseId = _data["salesforceCaseId"];
586
+ this.guardFlag = _data["guardFlag"];
587
+ this.isGuardrailed = _data["isGuardrailed"];
588
+ this.botVersion = _data["botVersion"];
589
+ this.metadata = _data["metadata"];
590
+ this.feedback = _data["feedback"] ? Feedback.fromJS(_data["feedback"]) : <any>undefined;
591
+ this.sessionFeedback = _data["sessionFeedback"] ? Feedback.fromJS(_data["sessionFeedback"]) : <any>undefined;
592
+ }
593
+ }
594
+
595
+ static fromJS(data: any): ExportHistoryMessage {
596
+ data = typeof data === 'object' ? data : {};
597
+ let result = new ExportHistoryMessage();
598
+ result.init(data);
599
+ return result;
600
+ }
601
+
602
+ toJSON(data?: any) {
603
+ data = typeof data === 'object' ? data : {};
604
+ data["id"] = this.id;
605
+ data["sessionId"] = this.sessionId;
606
+ data["timeStamp"] = this.timeStamp ? this.timeStamp.toISOString() : <any>undefined;
607
+ data["userId"] = this.userId;
608
+ data["sessionStartTime"] = this.sessionStartTime ? this.sessionStartTime.toISOString() : <any>undefined;
609
+ data["sessionEndTime"] = this.sessionEndTime ? this.sessionEndTime.toISOString() : <any>undefined;
610
+ data["userName"] = this.userName;
611
+ data["userEmail"] = this.userEmail;
612
+ data["question"] = this.question;
613
+ data["answer"] = this.answer;
614
+ data["messageType"] = this.messageType;
615
+ data["salesforceCaseId"] = this.salesforceCaseId;
616
+ data["guardFlag"] = this.guardFlag;
617
+ data["isGuardrailed"] = this.isGuardrailed;
618
+ data["botVersion"] = this.botVersion;
619
+ data["metadata"] = this.metadata;
620
+ data["feedback"] = this.feedback ? this.feedback.toJSON() : <any>undefined;
621
+ data["sessionFeedback"] = this.sessionFeedback ? this.sessionFeedback.toJSON() : <any>undefined;
622
+ return data;
623
+ }
624
+ }
625
+
626
+ export interface IExportHistoryMessage {
627
+ /** Primary key. */
628
+ id?: number;
629
+ /** Session ID. Required in multi-turn conversations after the session is created. */
630
+ sessionId?: number | undefined;
631
+ timeStamp?: Date;
632
+ userId?: number;
633
+ sessionStartTime?: Date;
634
+ sessionEndTime?: Date | undefined;
635
+ userName?: string | undefined;
636
+ userEmail?: string | undefined;
637
+ question?: string | undefined;
638
+ answer?: string | undefined;
639
+ messageType?: string | undefined;
640
+ salesforceCaseId?: string | undefined;
641
+ guardFlag?: string | undefined;
642
+ isGuardrailed?: boolean;
643
+ botVersion?: string | undefined;
644
+ metadata?: any | undefined;
645
+ feedback?: Feedback;
646
+ sessionFeedback?: Feedback;
647
+ }
648
+
649
+ /** User feedback for chatbot interaction. */
398
650
  export class Feedback implements IFeedback {
651
+ /** A link to correct information according to user. */
399
652
  linkUrl?: string | undefined;
653
+ /** User typed input. */
400
654
  description?: string | undefined;
655
+ /** Session ID for session feedback. */
401
656
  sessionId?: number | undefined;
657
+ /** Message ID for message feedback. */
402
658
  messageId?: number | undefined;
659
+ /** Selected options. */
403
660
  options?: FeedbackOptions[] | undefined;
404
661
  rating?: FeedbackRatings;
405
662
 
@@ -450,11 +707,17 @@ export class Feedback implements IFeedback {
450
707
  }
451
708
  }
452
709
 
710
+ /** User feedback for chatbot interaction. */
453
711
  export interface IFeedback {
712
+ /** A link to correct information according to user. */
454
713
  linkUrl?: string | undefined;
714
+ /** User typed input. */
455
715
  description?: string | undefined;
716
+ /** Session ID for session feedback. */
456
717
  sessionId?: number | undefined;
718
+ /** Message ID for message feedback. */
457
719
  messageId?: number | undefined;
720
+ /** Selected options. */
458
721
  options?: FeedbackOptions[] | undefined;
459
722
  rating?: FeedbackRatings;
460
723
  }
@@ -512,10 +775,14 @@ export interface IFrontendModel {
512
775
  options: Option;
513
776
  }
514
777
 
778
+ /** A meaningful selectable option or a parent node for other options. */
515
779
  export class Option implements IOption {
780
+ /** Identifier key. */
516
781
  key!: string;
782
+ /** Display name. */
517
783
  displayName?: string | undefined;
518
784
  type!: OptionType;
785
+ /** Child options down the hierarchy. */
519
786
  subOptions?: Option[] | undefined;
520
787
 
521
788
  constructor(data?: IOption) {
@@ -561,10 +828,14 @@ export class Option implements IOption {
561
828
  }
562
829
  }
563
830
 
831
+ /** A meaningful selectable option or a parent node for other options. */
564
832
  export interface IOption {
833
+ /** Identifier key. */
565
834
  key: string;
835
+ /** Display name. */
566
836
  displayName?: string | undefined;
567
837
  type: OptionType;
838
+ /** Child options down the hierarchy. */
568
839
  subOptions?: Option[] | undefined;
569
840
  }
570
841
 
@@ -574,6 +845,7 @@ export enum OptionType {
574
845
  Selectable = 2,
575
846
  }
576
847
 
848
+ /** A scored link to Knowledge Base article. */
577
849
  export class ScoredUrl implements IScoredUrl {
578
850
  url?: string | undefined;
579
851
  score?: number;
@@ -612,14 +884,18 @@ export class ScoredUrl implements IScoredUrl {
612
884
  }
613
885
  }
614
886
 
887
+ /** A scored link to Knowledge Base article. */
615
888
  export interface IScoredUrl {
616
889
  url?: string | undefined;
617
890
  score?: number;
618
891
  title?: string | undefined;
619
892
  }
620
893
 
894
+ /** User-selected values from available options. Hierarchy of TitanChatbot.Host.API.Models.Selections must match hierarchy of TitanChatbot.Host.API.Models.Option. */
621
895
  export class Selections implements ISelections {
896
+ /** Selected values. */
622
897
  values?: string[] | undefined;
898
+ /** Child selections down the hierarchy. */
623
899
  subOptions?: { [key: string]: Selections; } | undefined;
624
900
 
625
901
  constructor(data?: ISelections) {
@@ -673,13 +949,19 @@ export class Selections implements ISelections {
673
949
  }
674
950
  }
675
951
 
952
+ /** User-selected values from available options. Hierarchy of TitanChatbot.Host.API.Models.Selections must match hierarchy of TitanChatbot.Host.API.Models.Option. */
676
953
  export interface ISelections {
954
+ /** Selected values. */
677
955
  values?: string[] | undefined;
956
+ /** Child selections down the hierarchy. */
678
957
  subOptions?: { [key: string]: Selections; } | undefined;
679
958
  }
680
959
 
960
+ /** Series of chatbot exchanges making a conversation. */
681
961
  export class Session implements ISession {
962
+ /** Primary key. */
682
963
  id?: number;
964
+ /** Arbitrary data to be stored in session. */
683
965
  data?: { [key: string]: string; } | undefined;
684
966
 
685
967
  constructor(data?: ISession) {
@@ -725,16 +1007,26 @@ export class Session implements ISession {
725
1007
  }
726
1008
  }
727
1009
 
1010
+ /** Series of chatbot exchanges making a conversation. */
728
1011
  export interface ISession {
1012
+ /** Primary key. */
729
1013
  id?: number;
1014
+ /** Arbitrary data to be stored in session. */
730
1015
  data?: { [key: string]: string; } | undefined;
731
1016
  }
732
1017
 
1018
+ /** User request message. */
733
1019
  export class UserMessage implements IUserMessage {
1020
+ /** Primary key. */
1021
+ id?: number;
1022
+ /** Session ID. Required in multi-turn conversations after the session is created. */
734
1023
  sessionId?: number | undefined;
1024
+ timeStamp?: Date;
1025
+ /** User question. */
735
1026
  question!: string;
736
1027
  experience!: Experience;
737
1028
  selections?: Selections;
1029
+ /** Additional context. */
738
1030
  context?: { [key: string]: any; } | undefined;
739
1031
 
740
1032
  constructor(data?: IUserMessage) {
@@ -748,7 +1040,9 @@ export class UserMessage implements IUserMessage {
748
1040
 
749
1041
  init(_data?: any) {
750
1042
  if (_data) {
1043
+ this.id = _data["id"];
751
1044
  this.sessionId = _data["sessionId"];
1045
+ this.timeStamp = _data["timeStamp"] ? new Date(_data["timeStamp"].toString()) : <any>undefined;
752
1046
  this.question = _data["question"];
753
1047
  this.experience = _data["experience"];
754
1048
  this.selections = _data["selections"] ? Selections.fromJS(_data["selections"]) : <any>undefined;
@@ -771,7 +1065,9 @@ export class UserMessage implements IUserMessage {
771
1065
 
772
1066
  toJSON(data?: any) {
773
1067
  data = typeof data === 'object' ? data : {};
1068
+ data["id"] = this.id;
774
1069
  data["sessionId"] = this.sessionId;
1070
+ data["timeStamp"] = this.timeStamp ? this.timeStamp.toISOString() : <any>undefined;
775
1071
  data["question"] = this.question;
776
1072
  data["experience"] = this.experience;
777
1073
  data["selections"] = this.selections ? this.selections.toJSON() : <any>undefined;
@@ -786,11 +1082,18 @@ export class UserMessage implements IUserMessage {
786
1082
  }
787
1083
  }
788
1084
 
1085
+ /** User request message. */
789
1086
  export interface IUserMessage {
1087
+ /** Primary key. */
1088
+ id?: number;
1089
+ /** Session ID. Required in multi-turn conversations after the session is created. */
790
1090
  sessionId?: number | undefined;
1091
+ timeStamp?: Date;
1092
+ /** User question. */
791
1093
  question: string;
792
1094
  experience: Experience;
793
1095
  selections?: Selections;
1096
+ /** Additional context. */
794
1097
  context?: { [key: string]: any; } | undefined;
795
1098
  }
796
1099
 
@@ -267,14 +267,20 @@ describe('[ChatbotUiBackendStore]', () => {
267
267
  });
268
268
 
269
269
  test('should start session', async () => {
270
+ const spyGetData = jest.spyOn(store, 'getSessionData').mockResolvedValue({
271
+ defaultData: 'defaultData',
272
+ });
270
273
  chatbotApi.postSession.mockResolvedValue(createSession(1));
271
274
  const { session } = await runChatUiEventListener(store.handleSessionStart, [
272
275
  { custom: 'data' },
273
276
  ]);
274
277
 
278
+ expect(spyGetData).toHaveBeenCalled();
275
279
  expect(session).toEqual(createSession(1));
276
280
  expect(chatbotApi.postSession).toHaveBeenCalledWith(
277
- { custom: 'data' },
281
+ {
282
+ data: { custom: 'data', defaultData: 'defaultData' },
283
+ },
278
284
  expect.any(AbortSignal)
279
285
  );
280
286
  });
@@ -290,7 +296,9 @@ describe('[ChatbotUiBackendStore]', () => {
290
296
  expect(r2.session).toEqual(createSession(1));
291
297
  expect(chatbotApi.postSession).toHaveBeenCalledTimes(1);
292
298
  expect(chatbotApi.postSession).toHaveBeenCalledWith(
293
- { custom: 'data' },
299
+ {
300
+ data: { custom: 'data' },
301
+ },
294
302
  expect.any(AbortSignal)
295
303
  );
296
304
  });
@@ -65,7 +65,7 @@ describe('[ChatbotUiStore]', () => {
65
65
  resolve(ModelsMocks.mockSession());
66
66
  }
67
67
  );
68
- const sessionData = ModelsMocks.mockSession({ id: 1 });
68
+ const sessionData = { customData: 'customData' };
69
69
  const session = await store.startSession(sessionData, true);
70
70
  expect(session).toBeDefined();
71
71
  expect(session?.id).toBe(1);
@@ -29,6 +29,7 @@ export interface IChatbotUiBackendStore extends IChatUiBackendStore {
29
29
  saveCurrentState: () => void;
30
30
  deleteFromSessionStorage: () => void;
31
31
  restoreChatSession: () => void;
32
+ getSessionData: () => Promise<Models.ISession['data'] | undefined>;
32
33
  restartTimers: () => void;
33
34
  }
34
35
 
@@ -123,7 +124,7 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
123
124
 
124
125
  handleSessionStart: ChatUiEventListener<{
125
126
  session?: Models.ISession;
126
- }> = async (resolve, _, sessionData?: Models.ISession, forceRecreate?: boolean) => {
127
+ }> = async (resolve, _, sessionData?: Models.ISession['data'], forceRecreate?: boolean) => {
127
128
  const session = await this.startSession(sessionData, forceRecreate);
128
129
  resolve({
129
130
  session,
@@ -206,6 +207,10 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
206
207
  });
207
208
  };
208
209
 
210
+ async getSessionData(): Promise<Models.ISession['data'] | undefined> {
211
+ return Promise.resolve(undefined);
212
+ }
213
+
209
214
  restoreChatSession() {}
210
215
 
211
216
  saveCurrentState() {}
@@ -325,7 +330,7 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
325
330
  this.session = session;
326
331
  }
327
332
 
328
- private async startSession(sessionData?: Models.ISession, forceRecreate = false) {
333
+ private async startSession(sessionData?: Models.ISession['data'], forceRecreate = false) {
329
334
  if (forceRecreate) {
330
335
  this.reset();
331
336
  this.sessionPromise = undefined;
@@ -334,11 +339,17 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
334
339
  return this.session;
335
340
  }
336
341
  if (!this.sessionPromise) {
337
- this.sessionPromise = this.api(
338
- 'postSession',
339
- ModelsUtils.createNewSessionModel(sessionData),
340
- this.abortController.signal
341
- );
342
+ this.sessionPromise = (async () => {
343
+ let data = await this.getSessionData();
344
+ if (sessionData) {
345
+ data = { ...data, ...sessionData };
346
+ }
347
+ return this.api(
348
+ 'postSession',
349
+ ModelsUtils.createNewSessionModel({ data }),
350
+ this.abortController.signal
351
+ );
352
+ })();
342
353
  const session = await this.sessionPromise;
343
354
  this.setSession(session);
344
355
  this.withSaveState(() => {
@@ -18,7 +18,7 @@ export interface IChatbotUiStore extends IChatUiStore<ChatbotCustomizations> {
18
18
  settings?: Models.IFrontendModel;
19
19
  setFilters: (filterOptions: Models.IFrontendModel) => void;
20
20
  startSession: (
21
- sessionData?: Models.ISession,
21
+ sessionData?: Models.ISession['data'],
22
22
  forceRecreate?: boolean
23
23
  ) => Promise<undefined | Models.Session>;
24
24
  sendSessionFeedback: (
@@ -64,7 +64,7 @@ export class ChatbotUiStore extends ChatUiStore<ChatbotCustomizations> implement
64
64
  }
65
65
 
66
66
  @action
67
- async startSession(sessionData?: Models.ISession, forceRecreate?: boolean) {
67
+ async startSession(sessionData?: Models.ISession['data'], forceRecreate?: boolean) {
68
68
  const result = await this.emitAsync<Models.Session>(
69
69
  ChatbotUiEvent.eventChatbotSessionStart,
70
70
  sessionData,