@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.45 → 0.0.1-alpha.48

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 (129) hide show
  1. package/{lib-esm → dist}/client/chat.client.d.ts +0 -0
  2. package/{lib-esm → dist}/client/contact-method.client.d.ts +0 -0
  3. package/{lib-esm → dist}/client/http.client.d.ts +0 -0
  4. package/{lib-esm → dist}/client/middleware.client.d.ts +0 -0
  5. package/dist/contact-method.js +102 -0
  6. package/dist/contact-method.js.map +1 -0
  7. package/{lib-esm → dist}/contract/custom-component/contact-method-item.d.ts +0 -0
  8. package/{lib-esm → dist}/contract/custom-component/contact-method-list.d.ts +0 -0
  9. package/{lib-esm → dist}/contract/custom-component/contact-method.d.ts +0 -0
  10. package/{lib-esm → dist}/contract/custom-component/entry-context.d.ts +0 -0
  11. package/{lib-esm → dist}/contract/enum/server-entry-type.enum.d.ts +0 -0
  12. package/{lib-esm → dist}/contract/model/conversation-api-model/list.model.d.ts +0 -0
  13. package/{lib-esm → dist}/contract/model/conversation-api-model/message.model.d.ts +0 -0
  14. package/{lib-esm → dist}/contract/model/http/action.model.d.ts +0 -0
  15. package/{lib-esm → dist}/contract/model/http/client-action.model.d.ts +0 -0
  16. package/{lib-esm → dist}/contract/model/http/client-envelope.model.d.ts +0 -0
  17. package/{lib-esm → dist}/contract/model/http/connect-options.model.d.ts +0 -0
  18. package/{lib-esm → dist}/contract/model/http/global-state.model.d.ts +0 -0
  19. package/{lib-esm → dist}/contract/model/http/http-client-options.model.d.ts +0 -0
  20. package/{lib-esm → dist}/contract/model/http/server-entry.model.d.ts +0 -0
  21. package/{lib-esm → dist}/contract/model/http/server-envelope.model.d.ts +0 -0
  22. package/{lib-esm → dist}/contract/model/middleware/aggregator-state.model.d.ts +0 -0
  23. package/{lib-esm → dist}/contract/model/shared/loose-object.model.d.ts +0 -0
  24. package/{lib-esm → dist}/helper/chat.helper.d.ts +0 -0
  25. package/{lib-esm → dist}/helper/http.helper.d.ts +0 -0
  26. package/{lib-esm → dist}/helper/middleware.helper.d.ts +0 -0
  27. package/{lib-esm → dist}/helper/store.helper.d.ts +0 -0
  28. package/{lib-esm → dist}/index.d.ts +0 -0
  29. package/dist/index.js +1131 -0
  30. package/dist/index.js.map +1 -0
  31. package/{lib-esm → dist}/interface/entry.interface.d.ts +0 -0
  32. package/{lib-esm → dist}/interface/middleware/paging.interface.d.ts +0 -0
  33. package/{lib-esm → dist}/interface/middleware/processor.interface.d.ts +0 -0
  34. package/{lib-esm → dist}/plugin.d.ts +0 -0
  35. package/{lib-esm → dist}/utils.d.ts +0 -0
  36. package/package.json +14 -15
  37. package/lib/client/chat.client.d.ts +0 -16
  38. package/lib/client/chat.client.js +0 -145
  39. package/lib/client/contact-method.client.d.ts +0 -34
  40. package/lib/client/contact-method.client.js +0 -337
  41. package/lib/client/http.client.d.ts +0 -26
  42. package/lib/client/http.client.js +0 -211
  43. package/lib/client/middleware.client.d.ts +0 -14
  44. package/lib/client/middleware.client.js +0 -125
  45. package/lib/contract/custom-component/contact-method-item.d.ts +0 -9
  46. package/lib/contract/custom-component/contact-method-item.js +0 -34
  47. package/lib/contract/custom-component/contact-method-list.d.ts +0 -7
  48. package/lib/contract/custom-component/contact-method-list.js +0 -13
  49. package/lib/contract/custom-component/contact-method.d.ts +0 -3
  50. package/lib/contract/custom-component/contact-method.js +0 -35
  51. package/lib/contract/custom-component/entry-context.d.ts +0 -5
  52. package/lib/contract/custom-component/entry-context.js +0 -4
  53. package/lib/contract/enum/server-entry-type.enum.d.ts +0 -7
  54. package/lib/contract/enum/server-entry-type.enum.js +0 -8
  55. package/lib/contract/model/conversation-api-model/list.model.d.ts +0 -5
  56. package/lib/contract/model/conversation-api-model/list.model.js +0 -1
  57. package/lib/contract/model/conversation-api-model/message.model.d.ts +0 -7
  58. package/lib/contract/model/conversation-api-model/message.model.js +0 -1
  59. package/lib/contract/model/http/action.model.d.ts +0 -3
  60. package/lib/contract/model/http/action.model.js +0 -1
  61. package/lib/contract/model/http/client-action.model.d.ts +0 -4
  62. package/lib/contract/model/http/client-action.model.js +0 -2
  63. package/lib/contract/model/http/client-envelope.model.d.ts +0 -9
  64. package/lib/contract/model/http/client-envelope.model.js +0 -1
  65. package/lib/contract/model/http/connect-options.model.d.ts +0 -5
  66. package/lib/contract/model/http/connect-options.model.js +0 -1
  67. package/lib/contract/model/http/global-state.model.d.ts +0 -8
  68. package/lib/contract/model/http/global-state.model.js +0 -1
  69. package/lib/contract/model/http/http-client-options.model.d.ts +0 -5
  70. package/lib/contract/model/http/http-client-options.model.js +0 -1
  71. package/lib/contract/model/http/server-entry.model.d.ts +0 -11
  72. package/lib/contract/model/http/server-entry.model.js +0 -1
  73. package/lib/contract/model/http/server-envelope.model.d.ts +0 -10
  74. package/lib/contract/model/http/server-envelope.model.js +0 -1
  75. package/lib/contract/model/middleware/aggregator-state.model.d.ts +0 -4
  76. package/lib/contract/model/middleware/aggregator-state.model.js +0 -2
  77. package/lib/contract/model/shared/loose-object.model.d.ts +0 -3
  78. package/lib/contract/model/shared/loose-object.model.js +0 -1
  79. package/lib/helper/chat.helper.d.ts +0 -8
  80. package/lib/helper/chat.helper.js +0 -18
  81. package/lib/helper/http.helper.d.ts +0 -13
  82. package/lib/helper/http.helper.js +0 -28
  83. package/lib/helper/middleware.helper.d.ts +0 -12
  84. package/lib/helper/middleware.helper.js +0 -68
  85. package/lib/helper/store.helper.d.ts +0 -23
  86. package/lib/helper/store.helper.js +0 -169
  87. package/lib/index.d.ts +0 -2
  88. package/lib/index.js +0 -2
  89. package/lib/interface/entry.interface.d.ts +0 -20
  90. package/lib/interface/entry.interface.js +0 -290
  91. package/lib/interface/middleware/paging.interface.d.ts +0 -4
  92. package/lib/interface/middleware/paging.interface.js +0 -53
  93. package/lib/interface/middleware/processor.interface.d.ts +0 -10
  94. package/lib/interface/middleware/processor.interface.js +0 -118
  95. package/lib/plugin.d.ts +0 -3
  96. package/lib/plugin.js +0 -154
  97. package/lib/utils.d.ts +0 -2
  98. package/lib/utils.js +0 -79
  99. package/lib-esm/client/chat.client.js +0 -145
  100. package/lib-esm/client/contact-method.client.js +0 -337
  101. package/lib-esm/client/http.client.js +0 -211
  102. package/lib-esm/client/middleware.client.js +0 -125
  103. package/lib-esm/contract/custom-component/contact-method-item.js +0 -34
  104. package/lib-esm/contract/custom-component/contact-method-list.js +0 -13
  105. package/lib-esm/contract/custom-component/contact-method.js +0 -35
  106. package/lib-esm/contract/custom-component/entry-context.js +0 -4
  107. package/lib-esm/contract/enum/server-entry-type.enum.js +0 -8
  108. package/lib-esm/contract/model/conversation-api-model/list.model.js +0 -1
  109. package/lib-esm/contract/model/conversation-api-model/message.model.js +0 -1
  110. package/lib-esm/contract/model/http/action.model.js +0 -1
  111. package/lib-esm/contract/model/http/client-action.model.js +0 -2
  112. package/lib-esm/contract/model/http/client-envelope.model.js +0 -1
  113. package/lib-esm/contract/model/http/connect-options.model.js +0 -1
  114. package/lib-esm/contract/model/http/global-state.model.js +0 -1
  115. package/lib-esm/contract/model/http/http-client-options.model.js +0 -1
  116. package/lib-esm/contract/model/http/server-entry.model.js +0 -1
  117. package/lib-esm/contract/model/http/server-envelope.model.js +0 -1
  118. package/lib-esm/contract/model/middleware/aggregator-state.model.js +0 -2
  119. package/lib-esm/contract/model/shared/loose-object.model.js +0 -1
  120. package/lib-esm/helper/chat.helper.js +0 -18
  121. package/lib-esm/helper/http.helper.js +0 -28
  122. package/lib-esm/helper/middleware.helper.js +0 -68
  123. package/lib-esm/helper/store.helper.js +0 -169
  124. package/lib-esm/index.js +0 -2
  125. package/lib-esm/interface/entry.interface.js +0 -290
  126. package/lib-esm/interface/middleware/paging.interface.js +0 -53
  127. package/lib-esm/interface/middleware/processor.interface.js +0 -118
  128. package/lib-esm/plugin.js +0 -154
  129. package/lib-esm/utils.js +0 -79
package/lib/plugin.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Container } from '@webprovisions/platform';
2
- declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
3
- export default KnowledgeBotProviderPlugin;
package/lib/plugin.js DELETED
@@ -1,154 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
38
- import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
39
- import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
40
- import { v4 } from 'uuid';
41
- import ChatClient from './client/chat.client';
42
- import { ContactMethodClient } from './client/contact-method.client';
43
- import { HttpClient } from './client/http.client';
44
- import MiddlewareClient from './client/middleware.client';
45
- import { getContactMethodEntry } from './utils';
46
- var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
47
- // ComponentNodeController type differs from component passed into registerProvider
48
- ) {
49
- var knowledgeBotEndpoint = component.properties().knowledgeBotEndpoint;
50
- if (knowledgeBotEndpoint) {
51
- return "".concat(knowledgeBotEndpoint, "/conversations");
52
- }
53
- var data = container.get('$settings').data;
54
- if (!data || !data.projection)
55
- throw new Error('Missing Knowledge Bot endpoint');
56
- return "".concat(data.projection, "/conversations");
57
- };
58
- var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
59
- var dataClient, platform, contactMethodPlatform;
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
62
- case 0: return [4 /*yield*/, DataClient.getInstance(container)];
63
- case 1:
64
- dataClient = _a.sent();
65
- return [4 /*yield*/, ConversationPlatform.getInstance(container)];
66
- case 2:
67
- platform = _a.sent();
68
- return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
69
- case 3:
70
- contactMethodPlatform = _a.sent();
71
- registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
72
- platform.registerProvider('chat.bot', function (conversation, component) {
73
- var endpoint = getKnowledgeBotEndpoint(container, component);
74
- var clientId = v4();
75
- var agent = conversation.createAgent({
76
- name: '',
77
- avatar: undefined,
78
- });
79
- // passes the user and the agent to the Chat Helper
80
- ChatClient.initialize(conversation.user, agent);
81
- // passes the conversation provider to the Contact Method Client
82
- ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
83
- // passes the container and the widget to the Middleware Store
84
- MiddlewareClient.initialize(container, container.get('$widget'));
85
- // executes to decide on what to do on first load
86
- var httpClient = new HttpClient(endpoint, clientId, container);
87
- var firstLoader = conversation.loading();
88
- httpClient.firstHit().then(firstLoader);
89
- component.actions.create('expand', function (input) {
90
- var cmClient = new ContactMethodClient(container);
91
- cmClient.expandContactMethod(input);
92
- });
93
- component.actions.create('evaluate', function (input) {
94
- var cmClient = new ContactMethodClient(container);
95
- cmClient.handleNewForm(input.form, input.form.id);
96
- });
97
- component.actions.create('validate', function (input) {
98
- var cmClient = new ContactMethodClient(container);
99
- cmClient.validate(input.form);
100
- });
101
- component.actions.create('submit', function (input) {
102
- var _a;
103
- if ((_a = input === null || input === void 0 ? void 0 : input.form) === null || _a === void 0 ? void 0 : _a.schema.id) {
104
- var contactMethodEntry = getContactMethodEntry(input.form.schema.id);
105
- }
106
- var cmClient = new ContactMethodClient(container);
107
- cmClient.validate(input.form);
108
- });
109
- component.actions.watch('conversation.user-typing', function (input, next) {
110
- return next(input);
111
- });
112
- component.actions.watch('conversation.user-submit', function (input, next) {
113
- var httpClient = new HttpClient(endpoint, clientId, container);
114
- var loader = conversation.loading();
115
- httpClient.handlePhrase(input.text).then(loader);
116
- return next(input);
117
- });
118
- component.actions.watch('conversation.form', function (input, next) {
119
- return next(input);
120
- });
121
- component.actions.watch('conversation.action', function (input, next) {
122
- var chatClient = new ChatClient(container);
123
- var cmClient = new ContactMethodClient(container);
124
- // if (input === 'contact' || input.split('/').length > 1) {
125
- // cmClient.handleContactMethod(input);
126
- // return next(input);
127
- // }
128
- var loader = conversation.loading();
129
- if (input.split('/').length > 1) {
130
- cmClient.handleContactMethod(input).then(loader);
131
- return next(input);
132
- }
133
- var httpClient = new HttpClient(endpoint, clientId, container);
134
- if (input == 'burger-clicked') {
135
- httpClient.handleCategories().then(loader);
136
- return next(input);
137
- }
138
- var middlewareClient = new MiddlewareClient(container);
139
- // this is an update check, as it requires
140
- // a lot different logic and no user message
141
- if (middlewareClient.checkForUpdate(input)) {
142
- httpClient.handleUpdate(input).then(loader);
143
- return next(input);
144
- }
145
- chatClient.printUserMessageAndStoreIt(input);
146
- httpClient.handleInput(input).then(loader);
147
- return next(input);
148
- });
149
- });
150
- return [2 /*return*/];
151
- }
152
- });
153
- }); };
154
- export default KnowledgeBotProviderPlugin;
package/lib/utils.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
2
- export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, validation?: any) => any;
package/lib/utils.js DELETED
@@ -1,79 +0,0 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
- import { FormBuilder } from '@telia-ace/widget-forms';
18
- import { StoreHelper } from './helper/store.helper';
19
- export var getContactMethodEntry = function (contactMethodId) {
20
- var entries = StoreHelper.getEntryStore();
21
- return entries.find(function (e) { return e.content.id === +contactMethodId; });
22
- };
23
- var convertLegacySymbol = function (symbol) {
24
- if (symbol) {
25
- var type = symbol.type, content = symbol.content;
26
- if (type && content) {
27
- return { type: type, content: content };
28
- }
29
- }
30
- };
31
- export var contactMethodFromLegacy = function (_a, validation) {
32
- var id = _a.id, title = _a.title, defaultIcon = _a.defaultIcon, _b = __read(_a.exits, 1), exit = _b[0], exitType = _a.exitType, confirmationText = _a.confirmationText, expandFormAutomatically = _a.expandFormAutomatically, form = _a.form, description = _a.description;
33
- var adapter = (exit || { Adapter: {} }).adapter;
34
- var _c = adapter.clientName, clientName = _c === void 0 ? '' : _c, _d = adapter.settings, adapterSettings = _d === void 0 ? {} : _d, _e = adapter.customClientName, customClientName = _e === void 0 ? '' : _e;
35
- var settings = {
36
- id: id.toString(),
37
- title: title,
38
- description: description,
39
- symbol: convertLegacySymbol(defaultIcon),
40
- clientName: clientName === 'custom.adapter' ? customClientName : clientName,
41
- expanded: true,
42
- inline: true,
43
- body: {},
44
- };
45
- if (clientName.indexOf('phone') > -1 || clientName.indexOf('freetext') > -1) {
46
- var displayTextBeforeClick = adapterSettings.displayTextBeforeClick, textBeforeClick = adapterSettings.textBeforeClick;
47
- if (displayTextBeforeClick === 'true') {
48
- settings.expanded = false;
49
- settings.title = textBeforeClick;
50
- }
51
- if (clientName.indexOf('phone.text') > -1) {
52
- settings.body.phoneNumber = adapterSettings.phoneNumber;
53
- }
54
- else {
55
- settings.body.freetext = adapterSettings.freetext;
56
- }
57
- }
58
- if (clientName.indexOf('chat.popup') > -1 ||
59
- clientName.indexOf('link') > -1 ||
60
- (clientName === 'custom.adapter' && exitType === 'custom')) {
61
- settings.body = adapterSettings;
62
- settings.body.confirmationFallback = confirmationText;
63
- }
64
- if (clientName.indexOf('ace') > -1) {
65
- settings.body = adapterSettings;
66
- }
67
- if (form && form.hasValueComponents) {
68
- if (validation) {
69
- settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form, validation).get();
70
- }
71
- else {
72
- settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form).get();
73
- }
74
- if (!expandFormAutomatically) {
75
- settings.expanded = settings.inline = false;
76
- }
77
- }
78
- return settings;
79
- };
@@ -1,145 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var __values = (this && this.__values) || function(o) {
38
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
- if (m) return m.call(o);
40
- if (o && typeof o.length === "number") return {
41
- next: function () {
42
- if (o && i >= o.length) o = void 0;
43
- return { value: o && o[i++], done: !o };
44
- }
45
- };
46
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
- };
48
- import { v4 as newGuid } from 'uuid';
49
- import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
50
- import { ChatHelper } from '../helper/chat.helper';
51
- import { StoreHelper } from '../helper/store.helper';
52
- import EntryInterface from '../interface/entry.interface';
53
- var ChatClient = /** @class */ (function () {
54
- function ChatClient(container) {
55
- this.entryInterface = new EntryInterface(container);
56
- }
57
- // Initialize from setting the user and agent for the Helper
58
- ChatClient.initialize = function (user, agent) {
59
- ChatHelper.setUser(user);
60
- ChatHelper.setAgent(agent);
61
- };
62
- // function for posting the messages
63
- ChatClient.prototype.processMessageArrayAndStoreIt = function (messages) {
64
- return __awaiter(this, void 0, void 0, function () {
65
- var _a, _b, message;
66
- var e_1, _c;
67
- return __generator(this, function (_d) {
68
- switch (_d.label) {
69
- case 0:
70
- try {
71
- for (_a = __values(messages.filter(function (o) { return o && o != null && !!o.message; })), _b = _a.next(); !_b.done; _b = _a.next()) {
72
- message = _b.value;
73
- if (message.isUser)
74
- this.postUserMessage(message);
75
- else
76
- this.postAgentMessage(message);
77
- }
78
- }
79
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
80
- finally {
81
- try {
82
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
83
- }
84
- finally { if (e_1) throw e_1.error; }
85
- }
86
- return [4 /*yield*/, StoreHelper.insertOrUpdateMessageArrayStore(messages)];
87
- case 1:
88
- _d.sent();
89
- return [2 /*return*/];
90
- }
91
- });
92
- });
93
- };
94
- // function for updating current messages
95
- ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
96
- var conversationEntry = undefined;
97
- messages.forEach(function (o) {
98
- var message = StoreHelper.getMessage(o.id);
99
- message === null || message === void 0 ? void 0 : message.conversationEntry.update(o.message);
100
- conversationEntry = message === null || message === void 0 ? void 0 : message.conversationEntry;
101
- });
102
- StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
103
- };
104
- // function for posting a message for the user actions, such as button clicks
105
- ChatClient.prototype.printUserMessageAndStoreIt = function (action) {
106
- if (action == 'next' || action == 'help')
107
- return;
108
- var entry = StoreHelper.getEntry(action);
109
- var message = {
110
- id: newGuid(),
111
- message: !entry ? action : this.getTitleFromEntry(entry, action),
112
- isUser: true,
113
- };
114
- this.postUserMessage(message);
115
- StoreHelper.insertOrUpdateMessageArrayStore([message]);
116
- };
117
- ChatClient.prototype.postUserMessage = function (message) {
118
- ChatHelper.getUser().print(message.message);
119
- };
120
- ChatClient.prototype.postAgentMessage = function (message) {
121
- message.conversationEntry = ChatHelper.getAgent().print(message.message);
122
- };
123
- ChatClient.prototype.getTitleFromEntry = function (entry, action) {
124
- var entryType = ServerEntryTypeEnum[entry.type];
125
- switch (entryType) {
126
- case ServerEntryTypeEnum.List:
127
- return this.getTitleFromList(entry, action);
128
- case ServerEntryTypeEnum.Text:
129
- return this.getTitleFromText(entry, action);
130
- default:
131
- return '';
132
- }
133
- };
134
- ChatClient.prototype.getTitleFromText = function (entry, action) {
135
- if (!!entry.content.items)
136
- return this.getTitleFromList(entry, action);
137
- else
138
- return entry.content.html;
139
- };
140
- ChatClient.prototype.getTitleFromList = function (entry, action) {
141
- return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
142
- };
143
- return ChatClient;
144
- }());
145
- export default ChatClient;