@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.2 → 0.0.1-alpha.5

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 (121) hide show
  1. package/lib/client/chat.client.d.ts +15 -0
  2. package/lib/client/chat.client.js +80 -0
  3. package/lib/client/contact-method.client.d.ts +22 -0
  4. package/lib/client/contact-method.client.js +276 -0
  5. package/lib/client/http.client.d.ts +22 -0
  6. package/lib/client/http.client.js +114 -0
  7. package/lib/client/middleware.client.d.ts +13 -0
  8. package/lib/client/middleware.client.js +60 -0
  9. package/lib/contract/custom-component/contact-method-item.d.ts +8 -0
  10. package/lib/contract/custom-component/contact-method-item.js +76 -0
  11. package/lib/contract/custom-component/contact-method-list.d.ts +7 -0
  12. package/lib/contract/custom-component/contact-method-list.js +41 -0
  13. package/lib/contract/custom-component/contact-method.d.ts +3 -0
  14. package/lib/contract/custom-component/contact-method.js +38 -0
  15. package/lib/contract/enum/server-entry-type.enum.d.ts +6 -0
  16. package/lib/contract/enum/server-entry-type.enum.js +10 -0
  17. package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -0
  18. package/lib/contract/model/conversation-api-model/list.model.js +2 -0
  19. package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -0
  20. package/lib/contract/model/conversation-api-model/message.model.js +2 -0
  21. package/lib/contract/model/http/action.model.d.ts +3 -0
  22. package/lib/contract/model/http/action.model.js +2 -0
  23. package/lib/contract/model/http/client-action.model.d.ts +4 -0
  24. package/lib/contract/model/http/client-action.model.js +3 -0
  25. package/lib/contract/model/http/client-envelope.model.d.ts +9 -0
  26. package/lib/contract/model/http/client-envelope.model.js +2 -0
  27. package/lib/contract/model/http/connect-options.model.d.ts +5 -0
  28. package/lib/contract/model/http/connect-options.model.js +2 -0
  29. package/lib/contract/model/http/global-state.model.d.ts +8 -0
  30. package/lib/contract/model/http/global-state.model.js +2 -0
  31. package/lib/contract/model/http/http-client-options.model.d.ts +5 -0
  32. package/lib/contract/model/http/http-client-options.model.js +2 -0
  33. package/lib/contract/model/http/server-entry.model.d.ts +11 -0
  34. package/lib/contract/model/http/server-entry.model.js +2 -0
  35. package/lib/contract/model/http/server-envelope.model.d.ts +10 -0
  36. package/lib/contract/model/http/server-envelope.model.js +2 -0
  37. package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -0
  38. package/lib/contract/model/middleware/aggregator-state.model.js +3 -0
  39. package/lib/contract/model/shared/loose-object.model.d.ts +3 -0
  40. package/lib/contract/model/shared/loose-object.model.js +2 -0
  41. package/lib/helper/chat.helper.d.ts +8 -0
  42. package/lib/helper/chat.helper.js +21 -0
  43. package/lib/helper/http.helper.d.ts +13 -0
  44. package/lib/helper/http.helper.js +33 -0
  45. package/lib/helper/middleware.helper.d.ts +12 -0
  46. package/lib/helper/middleware.helper.js +72 -0
  47. package/lib/helper/store.helper.d.ts +22 -0
  48. package/lib/helper/store.helper.js +80 -0
  49. package/lib/index.d.ts +2 -0
  50. package/lib/index.js +8 -0
  51. package/lib/interface/entry.interface.d.ts +17 -0
  52. package/lib/interface/entry.interface.js +138 -0
  53. package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
  54. package/lib/interface/middleware/contact-expanded.interface.js +50 -0
  55. package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
  56. package/lib/interface/middleware/legacy-contact-methods.interface.js +394 -0
  57. package/lib/interface/middleware/paging.interface.d.ts +4 -0
  58. package/lib/interface/middleware/paging.interface.js +55 -0
  59. package/lib/interface/middleware/processor.interface.d.ts +10 -0
  60. package/lib/interface/middleware/processor.interface.js +120 -0
  61. package/lib/plugin.d.ts +3 -0
  62. package/lib/plugin.js +172 -0
  63. package/lib-esm/client/chat.client.d.ts +15 -0
  64. package/lib-esm/client/chat.client.js +75 -0
  65. package/lib-esm/client/contact-method.client.d.ts +22 -0
  66. package/lib-esm/client/contact-method.client.js +270 -0
  67. package/lib-esm/client/http.client.d.ts +22 -0
  68. package/lib-esm/client/http.client.js +108 -0
  69. package/lib-esm/client/middleware.client.d.ts +13 -0
  70. package/lib-esm/client/middleware.client.js +55 -0
  71. package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -0
  72. package/lib-esm/contract/custom-component/contact-method-item.js +51 -0
  73. package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -0
  74. package/lib-esm/contract/custom-component/contact-method-list.js +13 -0
  75. package/lib-esm/contract/custom-component/contact-method.d.ts +3 -0
  76. package/lib-esm/contract/custom-component/contact-method.js +33 -0
  77. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +6 -0
  78. package/lib-esm/contract/enum/server-entry-type.enum.js +7 -0
  79. package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -0
  80. package/lib-esm/contract/model/conversation-api-model/list.model.js +1 -0
  81. package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -0
  82. package/lib-esm/contract/model/conversation-api-model/message.model.js +1 -0
  83. package/lib-esm/contract/model/http/action.model.d.ts +3 -0
  84. package/lib-esm/contract/model/http/action.model.js +1 -0
  85. package/lib-esm/contract/model/http/client-action.model.d.ts +4 -0
  86. package/lib-esm/contract/model/http/client-action.model.js +2 -0
  87. package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -0
  88. package/lib-esm/contract/model/http/client-envelope.model.js +1 -0
  89. package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -0
  90. package/lib-esm/contract/model/http/connect-options.model.js +1 -0
  91. package/lib-esm/contract/model/http/global-state.model.d.ts +8 -0
  92. package/lib-esm/contract/model/http/global-state.model.js +1 -0
  93. package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -0
  94. package/lib-esm/contract/model/http/http-client-options.model.js +1 -0
  95. package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -0
  96. package/lib-esm/contract/model/http/server-entry.model.js +1 -0
  97. package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -0
  98. package/lib-esm/contract/model/http/server-envelope.model.js +1 -0
  99. package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -0
  100. package/lib-esm/contract/model/middleware/aggregator-state.model.js +2 -0
  101. package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -0
  102. package/lib-esm/contract/model/shared/loose-object.model.js +1 -0
  103. package/lib-esm/helper/chat.helper.d.ts +8 -0
  104. package/lib-esm/helper/chat.helper.js +18 -0
  105. package/lib-esm/helper/http.helper.d.ts +13 -0
  106. package/lib-esm/helper/http.helper.js +30 -0
  107. package/lib-esm/helper/middleware.helper.d.ts +12 -0
  108. package/lib-esm/helper/middleware.helper.js +69 -0
  109. package/lib-esm/helper/store.helper.d.ts +22 -0
  110. package/lib-esm/helper/store.helper.js +77 -0
  111. package/lib-esm/index.d.ts +2 -0
  112. package/lib-esm/index.js +2 -0
  113. package/lib-esm/interface/entry.interface.d.ts +17 -0
  114. package/lib-esm/interface/entry.interface.js +136 -0
  115. package/lib-esm/interface/middleware/paging.interface.d.ts +4 -0
  116. package/lib-esm/interface/middleware/paging.interface.js +53 -0
  117. package/lib-esm/interface/middleware/processor.interface.d.ts +10 -0
  118. package/lib-esm/interface/middleware/processor.interface.js +118 -0
  119. package/lib-esm/plugin.d.ts +3 -0
  120. package/lib-esm/plugin.js +144 -0
  121. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ProcessorInterface = /** @class */ (function () {
4
+ function ProcessorInterface() {
5
+ }
6
+ ProcessorInterface.prototype.process = function (entries) {
7
+ var processedEntries = entries;
8
+ processedEntries = this.deletePaging(processedEntries);
9
+ processedEntries = this.delete(processedEntries);
10
+ processedEntries = this.merge(processedEntries);
11
+ processedEntries = this.moveLoader(processedEntries);
12
+ return processedEntries;
13
+ };
14
+ ProcessorInterface.prototype.processUpdate = function (entry, updateEntryArray) {
15
+ var _this = this;
16
+ updateEntryArray
17
+ .filter(function (t) { return t.type == 'List'; })
18
+ .forEach(function (o) {
19
+ var _a;
20
+ (_a = o.content) === null || _a === void 0 ? void 0 : _a.items.forEach(function (t) {
21
+ if (!(entry === null || entry === void 0 ? void 0 : entry.content.items.find(function (p) { return p.actionKey == t.actionKey; })))
22
+ entry === null || entry === void 0 ? void 0 : entry.content.items.push(t);
23
+ });
24
+ Object.keys(o.actions).forEach(function (t) {
25
+ _this.handleActionUpdateOrInsert(entry === null || entry === void 0 ? void 0 : entry.actions, t, o.actions);
26
+ });
27
+ });
28
+ //moves the show more and if it helped to the end if it is needed
29
+ var itemArray = entry === null || entry === void 0 ? void 0 : entry.content.items;
30
+ if (itemArray.find(function (o) { return o.actionKey == 'next'; })) {
31
+ itemArray.push(itemArray.splice(itemArray.indexOf(itemArray.find(function (o) { return o.actionKey == 'next'; })), 1)[0]);
32
+ }
33
+ if (itemArray.find(function (o) { return o.actionKey == 'help'; })) {
34
+ itemArray.push(itemArray.splice(itemArray.indexOf(itemArray.find(function (o) { return o.actionKey == 'help'; })), 1)[0]);
35
+ }
36
+ return entry ? [entry] : [];
37
+ };
38
+ ProcessorInterface.prototype.handleActionUpdateOrInsert = function (currentArray, actionKey, action) {
39
+ if (!!currentArray)
40
+ currentArray[actionKey] = action[actionKey];
41
+ };
42
+ ProcessorInterface.prototype.deletePaging = function (entries) {
43
+ return entries.filter(function (entry) {
44
+ var isEmptyPaging = entry.type === 'List' &&
45
+ entry.tags &&
46
+ entry.tags.indexOf('paging') > -1 &&
47
+ typeof entry.content === 'undefined';
48
+ return !isEmptyPaging;
49
+ });
50
+ };
51
+ ProcessorInterface.prototype.delete = function (entries) {
52
+ return entries.filter(function (entry) { return entry.content !== null; });
53
+ };
54
+ ProcessorInterface.prototype.merge = function (entries) {
55
+ var output = [];
56
+ var merge = function (source, target) {
57
+ if (target === void 0) { target = {}; }
58
+ var content = {};
59
+ if (source == null) {
60
+ return null;
61
+ }
62
+ if (target) {
63
+ Object.keys(target).forEach(function (key) {
64
+ content[key] = target[key];
65
+ });
66
+ }
67
+ Object.keys(source).forEach(function (key) {
68
+ if (key == 'items') {
69
+ if (!content[key])
70
+ content[key] = [];
71
+ content[key] = content[key].concat(source[key]);
72
+ }
73
+ else if (key == 'html')
74
+ content[key] = content[key] + source[key];
75
+ else
76
+ content[key] = source[key];
77
+ });
78
+ return content;
79
+ };
80
+ var mergeLocalState = function (source, target) {
81
+ if (source == null)
82
+ return null;
83
+ if (Object.keys(source.actions).length === 0)
84
+ return target.localState;
85
+ if (Object.keys(target.actions).length === 0)
86
+ return source.localState;
87
+ return target.localState;
88
+ };
89
+ entries.forEach(function (entry) {
90
+ if (entry.relation) {
91
+ var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
92
+ if (existingEntry) {
93
+ var existingIndex = output.indexOf(existingEntry);
94
+ existingEntry.localState = mergeLocalState(entry, existingEntry);
95
+ existingEntry.content = merge(entry.content, existingEntry.content);
96
+ existingEntry.actions = merge(entry.actions, existingEntry.actions);
97
+ output[existingIndex] = existingEntry;
98
+ }
99
+ }
100
+ else {
101
+ output.push(entry);
102
+ }
103
+ });
104
+ return output;
105
+ };
106
+ ProcessorInterface.prototype.moveLoader = function (entries) {
107
+ // Moves the loader component to last position in stream
108
+ var loaderEntry = entries.find(function (e) { return e.id === 'loader'; });
109
+ if (!loaderEntry) {
110
+ return entries;
111
+ }
112
+ var loaderIndex = entries.indexOf(loaderEntry);
113
+ if (loaderIndex > -1) {
114
+ entries.splice(entries.length - 1, 0, entries.splice(loaderIndex, 1)[0]);
115
+ }
116
+ return entries;
117
+ };
118
+ return ProcessorInterface;
119
+ }());
120
+ exports.default = ProcessorInterface;
@@ -0,0 +1,3 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ declare const ConversationPlugin: (container: Container) => Promise<void>;
3
+ export default ConversationPlugin;
package/lib/plugin.js ADDED
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __read = (this && this.__read) || function (o, n) {
62
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
63
+ if (!m) return o;
64
+ var i = m.call(o), r, ar = [], e;
65
+ try {
66
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
67
+ }
68
+ catch (error) { e = { error: error }; }
69
+ finally {
70
+ try {
71
+ if (r && !r.done && (m = i["return"])) m.call(i);
72
+ }
73
+ finally { if (e) throw e.error; }
74
+ }
75
+ return ar;
76
+ };
77
+ var __importDefault = (this && this.__importDefault) || function (mod) {
78
+ return (mod && mod.__esModule) ? mod : { "default": mod };
79
+ };
80
+ Object.defineProperty(exports, "__esModule", { value: true });
81
+ var knowledge_widget_adapters_1 = require("@telia-ace/knowledge-widget-adapters");
82
+ var knowledge_widget_core_1 = require("@telia-ace/knowledge-widget-core");
83
+ var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
84
+ var widget_conversation_1 = require("@telia-ace/widget-conversation");
85
+ var chat_client_1 = __importDefault(require("./client/chat.client"));
86
+ var contact_method_client_1 = require("./client/contact-method.client");
87
+ var http_client_1 = require("./client/http.client");
88
+ var middleware_client_1 = __importDefault(require("./client/middleware.client"));
89
+ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
91
+ return __generator(this, function (_b) {
92
+ switch (_b.label) {
93
+ case 0: return [4 /*yield*/, widget_conversation_1.ConversationPlatform.getInstance(container)];
94
+ case 1:
95
+ platform = _b.sent();
96
+ return [4 /*yield*/, knowledge_widget_adapters_1.ContactMethodPlatform.getInstance(container)];
97
+ case 2:
98
+ contactMethodPlatform = _b.sent();
99
+ return [4 /*yield*/, knowledge_widget_types_grid_1.DataClient.getInstance(container)];
100
+ case 3:
101
+ dataClient = _b.sent();
102
+ return [4 /*yield*/, knowledge_widget_core_1.ComponentPlatform.getInstance(container)];
103
+ case 4:
104
+ compPlatform = _b.sent();
105
+ _a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
106
+ endpoint = '';
107
+ setTimeout(function () {
108
+ endpoint = component.attributes.properties.knowledgeBotEndpoint;
109
+ });
110
+ platform.registerProvider('chat.bot', function (conversation, component) {
111
+ (0, widget_conversation_1.registerCustomMessageComponent)(container, 'ace-knowledge-contact-method', Promise.resolve().then(function () { return __importStar(require('./contract/custom-component/contact-method')); }));
112
+ var agent = conversation.createAgent({
113
+ name: 'John Doe',
114
+ avatar: 'https://www.site.com/avatar.jpg',
115
+ });
116
+ // pases the user and the agent to the Chat Helper
117
+ chat_client_1.default.initialize(conversation.user, agent);
118
+ // passes the conversation provider to the Contact Method Client
119
+ contact_method_client_1.ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
120
+ // passes the container and the widget to the Middleware Store
121
+ middleware_client_1.default.initialize(container, container.get('$widget'));
122
+ // executes to decide on what to do on first load
123
+ var httpClient = new http_client_1.HttpClient(endpoint);
124
+ httpClient.firstHit();
125
+ component.actions.create('evaluate', function (input) {
126
+ var cmClient = new contact_method_client_1.ContactMethodClient();
127
+ cmClient.handleNewForm(input.form, input.form.id);
128
+ });
129
+ component.actions.create('validate', function (input) {
130
+ var cmClient = new contact_method_client_1.ContactMethodClient();
131
+ cmClient.validate(input.form);
132
+ });
133
+ component.actions.create('submit', function (input) {
134
+ var cmClient = new contact_method_client_1.ContactMethodClient();
135
+ cmClient.validate(input.form);
136
+ });
137
+ component.actions.watch('conversation.user-typing', function (input, next) {
138
+ return next(input);
139
+ });
140
+ component.actions.watch('conversation.user-submit', function (input, next) {
141
+ var httpClient = new http_client_1.HttpClient(endpoint);
142
+ httpClient.handlePhrase(input.text);
143
+ return next(input);
144
+ });
145
+ component.actions.watch('conversation.form', function (input, next) {
146
+ return next(input);
147
+ });
148
+ component.actions.watch('conversation.action', function (input, next) {
149
+ var chatClient = new chat_client_1.default();
150
+ var cmClient = new contact_method_client_1.ContactMethodClient();
151
+ if (input === 'contact' || input.split('/').length > 1) {
152
+ cmClient.handleContactMethod(input);
153
+ return next(input);
154
+ }
155
+ var middlewareClient = new middleware_client_1.default();
156
+ // this is an update check, as it requires
157
+ // a lot different logic and no user message
158
+ if (middlewareClient.checkForUpdate(input)) {
159
+ middlewareClient.handleUpdate(input, endpoint);
160
+ return next(input);
161
+ }
162
+ chatClient.printUserMessageAndStoreIt(input);
163
+ var httpClient = new http_client_1.HttpClient(endpoint);
164
+ httpClient.handleInput(input);
165
+ return next(input);
166
+ });
167
+ });
168
+ return [2 /*return*/];
169
+ }
170
+ });
171
+ }); };
172
+ exports.default = ConversationPlugin;
@@ -0,0 +1,15 @@
1
+ import { Message } from '../contract/model/conversation-api-model/message.model';
2
+ import EntryInterface from '../interface/entry.interface';
3
+ export default class ChatClient {
4
+ entryInterface: EntryInterface;
5
+ constructor();
6
+ static initialize(user: any, agent: any): void;
7
+ processMessageArrayAndStoreIt(messages: Message[]): void;
8
+ updateMessageArrayAndStoreIt(messages: Message[]): void;
9
+ printUserMessageAndStoreIt(action: string): void;
10
+ private postUserMessage;
11
+ private postAgentMessage;
12
+ private getTitleFromEntry;
13
+ private getTitleFromText;
14
+ private getTitleFromList;
15
+ }
@@ -0,0 +1,75 @@
1
+ import { v4 as newGuid } from 'uuid';
2
+ import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
3
+ import { ChatHelper } from '../helper/chat.helper';
4
+ import { StoreHelper } from '../helper/store.helper';
5
+ import EntryInterface from '../interface/entry.interface';
6
+ var ChatClient = /** @class */ (function () {
7
+ function ChatClient() {
8
+ this.entryInterface = new EntryInterface();
9
+ }
10
+ ChatClient.initialize = function (user, agent) {
11
+ ChatHelper.setUser(user);
12
+ ChatHelper.setAgent(agent);
13
+ };
14
+ ChatClient.prototype.processMessageArrayAndStoreIt = function (messages) {
15
+ var _this = this;
16
+ messages
17
+ .filter(function (o) { return o && o != null; })
18
+ .forEach(function (o) {
19
+ if (o.isUser)
20
+ _this.postUserMessage(o);
21
+ else
22
+ _this.postAgentMessage(o);
23
+ });
24
+ StoreHelper.insertOrUpdateMessageArrayStore(messages);
25
+ };
26
+ ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
27
+ var conversationEntry = undefined;
28
+ messages.forEach(function (o) {
29
+ var message = StoreHelper.getMessage(o.id);
30
+ message === null || message === void 0 ? void 0 : message.conversationEntry.update(o.message);
31
+ conversationEntry = message === null || message === void 0 ? void 0 : message.conversationEntry;
32
+ });
33
+ StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
34
+ };
35
+ ChatClient.prototype.printUserMessageAndStoreIt = function (action) {
36
+ if (action == 'next' || action == 'help')
37
+ return;
38
+ var entry = StoreHelper.getEntry(action);
39
+ var message = {
40
+ id: newGuid(),
41
+ message: !entry ? action : this.getTitleFromEntry(entry, action),
42
+ isUser: true,
43
+ };
44
+ this.postUserMessage(message);
45
+ StoreHelper.insertOrUpdateMessageArrayStore([message]);
46
+ };
47
+ ChatClient.prototype.postUserMessage = function (message) {
48
+ ChatHelper.getUser().print(message.message);
49
+ };
50
+ ChatClient.prototype.postAgentMessage = function (message) {
51
+ message.conversationEntry = ChatHelper.getAgent().print(message.message);
52
+ };
53
+ ChatClient.prototype.getTitleFromEntry = function (entry, action) {
54
+ var entryType = ServerEntryTypeEnum[entry.type];
55
+ switch (entryType) {
56
+ case ServerEntryTypeEnum.List:
57
+ return this.getTitleFromList(entry, action);
58
+ case ServerEntryTypeEnum.Text:
59
+ return this.getTitleFromText(entry, action);
60
+ default:
61
+ return '';
62
+ }
63
+ };
64
+ ChatClient.prototype.getTitleFromText = function (entry, action) {
65
+ if (!!entry.content.items)
66
+ return this.getTitleFromList(entry, action);
67
+ else
68
+ return entry.content.html;
69
+ };
70
+ ChatClient.prototype.getTitleFromList = function (entry, action) {
71
+ return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
72
+ };
73
+ return ChatClient;
74
+ }());
75
+ export default ChatClient;
@@ -0,0 +1,22 @@
1
+ import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
2
+ import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
3
+ export declare class ContactMethodClient {
4
+ private static dataClient;
5
+ private static contactMethodPlatform;
6
+ private static contactMessageEntryArray;
7
+ private static agent;
8
+ private chatClient;
9
+ static initialize(dataClient: DataClient, contactMethodPlatform: ContactMethodPlatform, agent: any): void;
10
+ handleNewForm: (errors: any, entry: any) => Promise<void>;
11
+ handleContactMethod: (input?: string) => Promise<void>;
12
+ validate(form: any): void;
13
+ private handleContactCategoryList;
14
+ private handleForm;
15
+ private handleContactMethodList;
16
+ private handleSingleContactMethod;
17
+ private submit;
18
+ private removeForm;
19
+ private printMessage;
20
+ private loadContactMethods;
21
+ private updateForm;
22
+ }