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

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 +115 -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 +139 -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 +169 -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 +109 -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 +137 -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 +141 -0
  121. package/package.json +1 -1
@@ -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,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var uuid_1 = require("uuid");
7
+ var server_entry_type_enum_1 = require("../contract/enum/server-entry-type.enum");
8
+ var chat_helper_1 = require("../helper/chat.helper");
9
+ var store_helper_1 = require("../helper/store.helper");
10
+ var entry_interface_1 = __importDefault(require("../interface/entry.interface"));
11
+ var ChatClient = /** @class */ (function () {
12
+ function ChatClient() {
13
+ this.entryInterface = new entry_interface_1.default();
14
+ }
15
+ ChatClient.initialize = function (user, agent) {
16
+ chat_helper_1.ChatHelper.setUser(user);
17
+ chat_helper_1.ChatHelper.setAgent(agent);
18
+ };
19
+ ChatClient.prototype.processMessageArrayAndStoreIt = function (messages) {
20
+ var _this = this;
21
+ messages
22
+ .filter(function (o) { return o && o != null; })
23
+ .forEach(function (o) {
24
+ if (o.isUser)
25
+ _this.postUserMessage(o);
26
+ else
27
+ _this.postAgentMessage(o);
28
+ });
29
+ store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore(messages);
30
+ };
31
+ ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
32
+ var conversationEntry = undefined;
33
+ messages.forEach(function (o) {
34
+ var message = store_helper_1.StoreHelper.getMessage(o.id);
35
+ message === null || message === void 0 ? void 0 : message.conversationEntry.update(o.message);
36
+ conversationEntry = message === null || message === void 0 ? void 0 : message.conversationEntry;
37
+ });
38
+ store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
39
+ };
40
+ ChatClient.prototype.printUserMessageAndStoreIt = function (action) {
41
+ if (action == 'next' || action == 'help')
42
+ return;
43
+ var entry = store_helper_1.StoreHelper.getEntry(action);
44
+ var message = {
45
+ id: (0, uuid_1.v4)(),
46
+ message: !entry ? action : this.getTitleFromEntry(entry, action),
47
+ isUser: true,
48
+ };
49
+ this.postUserMessage(message);
50
+ store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([message]);
51
+ };
52
+ ChatClient.prototype.postUserMessage = function (message) {
53
+ chat_helper_1.ChatHelper.getUser().print(message.message);
54
+ };
55
+ ChatClient.prototype.postAgentMessage = function (message) {
56
+ message.conversationEntry = chat_helper_1.ChatHelper.getAgent().print(message.message);
57
+ };
58
+ ChatClient.prototype.getTitleFromEntry = function (entry, action) {
59
+ var entryType = server_entry_type_enum_1.ServerEntryTypeEnum[entry.type];
60
+ switch (entryType) {
61
+ case server_entry_type_enum_1.ServerEntryTypeEnum.List:
62
+ return this.getTitleFromList(entry, action);
63
+ case server_entry_type_enum_1.ServerEntryTypeEnum.Text:
64
+ return this.getTitleFromText(entry, action);
65
+ default:
66
+ return '';
67
+ }
68
+ };
69
+ ChatClient.prototype.getTitleFromText = function (entry, action) {
70
+ if (!!entry.content.items)
71
+ return this.getTitleFromList(entry, action);
72
+ else
73
+ return entry.content.html;
74
+ };
75
+ ChatClient.prototype.getTitleFromList = function (entry, action) {
76
+ return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
77
+ };
78
+ return ChatClient;
79
+ }());
80
+ exports.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
+ }
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.ContactMethodClient = void 0;
54
+ var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
55
+ var widget_forms_1 = require("@telia-ace/widget-forms");
56
+ var uuid_1 = require("uuid");
57
+ var store_helper_1 = require("../helper/store.helper");
58
+ var chat_client_1 = __importDefault(require("./chat.client"));
59
+ var ContactMethodClient = /** @class */ (function () {
60
+ function ContactMethodClient() {
61
+ var _this = this;
62
+ this.chatClient = new chat_client_1.default();
63
+ this.handleNewForm = function (errors, entry) { return __awaiter(_this, void 0, void 0, function () {
64
+ return __generator(this, function (_a) {
65
+ this.updateForm(entry.contactMethods, {
66
+ submit: 'Submit',
67
+ errors: errors,
68
+ });
69
+ entry.entry.update({
70
+ contactMethods: entry.contactMethods,
71
+ type: 'ace-knowledge-contact-method',
72
+ noPadding: true,
73
+ });
74
+ return [2 /*return*/];
75
+ });
76
+ }); };
77
+ this.handleContactMethod = function (input) {
78
+ if (input === void 0) { input = ''; }
79
+ return __awaiter(_this, void 0, void 0, function () {
80
+ var contactMethods;
81
+ var _a;
82
+ return __generator(this, function (_b) {
83
+ switch (_b.label) {
84
+ case 0:
85
+ if (!(input == 'contact')) return [3 /*break*/, 2];
86
+ return [4 /*yield*/, this.handleContactCategoryList(input)];
87
+ case 1:
88
+ _b.sent();
89
+ return [3 /*break*/, 4];
90
+ case 2: return [4 /*yield*/, this.loadContactMethods(input.split('/')[1], // type
91
+ input.split('/')[0] // id
92
+ )];
93
+ case 3:
94
+ contactMethods = _b.sent();
95
+ if (!!((_a = contactMethods.body) === null || _a === void 0 ? void 0 : _a.form)) {
96
+ this.handleForm(input, contactMethods);
97
+ }
98
+ else if (!contactMethods.expanded && contactMethods.inline) {
99
+ this.handleSingleContactMethod(contactMethods);
100
+ }
101
+ else if (!!contactMethods.contactMethods) {
102
+ this.handleContactMethodList(input, contactMethods);
103
+ }
104
+ _b.label = 4;
105
+ case 4: return [2 /*return*/];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ this.handleContactCategoryList = function (input) { return __awaiter(_this, void 0, void 0, function () {
111
+ var newGuid, type, contactMethods;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ newGuid = (0, uuid_1.v4)();
116
+ type = knowledge_widget_types_grid_1.DataType.ContactMethodCategories;
117
+ return [4 /*yield*/, this.loadContactMethods(type)];
118
+ case 1:
119
+ contactMethods = _a.sent();
120
+ this.chatClient.printUserMessageAndStoreIt(input);
121
+ this.printMessage(newGuid, contactMethods);
122
+ return [2 /*return*/];
123
+ }
124
+ });
125
+ }); };
126
+ this.updateForm = function (contactMethod, properties) {
127
+ var _a;
128
+ if ((_a = contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) === null || _a === void 0 ? void 0 : _a.form) {
129
+ var body = contactMethod.body;
130
+ var builder = new widget_forms_1.FormBuilder(body.form);
131
+ if (!body.form.layout || !body.form.layout.submit) {
132
+ builder.createComponent((0, widget_forms_1.submitButton)(properties.submit, 'submit'));
133
+ }
134
+ if (properties.errors) {
135
+ builder.setValidationErrors(properties.errors);
136
+ }
137
+ return __assign(__assign({}, body), { form: builder.get() });
138
+ }
139
+ return (contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) || {};
140
+ };
141
+ }
142
+ ContactMethodClient.initialize = function (dataClient, contactMethodPlatform, agent) {
143
+ this.dataClient = dataClient;
144
+ this.contactMethodPlatform = contactMethodPlatform;
145
+ this.agent = agent;
146
+ };
147
+ ContactMethodClient.prototype.validate = function (form) {
148
+ var _this = this;
149
+ var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == form.schema.id; });
150
+ ContactMethodClient.contactMethodPlatform.validate(entry.contactMethods).then(function (result) {
151
+ _this.handleNewForm(result.errors, entry);
152
+ if (result.valid) {
153
+ _this.submit(entry);
154
+ _this.removeForm(entry);
155
+ }
156
+ });
157
+ };
158
+ ContactMethodClient.prototype.handleForm = function (input, contactMethods) {
159
+ var title = input.split('/')[2];
160
+ contactMethods.expanded = true;
161
+ this.updateForm(contactMethods, {
162
+ submit: 'Submit',
163
+ errors: undefined,
164
+ });
165
+ this.printMessage(contactMethods.id, contactMethods, title);
166
+ };
167
+ ContactMethodClient.prototype.handleContactMethodList = function (input, contactMethods) {
168
+ var title = input.split('/')[2];
169
+ var newGuid = (0, uuid_1.v4)();
170
+ this.printMessage(newGuid, contactMethods, title);
171
+ };
172
+ ContactMethodClient.prototype.handleSingleContactMethod = function (contactMethods) {
173
+ var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) {
174
+ return o.contactMethods.contactMethods.find(function (t) { return t.id == contactMethods.id; });
175
+ });
176
+ var curCM = entry.contactMethods.contactMethods.find(function (t) { return t.id == contactMethods.id; });
177
+ curCM.expanded = true;
178
+ var message = {
179
+ contactMethods: entry.contactMethods,
180
+ type: 'ace-knowledge-contact-method',
181
+ noPadding: true,
182
+ };
183
+ store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([
184
+ {
185
+ id: entry.id,
186
+ message: message,
187
+ isUser: false,
188
+ },
189
+ ]);
190
+ entry.entry.update(message);
191
+ };
192
+ ContactMethodClient.prototype.submit = function (entry) {
193
+ ContactMethodClient.contactMethodPlatform.submit(entry.contactMethods).then(function (result) {
194
+ if (!!result)
195
+ ContactMethodClient.agent.print(result);
196
+ });
197
+ };
198
+ ContactMethodClient.prototype.removeForm = function (entry) {
199
+ entry.entry.remove();
200
+ ContactMethodClient.contactMessageEntryArray.splice(ContactMethodClient.contactMessageEntryArray.indexOf(entry), 1);
201
+ };
202
+ ContactMethodClient.prototype.printMessage = function (newGuid, contactMethods, title) {
203
+ if (title === void 0) { title = undefined; }
204
+ if (ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == contactMethods.id; })) {
205
+ var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == contactMethods.id; });
206
+ var message = {
207
+ contactMethods: contactMethods,
208
+ type: 'ace-knowledge-contact-method',
209
+ noPadding: true,
210
+ };
211
+ entry.entry.update(message);
212
+ store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([
213
+ {
214
+ id: entry.guid,
215
+ message: message,
216
+ isUser: false,
217
+ },
218
+ ]);
219
+ }
220
+ else {
221
+ if (title)
222
+ this.chatClient.printUserMessageAndStoreIt(title);
223
+ var message = {
224
+ contactMethods: contactMethods,
225
+ type: 'ace-knowledge-contact-method',
226
+ noPadding: true,
227
+ };
228
+ var entry = ContactMethodClient.agent.print(message);
229
+ store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([
230
+ {
231
+ id: newGuid,
232
+ message: message,
233
+ isUser: false,
234
+ },
235
+ ]);
236
+ ContactMethodClient.contactMessageEntryArray.push({
237
+ id: newGuid,
238
+ contactMethods: contactMethods,
239
+ entry: entry,
240
+ });
241
+ }
242
+ };
243
+ ContactMethodClient.prototype.loadContactMethods = function (dataType, id) {
244
+ if (id === void 0) { id = undefined; }
245
+ switch (dataType) {
246
+ case knowledge_widget_types_grid_1.DataType.ContactMethodCategories: {
247
+ return ContactMethodClient.dataClient
248
+ .fetch(knowledge_widget_types_grid_1.DataType.ContactMethods, { contactMethodCategoryId: id })
249
+ .then(function (contactMethods) { return contactMethods; });
250
+ }
251
+ case knowledge_widget_types_grid_1.DataType.ContactMethods: {
252
+ if (!!id) {
253
+ return ContactMethodClient.dataClient
254
+ .fetch(knowledge_widget_types_grid_1.DataType.ContactMethod, { contactMethodId: id })
255
+ .then(function (contactMethods) { return contactMethods; });
256
+ }
257
+ else {
258
+ return ContactMethodClient.dataClient
259
+ .fetch(knowledge_widget_types_grid_1.DataType.ContactMethods, {})
260
+ .then(function (contactMethods) { return contactMethods; });
261
+ }
262
+ }
263
+ case knowledge_widget_types_grid_1.DataType.ContactMethodCategories: {
264
+ return ContactMethodClient.dataClient
265
+ .fetch(knowledge_widget_types_grid_1.DataType.ContactMethods, { contactMethodCategoryId: id })
266
+ .then(function (contactMethods) { return contactMethods; });
267
+ }
268
+ default: {
269
+ return Promise.resolve(undefined);
270
+ }
271
+ }
272
+ };
273
+ ContactMethodClient.contactMessageEntryArray = [];
274
+ return ContactMethodClient;
275
+ }());
276
+ exports.ContactMethodClient = ContactMethodClient;
@@ -0,0 +1,22 @@
1
+ import { ServerEntry } from '../contract/model/http/server-entry.model';
2
+ export declare class HttpClient {
3
+ private endpointUrl;
4
+ private clientId;
5
+ private projectionPath;
6
+ private apiEndpoint;
7
+ private options;
8
+ private middlewareClient;
9
+ private chatClient;
10
+ constructor(endpoint: string);
11
+ firstHit(): void;
12
+ handleUpdate(action: string): Promise<ServerEntry[]>;
13
+ handleInput(action: string): void;
14
+ handlePhrase(phrase: string): void;
15
+ private postAndHandleTheData;
16
+ private postAndReturnTheData;
17
+ private getHttpOptions;
18
+ private constructInputEnvelope;
19
+ private constructPhraseEnvelope;
20
+ private constructFirstHitEnvelope;
21
+ private handleResponseData;
22
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HttpClient = void 0;
7
+ var http_helper_1 = require("../helper/http.helper");
8
+ var middleware_helper_1 = require("../helper/middleware.helper");
9
+ var store_helper_1 = require("../helper/store.helper");
10
+ var chat_client_1 = __importDefault(require("./chat.client"));
11
+ var middleware_client_1 = __importDefault(require("./middleware.client"));
12
+ var HttpClient = /** @class */ (function () {
13
+ function HttpClient(endpoint) {
14
+ this.options = {
15
+ credentials: http_helper_1.HttpHelper.getCredentials(),
16
+ clientId: '84d96a63-b8ba-33ec-22d5-515255f866f8',
17
+ };
18
+ console.log(endpoint);
19
+ this.apiEndpoint = endpoint;
20
+ this.projectionPath = window.location.href;
21
+ this.endpointUrl = http_helper_1.HttpHelper.combineUrl(this.projectionPath, 'conversations');
22
+ this.clientId = this.options.clientId;
23
+ this.middlewareClient = new middleware_client_1.default();
24
+ this.chatClient = new chat_client_1.default();
25
+ }
26
+ HttpClient.prototype.firstHit = function () {
27
+ var _this = this;
28
+ // On first hit if there are entries stored in the storage, use them
29
+ // Otherwise start a new session
30
+ middleware_helper_1.MiddlewareHelper.getEntrySessionStorage().then(function (o) {
31
+ if (o && o.length > 0)
32
+ _this.chatClient.processMessageArrayAndStoreIt(o);
33
+ else {
34
+ var envelope = _this.constructFirstHitEnvelope();
35
+ _this.postAndHandleTheData(envelope);
36
+ }
37
+ });
38
+ };
39
+ // for updates, such as paging changes
40
+ HttpClient.prototype.handleUpdate = function (action) {
41
+ var envelope = this.constructInputEnvelope(action);
42
+ return this.postAndReturnTheData(envelope, action).then(function (o) {
43
+ return o.entries;
44
+ });
45
+ };
46
+ // for action clicks
47
+ HttpClient.prototype.handleInput = function (action) {
48
+ var envelope = this.constructInputEnvelope(action);
49
+ this.postAndHandleTheData(envelope, action);
50
+ };
51
+ // for text entries by user
52
+ HttpClient.prototype.handlePhrase = function (phrase) {
53
+ var envelope = this.constructPhraseEnvelope(phrase);
54
+ this.postAndHandleTheData(envelope);
55
+ };
56
+ HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
57
+ var _this = this;
58
+ return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
59
+ .then(function (response) {
60
+ if (response.ok)
61
+ return response.json();
62
+ throw response;
63
+ })
64
+ .then(function (data) {
65
+ _this.handleResponseData(data, action);
66
+ })
67
+ .catch(function (err) { return console.log(err); });
68
+ };
69
+ HttpClient.prototype.postAndReturnTheData = function (envelope, action) {
70
+ return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
71
+ .then(function (response) {
72
+ if (response.ok)
73
+ return response.json();
74
+ throw response;
75
+ })
76
+ .then(function (data) {
77
+ return data;
78
+ })
79
+ .catch(function (err) { return console.log(err); });
80
+ };
81
+ HttpClient.prototype.getHttpOptions = function (envelope) {
82
+ return Object.assign({}, http_helper_1.HttpHelper.fetchOptions, {
83
+ body: JSON.stringify(envelope),
84
+ credentials: this.options.credentials,
85
+ });
86
+ };
87
+ HttpClient.prototype.constructInputEnvelope = function (action) {
88
+ return {
89
+ action: store_helper_1.StoreHelper.getAction(action),
90
+ localState: store_helper_1.StoreHelper.getLocalState(action),
91
+ globalState: store_helper_1.StoreHelper.getGlobalState(),
92
+ clientId: this.clientId,
93
+ };
94
+ };
95
+ HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
96
+ return {
97
+ command: { phrase: phrase },
98
+ globalState: store_helper_1.StoreHelper.getGlobalState(),
99
+ clientId: this.clientId,
100
+ };
101
+ };
102
+ HttpClient.prototype.constructFirstHitEnvelope = function () {
103
+ return {
104
+ command: { site: this.endpointUrl },
105
+ clientId: this.clientId,
106
+ globalState: {},
107
+ };
108
+ };
109
+ HttpClient.prototype.handleResponseData = function (envelope, action) {
110
+ store_helper_1.StoreHelper.setGlobalState(envelope.globalState);
111
+ this.middlewareClient.handleEntries(envelope.entries, action);
112
+ };
113
+ return HttpClient;
114
+ }());
115
+ exports.HttpClient = HttpClient;
@@ -0,0 +1,13 @@
1
+ import { ServerEntry } from '../contract/model/http/server-entry.model';
2
+ export default class MiddlewareClient {
3
+ private paging;
4
+ private processor;
5
+ private entryInterface;
6
+ private chatClient;
7
+ constructor();
8
+ static initialize(container: any, widget: any): void;
9
+ handleEntries(entries: ServerEntry[], action?: string): void;
10
+ handleUpdate(input: string, endpoint: string): void;
11
+ checkForUpdate(input: string): boolean;
12
+ private executeMiddlewares;
13
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var middleware_helper_1 = require("../helper/middleware.helper");
7
+ var store_helper_1 = require("../helper/store.helper");
8
+ var entry_interface_1 = __importDefault(require("../interface/entry.interface"));
9
+ // import ContactExpandedInterface from "../interface/middleware/contact-expanded.interface";
10
+ // import ContactInterface from "../interface/middleware/legacy-contact-methods.interface";
11
+ var paging_interface_1 = __importDefault(require("../interface/middleware/paging.interface"));
12
+ var processor_interface_1 = __importDefault(require("../interface/middleware/processor.interface"));
13
+ var chat_client_1 = __importDefault(require("./chat.client"));
14
+ var http_client_1 = require("./http.client");
15
+ var MiddlewareClient = /** @class */ (function () {
16
+ function MiddlewareClient() {
17
+ // this.contactExpanded = new ContactExpandedInterface();
18
+ // this.legacyContact = new ContactInterface();
19
+ this.paging = new paging_interface_1.default();
20
+ this.processor = new processor_interface_1.default();
21
+ this.entryInterface = new entry_interface_1.default();
22
+ this.chatClient = new chat_client_1.default();
23
+ }
24
+ MiddlewareClient.initialize = function (container, widget) {
25
+ middleware_helper_1.MiddlewareHelper.setContainer(container);
26
+ middleware_helper_1.MiddlewareHelper.setWidget(widget);
27
+ };
28
+ // called on all standart scenarios like actions and user messages
29
+ MiddlewareClient.prototype.handleEntries = function (entries, action) {
30
+ var o = this.executeMiddlewares(entries, false, action);
31
+ var messageArray = this.entryInterface.transformArray(o);
32
+ this.chatClient.processMessageArrayAndStoreIt(messageArray);
33
+ };
34
+ // called on situations such as paging changes
35
+ // when no new entries will be printed
36
+ MiddlewareClient.prototype.handleUpdate = function (input, endpoint) {
37
+ var _this = this;
38
+ var httpClient = new http_client_1.HttpClient(endpoint);
39
+ httpClient.handleUpdate(input).then(function (entries) {
40
+ var o = _this.executeMiddlewares(entries, true, input);
41
+ var messageArray = _this.entryInterface.transformArray(o);
42
+ _this.chatClient.updateMessageArrayAndStoreIt(messageArray);
43
+ });
44
+ };
45
+ // checks whether the action was of an update type
46
+ MiddlewareClient.prototype.checkForUpdate = function (input) {
47
+ return input === 'next';
48
+ };
49
+ MiddlewareClient.prototype.executeMiddlewares = function (entries, isUpdate, action) {
50
+ if (isUpdate && action)
51
+ entries = this.processor.processUpdate(store_helper_1.StoreHelper.getEntry(action), entries);
52
+ else {
53
+ entries = this.processor.process(entries);
54
+ }
55
+ entries = this.paging.process(entries);
56
+ return entries;
57
+ };
58
+ return MiddlewareClient;
59
+ }());
60
+ exports.default = MiddlewareClient;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ interface PropsType {
3
+ contactMethod: any;
4
+ type: any;
5
+ className?: any;
6
+ }
7
+ declare const ContactMethodItem: React.FC<PropsType>;
8
+ export default ContactMethodItem;