@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.4 → 0.0.1-alpha.42
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.
- package/lib/client/chat.client.d.ts +3 -2
- package/lib/client/chat.client.js +98 -33
- package/lib/client/contact-method.client.d.ts +9 -1
- package/lib/client/contact-method.client.js +48 -32
- package/lib/client/http.client.d.ts +11 -7
- package/lib/client/http.client.js +138 -41
- package/lib/client/middleware.client.d.ts +4 -3
- package/lib/client/middleware.client.js +100 -35
- package/lib/contract/custom-component/contact-method-item.d.ts +1 -0
- package/lib/contract/custom-component/contact-method-item.js +10 -64
- package/lib/contract/custom-component/contact-method-list.js +6 -34
- package/lib/contract/custom-component/contact-method.js +12 -17
- package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib/contract/enum/server-entry-type.enum.js +5 -7
- package/lib/contract/model/conversation-api-model/list.model.js +1 -2
- package/lib/contract/model/conversation-api-model/message.model.js +1 -2
- package/lib/contract/model/http/action.model.js +1 -2
- package/lib/contract/model/http/client-action.model.js +1 -2
- package/lib/contract/model/http/client-envelope.model.js +1 -2
- package/lib/contract/model/http/connect-options.model.js +1 -2
- package/lib/contract/model/http/global-state.model.js +1 -2
- package/lib/contract/model/http/http-client-options.model.js +1 -2
- package/lib/contract/model/http/server-entry.model.js +1 -2
- package/lib/contract/model/http/server-envelope.model.js +1 -2
- package/lib/contract/model/middleware/aggregator-state.model.js +1 -2
- package/lib/contract/model/shared/loose-object.model.js +1 -2
- package/lib/helper/chat.helper.js +1 -4
- package/lib/helper/http.helper.d.ts +1 -1
- package/lib/helper/http.helper.js +8 -13
- package/lib/helper/middleware.helper.d.ts +1 -1
- package/lib/helper/middleware.helper.js +7 -11
- package/lib/helper/store.helper.d.ts +4 -3
- package/lib/helper/store.helper.js +105 -16
- package/lib/index.js +2 -8
- package/lib/interface/entry.interface.d.ts +6 -3
- package/lib/interface/entry.interface.js +207 -63
- package/lib/interface/middleware/paging.interface.js +3 -5
- package/lib/interface/middleware/processor.interface.js +2 -4
- package/lib/plugin.d.ts +2 -2
- package/lib/plugin.js +73 -90
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +79 -0
- package/lib-esm/client/chat.client.d.ts +3 -2
- package/lib-esm/client/chat.client.js +81 -11
- package/lib-esm/client/contact-method.client.d.ts +9 -1
- package/lib-esm/client/contact-method.client.js +28 -6
- package/lib-esm/client/http.client.d.ts +11 -7
- package/lib-esm/client/http.client.js +125 -22
- package/lib-esm/client/middleware.client.d.ts +4 -3
- package/lib-esm/client/middleware.client.js +89 -19
- package/lib-esm/contract/custom-component/contact-method-item.d.ts +1 -0
- package/lib-esm/contract/custom-component/contact-method-item.js +7 -36
- package/lib-esm/contract/custom-component/contact-method-list.js +1 -1
- package/lib-esm/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib-esm/contract/enum/server-entry-type.enum.js +3 -2
- package/lib-esm/helper/http.helper.d.ts +1 -1
- package/lib-esm/helper/http.helper.js +7 -9
- package/lib-esm/helper/middleware.helper.d.ts +1 -1
- package/lib-esm/helper/middleware.helper.js +5 -6
- package/lib-esm/helper/store.helper.d.ts +4 -3
- package/lib-esm/helper/store.helper.js +103 -11
- package/lib-esm/interface/entry.interface.d.ts +6 -3
- package/lib-esm/interface/entry.interface.js +191 -45
- package/lib-esm/interface/middleware/processor.interface.js +1 -1
- package/lib-esm/plugin.d.ts +2 -2
- package/lib-esm/plugin.js +66 -55
- package/lib-esm/utils.d.ts +2 -0
- package/lib-esm/utils.js +79 -0
- package/package.json +45 -45
- package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
- package/lib/interface/middleware/contact-expanded.interface.js +0 -50
- package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
- package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
|
@@ -1,40 +1,110 @@
|
|
|
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 { createStorageWriter, StorageCategory } from '@telia-ace/widget-services';
|
|
38
|
+
import { ChatHelper } from '../helper/chat.helper';
|
|
1
39
|
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
2
40
|
import { StoreHelper } from '../helper/store.helper';
|
|
3
41
|
import EntryInterface from '../interface/entry.interface';
|
|
4
|
-
// import ContactExpandedInterface from "../interface/middleware/contact-expanded.interface";
|
|
5
|
-
// import ContactInterface from "../interface/middleware/legacy-contact-methods.interface";
|
|
6
42
|
import PagingInterface from '../interface/middleware/paging.interface';
|
|
7
43
|
import ProcessorInterface from '../interface/middleware/processor.interface';
|
|
8
44
|
import ChatClient from './chat.client';
|
|
9
|
-
import { HttpClient } from './http.client';
|
|
10
45
|
var MiddlewareClient = /** @class */ (function () {
|
|
11
|
-
function MiddlewareClient() {
|
|
12
|
-
// this.contactExpanded = new ContactExpandedInterface();
|
|
13
|
-
// this.legacyContact = new ContactInterface();
|
|
46
|
+
function MiddlewareClient(container) {
|
|
14
47
|
this.paging = new PagingInterface();
|
|
15
48
|
this.processor = new ProcessorInterface();
|
|
16
|
-
this.entryInterface = new EntryInterface();
|
|
17
|
-
this.chatClient = new ChatClient();
|
|
49
|
+
this.entryInterface = new EntryInterface(container);
|
|
50
|
+
this.chatClient = new ChatClient(container);
|
|
18
51
|
}
|
|
19
52
|
MiddlewareClient.initialize = function (container, widget) {
|
|
20
53
|
MiddlewareHelper.setContainer(container);
|
|
21
54
|
MiddlewareHelper.setWidget(widget);
|
|
22
55
|
};
|
|
23
|
-
// called on all
|
|
56
|
+
// called on all standard scenarios like actions and user messages
|
|
24
57
|
MiddlewareClient.prototype.handleEntries = function (entries, action) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var widgetEntry, agent, write, o, messageArray;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
widgetEntry = (entries || []).find(function (e) { return e.type === 'Widget'; });
|
|
64
|
+
if (!widgetEntry) return [3 /*break*/, 2];
|
|
65
|
+
agent = ChatHelper.getAgent();
|
|
66
|
+
if (!agent) return [3 /*break*/, 2];
|
|
67
|
+
agent.update({
|
|
68
|
+
name: widgetEntry.content.agent.name,
|
|
69
|
+
avatar: widgetEntry.content.agent.avatar,
|
|
70
|
+
});
|
|
71
|
+
return [4 /*yield*/, createStorageWriter(MiddlewareHelper.getContainer(), 'bot-provider-conversation-meta', StorageCategory.Necessary)];
|
|
72
|
+
case 1:
|
|
73
|
+
write = _a.sent();
|
|
74
|
+
write({
|
|
75
|
+
agent: {
|
|
76
|
+
name: widgetEntry.content.agent.name,
|
|
77
|
+
avatar: widgetEntry.content.agent.avatar,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
_a.label = 2;
|
|
81
|
+
case 2:
|
|
82
|
+
o = this.executeMiddlewares(entries, false, action);
|
|
83
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
84
|
+
case 3:
|
|
85
|
+
messageArray = _a.sent();
|
|
86
|
+
this.chatClient.processMessageArrayAndStoreIt(messageArray);
|
|
87
|
+
return [2 /*return*/];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
28
91
|
};
|
|
29
92
|
// called on situations such as paging changes
|
|
30
93
|
// when no new entries will be printed
|
|
31
|
-
MiddlewareClient.prototype.handleUpdate = function (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
94
|
+
MiddlewareClient.prototype.handleUpdate = function (entries, action) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
var o, messageArray;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0:
|
|
100
|
+
o = this.executeMiddlewares(entries, true, action);
|
|
101
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
102
|
+
case 1:
|
|
103
|
+
messageArray = _a.sent();
|
|
104
|
+
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
38
108
|
});
|
|
39
109
|
};
|
|
40
110
|
// checks whether the action was of an update type
|
|
@@ -9,43 +9,14 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
-
if (!m) return o;
|
|
15
|
-
var i = m.call(o), r, ar = [], e;
|
|
16
|
-
try {
|
|
17
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
-
}
|
|
19
|
-
catch (error) { e = { error: error }; }
|
|
20
|
-
finally {
|
|
21
|
-
try {
|
|
22
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
-
}
|
|
24
|
-
finally { if (e) throw e.error; }
|
|
25
|
-
}
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
12
|
import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
|
|
29
|
-
import {
|
|
30
|
-
import React
|
|
31
|
-
var ContactMethodItem = function (
|
|
13
|
+
import { useDispatch } from '@telia-ace/knowledge-widget-ui';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
var ContactMethodItem = function (_a) {
|
|
16
|
+
var contactMethod = _a.contactMethod, className = _a.className;
|
|
32
17
|
var dispatch = useDispatch();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var events = container.get('$widget').events;
|
|
37
|
-
events.subscribe('form:validated', function (_event, _data) {
|
|
38
|
-
// TODO: this is a due to props not being updated when props.contactMethod.body changes
|
|
39
|
-
// perhaps there is a cleaner way of doing this
|
|
40
|
-
setBody(props.contactMethod.body);
|
|
41
|
-
});
|
|
42
|
-
}, [container]);
|
|
43
|
-
return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
|
|
44
|
-
dispatch('action', "".concat(props.contactMethod.id, "/").concat(props.type.toString(), "/").concat(props.contactMethod.title));
|
|
45
|
-
// dispatch(
|
|
46
|
-
// "expand",
|
|
47
|
-
// `${props.contactMethod.id}/${props.type.toString()}`
|
|
48
|
-
// );
|
|
49
|
-
}, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
|
|
18
|
+
return (React.createElement(GenericContactMethod, __assign({ className: className, onClick: function () {
|
|
19
|
+
dispatch('action', "".concat(contactMethod.id, "/contact-methods/").concat(contactMethod.title));
|
|
20
|
+
}, dispatch: dispatch }, contactMethod)));
|
|
50
21
|
};
|
|
51
22
|
export default ContactMethodItem;
|
|
@@ -6,7 +6,7 @@ import React, { Fragment } from 'react';
|
|
|
6
6
|
import styled from 'styled-components';
|
|
7
7
|
import ContactMethodItem from './contact-method-item';
|
|
8
8
|
var ContactMethodList = function (props) {
|
|
9
|
-
return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod })); })));
|
|
9
|
+
return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod, expanded: !!contactMethod.executeImmediately || undefined })); })));
|
|
10
10
|
};
|
|
11
11
|
var StyledContactMethod = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"], ["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
|
|
12
12
|
export default ContactMethodList;
|
|
@@ -2,6 +2,7 @@ export var ServerEntryTypeEnum;
|
|
|
2
2
|
(function (ServerEntryTypeEnum) {
|
|
3
3
|
ServerEntryTypeEnum[ServerEntryTypeEnum["Widget"] = 0] = "Widget";
|
|
4
4
|
ServerEntryTypeEnum[ServerEntryTypeEnum["Text"] = 1] = "Text";
|
|
5
|
-
ServerEntryTypeEnum[ServerEntryTypeEnum["
|
|
6
|
-
ServerEntryTypeEnum[ServerEntryTypeEnum["
|
|
5
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["Contact"] = 2] = "Contact";
|
|
6
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["List"] = 3] = "List";
|
|
7
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["Error"] = 4] = "Error";
|
|
7
8
|
})(ServerEntryTypeEnum || (ServerEntryTypeEnum = {}));
|
|
@@ -5,22 +5,20 @@ var HttpHelper = /** @class */ (function () {
|
|
|
5
5
|
return basePath + path;
|
|
6
6
|
};
|
|
7
7
|
HttpHelper.getCredentials = function () {
|
|
8
|
-
return
|
|
8
|
+
return 'same-origin';
|
|
9
9
|
};
|
|
10
|
-
var _a;
|
|
11
|
-
_a = HttpHelper;
|
|
12
10
|
HttpHelper.fetchOptions = {
|
|
13
|
-
method:
|
|
11
|
+
method: 'POST',
|
|
14
12
|
headers: {
|
|
15
|
-
Accept:
|
|
16
|
-
|
|
13
|
+
Accept: 'application/json',
|
|
14
|
+
'Content-Type': 'application/json',
|
|
17
15
|
},
|
|
18
16
|
};
|
|
19
|
-
HttpHelper.managedSubdomainSuffixes = [
|
|
17
|
+
HttpHelper.managedSubdomainSuffixes = ['stage', 'alpha', 'beta', 'gamma'];
|
|
20
18
|
HttpHelper.parseSubdomain = function (input) {
|
|
21
|
-
var index = input.lastIndexOf(
|
|
19
|
+
var index = input.lastIndexOf('-');
|
|
22
20
|
var lastPart = input.substr(index + 1);
|
|
23
|
-
if (
|
|
21
|
+
if (HttpHelper.managedSubdomainSuffixes.indexOf(lastPart) > -1) {
|
|
24
22
|
return input.substr(0, index);
|
|
25
23
|
}
|
|
26
24
|
return input;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message } from
|
|
1
|
+
import { Message } from '../contract/model/conversation-api-model/message.model';
|
|
2
2
|
export declare class MiddlewareHelper {
|
|
3
3
|
private static sessionMessageStorageVariable;
|
|
4
4
|
private static container;
|
|
@@ -34,12 +34,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import { createStorageWriter, readStorage, StorageCategory } from
|
|
37
|
+
import { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
|
|
38
38
|
var MiddlewareHelper = /** @class */ (function () {
|
|
39
39
|
function MiddlewareHelper() {
|
|
40
40
|
}
|
|
41
41
|
MiddlewareHelper.setContainer = function (container) {
|
|
42
|
-
|
|
42
|
+
MiddlewareHelper.container = container;
|
|
43
43
|
};
|
|
44
44
|
MiddlewareHelper.setWidget = function (widget) {
|
|
45
45
|
this.widget = widget;
|
|
@@ -58,10 +58,9 @@ var MiddlewareHelper = /** @class */ (function () {
|
|
|
58
58
|
MiddlewareHelper.sessionMessageStorageVariable = 'conversation-plugin-messages';
|
|
59
59
|
MiddlewareHelper.setEntrySessionStorage = function (messages) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
60
|
return __generator(_a, function (_b) {
|
|
61
|
-
createStorageWriter(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return [2 /*return*/];
|
|
61
|
+
return [2 /*return*/, createStorageWriter(MiddlewareHelper.container, MiddlewareHelper.sessionMessageStorageVariable, StorageCategory.Necessary).then(function (write) {
|
|
62
|
+
return write(messages);
|
|
63
|
+
})];
|
|
65
64
|
});
|
|
66
65
|
}); };
|
|
67
66
|
return MiddlewareHelper;
|
|
@@ -7,16 +7,17 @@ export declare class StoreHelper {
|
|
|
7
7
|
private static messageStore;
|
|
8
8
|
private static globalState;
|
|
9
9
|
constructor();
|
|
10
|
-
static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): void
|
|
11
|
-
|
|
10
|
+
static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): Promise<void>;
|
|
11
|
+
static insertMessageToStore(message: Message): void;
|
|
12
12
|
private static updateMessageInStore;
|
|
13
13
|
static checkIdInMessageStore(id: string): boolean;
|
|
14
14
|
static getLocalState(action: string): LooseObject | undefined;
|
|
15
15
|
static getGlobalState(): GlobalState;
|
|
16
|
-
static setGlobalState(state: GlobalState): void
|
|
16
|
+
static setGlobalState(state: GlobalState): Promise<void>;
|
|
17
17
|
static getAction(action: string): ClientAction;
|
|
18
18
|
static getCommand(text: string): LooseObject;
|
|
19
19
|
static getEntry(action: string): ServerEntry | undefined;
|
|
20
20
|
static getMessage(id: string): Message | undefined;
|
|
21
21
|
static getEntryStore(): ServerEntry[];
|
|
22
|
+
static rehydrateState(): Promise<void>;
|
|
22
23
|
}
|
|
@@ -1,25 +1,98 @@
|
|
|
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 { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
|
|
1
49
|
import { MiddlewareHelper } from './middleware.helper';
|
|
50
|
+
var botProviderGlobalStateSessionKey = 'bot-provider-global-state';
|
|
2
51
|
var StoreHelper = /** @class */ (function () {
|
|
3
52
|
function StoreHelper() {
|
|
4
53
|
StoreHelper.globalState = {
|
|
5
54
|
completedInteractionsCount: 0,
|
|
6
55
|
lastBotGuide: 0,
|
|
7
|
-
site: '
|
|
56
|
+
site: '',
|
|
8
57
|
invincibleParameters: {},
|
|
9
58
|
};
|
|
10
59
|
}
|
|
11
60
|
StoreHelper.insertOrUpdateMessageArrayStore = function (messageArray, entry) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var _loop_1, this_1, _a, _b, message;
|
|
63
|
+
var e_1, _c;
|
|
64
|
+
return __generator(this, function (_d) {
|
|
65
|
+
switch (_d.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
_loop_1 = function (message) {
|
|
68
|
+
if (!this_1.messageStore.find(function (o) { return o.id == message.id; })) {
|
|
69
|
+
this_1.insertMessageToStore(message);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this_1.updateMessageInStore(message, entry);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this_1 = this;
|
|
76
|
+
try {
|
|
77
|
+
for (_a = __values(messageArray.filter(function (o) { return !!o; })), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
78
|
+
message = _b.value;
|
|
79
|
+
_loop_1(message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
return [4 /*yield*/, MiddlewareHelper.setEntrySessionStorage(this.messageStore)];
|
|
90
|
+
case 1:
|
|
91
|
+
_d.sent();
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
21
95
|
});
|
|
22
|
-
MiddlewareHelper.setEntrySessionStorage(this.messageStore);
|
|
23
96
|
};
|
|
24
97
|
StoreHelper.insertMessageToStore = function (message) {
|
|
25
98
|
this.messageStore.push(message);
|
|
@@ -41,6 +114,9 @@ var StoreHelper = /** @class */ (function () {
|
|
|
41
114
|
};
|
|
42
115
|
StoreHelper.setGlobalState = function (state) {
|
|
43
116
|
StoreHelper.globalState = state;
|
|
117
|
+
return createStorageWriter(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey, StorageCategory.Necessary).then(function (write) {
|
|
118
|
+
return write(state);
|
|
119
|
+
});
|
|
44
120
|
};
|
|
45
121
|
StoreHelper.getAction = function (action) {
|
|
46
122
|
var entry = this.getEntry(action);
|
|
@@ -71,6 +147,22 @@ var StoreHelper = /** @class */ (function () {
|
|
|
71
147
|
return o.entry;
|
|
72
148
|
});
|
|
73
149
|
};
|
|
150
|
+
StoreHelper.rehydrateState = function () {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var state;
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0: return [4 /*yield*/, readStorage(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey)];
|
|
156
|
+
case 1:
|
|
157
|
+
state = _a.sent();
|
|
158
|
+
if (state) {
|
|
159
|
+
this.setGlobalState(state);
|
|
160
|
+
}
|
|
161
|
+
return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
74
166
|
StoreHelper.messageStore = [];
|
|
75
167
|
return StoreHelper;
|
|
76
168
|
}());
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
import { Message } from '../contract/model/conversation-api-model/message.model';
|
|
2
3
|
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
3
4
|
export default class EntryInterface {
|
|
5
|
+
private container;
|
|
4
6
|
private helpActionKey;
|
|
5
7
|
private nextActionKey;
|
|
6
|
-
constructor();
|
|
7
|
-
transform(entry: ServerEntry): Message | undefined
|
|
8
|
-
|
|
8
|
+
constructor(container: Container);
|
|
9
|
+
transform(entry: ServerEntry, feedbackEntry?: ServerEntry): Promise<Message | undefined>;
|
|
10
|
+
transformContactMethod(entry: ServerEntry): Promise<any>;
|
|
11
|
+
transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
|
|
9
12
|
getUserMessage(action: string): string | undefined;
|
|
10
13
|
private listTransform;
|
|
11
14
|
private getContentText;
|