@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.27 → 0.0.1-alpha.28
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 +2 -1
- package/lib/client/chat.client.js +2 -2
- package/lib/client/contact-method.client.d.ts +2 -0
- package/lib/client/contact-method.client.js +2 -2
- package/lib/client/http.client.d.ts +2 -1
- package/lib/client/http.client.js +3 -3
- package/lib/client/middleware.client.d.ts +5 -3
- package/lib/client/middleware.client.js +68 -9
- package/lib/interface/entry.interface.d.ts +6 -4
- package/lib/interface/entry.interface.js +161 -45
- package/lib/plugin.js +9 -9
- package/lib-esm/client/chat.client.d.ts +2 -1
- package/lib-esm/client/chat.client.js +2 -2
- package/lib-esm/client/contact-method.client.d.ts +2 -0
- package/lib-esm/client/contact-method.client.js +2 -2
- package/lib-esm/client/http.client.d.ts +2 -1
- package/lib-esm/client/http.client.js +3 -3
- package/lib-esm/client/middleware.client.d.ts +5 -3
- package/lib-esm/client/middleware.client.js +68 -9
- package/lib-esm/interface/entry.interface.d.ts +6 -4
- package/lib-esm/interface/entry.interface.js +161 -45
- package/lib-esm/plugin.js +9 -9
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
import { Message } from '../contract/model/conversation-api-model/message.model';
|
|
2
3
|
import EntryInterface from '../interface/entry.interface';
|
|
3
4
|
export default class ChatClient {
|
|
4
5
|
entryInterface: EntryInterface;
|
|
5
|
-
constructor();
|
|
6
|
+
constructor(container: Container);
|
|
6
7
|
static initialize(user: any, agent: any): void;
|
|
7
8
|
processMessageArrayAndStoreIt(messages: Message[]): void;
|
|
8
9
|
updateMessageArrayAndStoreIt(messages: Message[]): void;
|
|
@@ -4,8 +4,8 @@ import { ChatHelper } from '../helper/chat.helper';
|
|
|
4
4
|
import { StoreHelper } from '../helper/store.helper';
|
|
5
5
|
import EntryInterface from '../interface/entry.interface';
|
|
6
6
|
var ChatClient = /** @class */ (function () {
|
|
7
|
-
function ChatClient() {
|
|
8
|
-
this.entryInterface = new EntryInterface();
|
|
7
|
+
function ChatClient(container) {
|
|
8
|
+
this.entryInterface = new EntryInterface(container);
|
|
9
9
|
}
|
|
10
10
|
// Initialize from setting the user and agent for the Helper
|
|
11
11
|
ChatClient.initialize = function (user, agent) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ContactMethodPlatform } from '@humany/widget-adapters';
|
|
2
2
|
import { DataClient } from '@humany/widget-types-grid';
|
|
3
|
+
import { Container } from '@webprovisions/platform';
|
|
3
4
|
export declare class ContactMethodClient {
|
|
4
5
|
private static dataClient;
|
|
5
6
|
private static contactMethodPlatform;
|
|
@@ -7,6 +8,7 @@ export declare class ContactMethodClient {
|
|
|
7
8
|
private static agent;
|
|
8
9
|
private chatClient;
|
|
9
10
|
private static container;
|
|
11
|
+
constructor(container: Container);
|
|
10
12
|
static initialize(container: any, dataClient: DataClient, contactMethodPlatform: ContactMethodPlatform, agent: any): void;
|
|
11
13
|
handleNewForm: (errors: any, entry: any) => Promise<void>;
|
|
12
14
|
handleContactMethod: (input?: string) => Promise<void>;
|
|
@@ -51,9 +51,8 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
51
51
|
import { StoreHelper } from '../helper/store.helper';
|
|
52
52
|
import ChatClient from './chat.client';
|
|
53
53
|
var ContactMethodClient = /** @class */ (function () {
|
|
54
|
-
function ContactMethodClient() {
|
|
54
|
+
function ContactMethodClient(container) {
|
|
55
55
|
var _this = this;
|
|
56
|
-
this.chatClient = new ChatClient();
|
|
57
56
|
// function for handling forms as contact methods
|
|
58
57
|
this.handleNewForm = function (errors, entry) { return __awaiter(_this, void 0, void 0, function () {
|
|
59
58
|
return __generator(this, function (_a) {
|
|
@@ -134,6 +133,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
134
133
|
}
|
|
135
134
|
return (contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) || {};
|
|
136
135
|
};
|
|
136
|
+
this.chatClient = new ChatClient(container);
|
|
137
137
|
}
|
|
138
138
|
ContactMethodClient.initialize = function (container, dataClient, contactMethodPlatform, agent) {
|
|
139
139
|
this.dataClient = dataClient;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
export declare class HttpClient {
|
|
2
3
|
private endpointUrl;
|
|
3
4
|
private clientId;
|
|
@@ -6,7 +7,7 @@ export declare class HttpClient {
|
|
|
6
7
|
private options;
|
|
7
8
|
private middlewareClient;
|
|
8
9
|
private chatClient;
|
|
9
|
-
constructor(endpoint: string, clientId: string);
|
|
10
|
+
constructor(endpoint: string, clientId: string, container: Container);
|
|
10
11
|
firstHit(): void;
|
|
11
12
|
handleUpdate(action: string): void;
|
|
12
13
|
handleInput(action: string): void;
|
|
@@ -4,7 +4,7 @@ import { StoreHelper } from '../helper/store.helper';
|
|
|
4
4
|
import ChatClient from './chat.client';
|
|
5
5
|
import MiddlewareClient from './middleware.client';
|
|
6
6
|
var HttpClient = /** @class */ (function () {
|
|
7
|
-
function HttpClient(endpoint, clientId) {
|
|
7
|
+
function HttpClient(endpoint, clientId, container) {
|
|
8
8
|
this.options = {
|
|
9
9
|
credentials: HttpHelper.getCredentials(),
|
|
10
10
|
clientId: clientId,
|
|
@@ -13,8 +13,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
13
13
|
this.projectionPath = window.location.href;
|
|
14
14
|
this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, 'conversations');
|
|
15
15
|
this.clientId = this.options.clientId;
|
|
16
|
-
this.middlewareClient = new MiddlewareClient();
|
|
17
|
-
this.chatClient = new ChatClient();
|
|
16
|
+
this.middlewareClient = new MiddlewareClient(container);
|
|
17
|
+
this.chatClient = new ChatClient(container);
|
|
18
18
|
}
|
|
19
19
|
HttpClient.prototype.firstHit = function () {
|
|
20
20
|
var _this = this;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
2
3
|
export default class MiddlewareClient {
|
|
3
4
|
private paging;
|
|
4
5
|
private processor;
|
|
5
6
|
private entryInterface;
|
|
6
7
|
private chatClient;
|
|
7
|
-
|
|
8
|
+
private container;
|
|
9
|
+
constructor(container: Container);
|
|
8
10
|
static initialize(container: any, widget: any): void;
|
|
9
|
-
handleEntries(entries: ServerEntry[], action?: string): void
|
|
10
|
-
handleUpdate(entries: ServerEntry[], action?: string): void
|
|
11
|
+
handleEntries(entries: ServerEntry[], action?: string): Promise<void>;
|
|
12
|
+
handleUpdate(entries: ServerEntry[], action?: string): Promise<void>;
|
|
11
13
|
checkForUpdate(input: string): boolean;
|
|
12
14
|
private executeMiddlewares;
|
|
13
15
|
}
|
|
@@ -1,3 +1,39 @@
|
|
|
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
|
+
};
|
|
1
37
|
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
2
38
|
import { StoreHelper } from '../helper/store.helper';
|
|
3
39
|
import EntryInterface from '../interface/entry.interface';
|
|
@@ -5,11 +41,12 @@ import PagingInterface from '../interface/middleware/paging.interface';
|
|
|
5
41
|
import ProcessorInterface from '../interface/middleware/processor.interface';
|
|
6
42
|
import ChatClient from './chat.client';
|
|
7
43
|
var MiddlewareClient = /** @class */ (function () {
|
|
8
|
-
function MiddlewareClient() {
|
|
44
|
+
function MiddlewareClient(container) {
|
|
9
45
|
this.paging = new PagingInterface();
|
|
10
46
|
this.processor = new ProcessorInterface();
|
|
11
|
-
this.entryInterface = new EntryInterface();
|
|
12
|
-
this.chatClient = new ChatClient();
|
|
47
|
+
this.entryInterface = new EntryInterface(container);
|
|
48
|
+
this.chatClient = new ChatClient(container);
|
|
49
|
+
this.container = container;
|
|
13
50
|
}
|
|
14
51
|
MiddlewareClient.initialize = function (container, widget) {
|
|
15
52
|
MiddlewareHelper.setContainer(container);
|
|
@@ -17,16 +54,38 @@ var MiddlewareClient = /** @class */ (function () {
|
|
|
17
54
|
};
|
|
18
55
|
// called on all standart scenarios like actions and user messages
|
|
19
56
|
MiddlewareClient.prototype.handleEntries = function (entries, action) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var o, messageArray;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
o = this.executeMiddlewares(entries, false, action);
|
|
63
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
64
|
+
case 1:
|
|
65
|
+
messageArray = _a.sent();
|
|
66
|
+
this.chatClient.processMessageArrayAndStoreIt(messageArray);
|
|
67
|
+
return [2 /*return*/];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
23
71
|
};
|
|
24
72
|
// called on situations such as paging changes
|
|
25
73
|
// when no new entries will be printed
|
|
26
74
|
MiddlewareClient.prototype.handleUpdate = function (entries, action) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var o, messageArray;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
o = this.executeMiddlewares(entries, true, action);
|
|
81
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
82
|
+
case 1:
|
|
83
|
+
messageArray = _a.sent();
|
|
84
|
+
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
30
89
|
};
|
|
31
90
|
// checks whether the action was of an update type
|
|
32
91
|
MiddlewareClient.prototype.checkForUpdate = function (input) {
|
|
@@ -1,12 +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
|
-
transformContactMethod(entry: ServerEntry): any
|
|
9
|
-
transformArray(entryArray: ServerEntry[]): Message[]
|
|
8
|
+
constructor(container: Container);
|
|
9
|
+
transform(entry: ServerEntry): Promise<Message | undefined>;
|
|
10
|
+
transformContactMethod(entry: ServerEntry): Promise<any>;
|
|
11
|
+
transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
|
|
10
12
|
getUserMessage(action: string): string | undefined;
|
|
11
13
|
private listTransform;
|
|
12
14
|
private getContentText;
|
|
@@ -1,66 +1,182 @@
|
|
|
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
|
+
};
|
|
1
48
|
import { ConversationMessageListItemType, } from '@humany/widget-conversation';
|
|
49
|
+
import { DataType } from '@humany/widget-types-grid';
|
|
2
50
|
import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
|
|
3
51
|
import { StoreHelper } from '../helper/store.helper';
|
|
4
52
|
import { toContactMethod } from './convert';
|
|
5
53
|
import mocked from './_mocked-contact-method.json';
|
|
6
54
|
// TODO: toContactMethod and mocked.json should be removed
|
|
7
55
|
var EntryInterface = /** @class */ (function () {
|
|
8
|
-
function EntryInterface() {
|
|
56
|
+
function EntryInterface(container) {
|
|
57
|
+
this.container = container;
|
|
9
58
|
this.helpActionKey = 'help';
|
|
10
59
|
this.nextActionKey = 'next';
|
|
11
60
|
}
|
|
12
61
|
// transform the entry based on its type
|
|
13
62
|
EntryInterface.prototype.transform = function (entry) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var entryType, _a, _b;
|
|
65
|
+
return __generator(this, function (_c) {
|
|
66
|
+
switch (_c.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
entryType = ServerEntryTypeEnum[entry.type];
|
|
69
|
+
_a = entryType;
|
|
70
|
+
switch (_a) {
|
|
71
|
+
case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
|
|
72
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
|
|
73
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
|
|
74
|
+
case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
|
|
75
|
+
}
|
|
76
|
+
return [3 /*break*/, 6];
|
|
77
|
+
case 1: return [2 /*return*/, {
|
|
78
|
+
id: entry.id,
|
|
79
|
+
message: this.listTransform(entry),
|
|
80
|
+
entry: entry,
|
|
81
|
+
isUser: false,
|
|
82
|
+
}];
|
|
83
|
+
case 2: return [2 /*return*/, {
|
|
84
|
+
id: entry.id,
|
|
85
|
+
message: this.textTransform(entry),
|
|
86
|
+
entry: entry,
|
|
87
|
+
isUser: false,
|
|
88
|
+
}];
|
|
89
|
+
case 3: return [2 /*return*/, {
|
|
90
|
+
id: entry.id,
|
|
91
|
+
message: this.listTransform(entry),
|
|
92
|
+
entry: entry,
|
|
93
|
+
isUser: false,
|
|
94
|
+
}];
|
|
95
|
+
case 4:
|
|
96
|
+
_b = {
|
|
97
|
+
id: entry.id
|
|
98
|
+
};
|
|
99
|
+
return [4 /*yield*/, this.transformContactMethod(entry)];
|
|
100
|
+
case 5: return [2 /*return*/, (_b.message = _c.sent(),
|
|
101
|
+
_b.entry = entry,
|
|
102
|
+
_b.isUser = false,
|
|
103
|
+
_b)];
|
|
104
|
+
case 6: return [2 /*return*/];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
45
108
|
};
|
|
46
109
|
EntryInterface.prototype.transformContactMethod = function (entry) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
var dataClient, response, contactMethod;
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
|
|
115
|
+
case 1:
|
|
116
|
+
dataClient = _a.sent();
|
|
117
|
+
console.log('fetching contact method with id', entry);
|
|
118
|
+
return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
|
|
119
|
+
contactMethodId: entry.content.id,
|
|
120
|
+
})];
|
|
121
|
+
case 2:
|
|
122
|
+
response = _a.sent();
|
|
123
|
+
console.log('response', response);
|
|
124
|
+
contactMethod = toContactMethod(mocked.ContactMethod);
|
|
125
|
+
contactMethod.expanded = true; // TODO: ?
|
|
126
|
+
return [2 /*return*/, {
|
|
127
|
+
type: 'ace-knowledge-contact-method',
|
|
128
|
+
contactMethods: [contactMethod],
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
53
133
|
};
|
|
54
134
|
// transform an array of entries
|
|
55
135
|
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
|
|
138
|
+
var e_1, _a;
|
|
139
|
+
return __generator(this, function (_b) {
|
|
140
|
+
switch (_b.label) {
|
|
141
|
+
case 0:
|
|
142
|
+
returnArray = [];
|
|
143
|
+
_b.label = 1;
|
|
144
|
+
case 1:
|
|
145
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
146
|
+
entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
|
|
147
|
+
_b.label = 2;
|
|
148
|
+
case 2:
|
|
149
|
+
if (!!entryArray_1_1.done) return [3 /*break*/, 5];
|
|
150
|
+
o = entryArray_1_1.value;
|
|
151
|
+
return [4 /*yield*/, this.transform(o)];
|
|
152
|
+
case 3:
|
|
153
|
+
x = _b.sent();
|
|
154
|
+
if (!!x)
|
|
155
|
+
returnArray.push(x);
|
|
156
|
+
_b.label = 4;
|
|
157
|
+
case 4:
|
|
158
|
+
entryArray_1_1 = entryArray_1.next();
|
|
159
|
+
return [3 /*break*/, 2];
|
|
160
|
+
case 5: return [3 /*break*/, 8];
|
|
161
|
+
case 6:
|
|
162
|
+
e_1_1 = _b.sent();
|
|
163
|
+
e_1 = { error: e_1_1 };
|
|
164
|
+
return [3 /*break*/, 8];
|
|
165
|
+
case 7:
|
|
166
|
+
try {
|
|
167
|
+
if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
|
|
168
|
+
}
|
|
169
|
+
finally { if (e_1) throw e_1.error; }
|
|
170
|
+
return [7 /*endfinally*/];
|
|
171
|
+
case 8:
|
|
172
|
+
// entryArray.forEach((o) => {
|
|
173
|
+
// let x = this.transform(o);
|
|
174
|
+
// if (!!x) returnArray.push(x);
|
|
175
|
+
// });
|
|
176
|
+
return [2 /*return*/, returnArray];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
62
179
|
});
|
|
63
|
-
return returnArray;
|
|
64
180
|
};
|
|
65
181
|
// gets the text that should be printed as a user message on action
|
|
66
182
|
EntryInterface.prototype.getUserMessage = function (action) {
|
package/lib/plugin.js
CHANGED
|
@@ -83,25 +83,25 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
83
83
|
// passes the container and the widget to the Middleware Store
|
|
84
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
85
85
|
// executes to decide on what to do on first load
|
|
86
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
86
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
87
87
|
httpClient.firstHit();
|
|
88
88
|
component.actions.create('evaluate', function (input) {
|
|
89
|
-
var cmClient = new ContactMethodClient();
|
|
89
|
+
var cmClient = new ContactMethodClient(container);
|
|
90
90
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
91
91
|
});
|
|
92
92
|
component.actions.create('validate', function (input) {
|
|
93
|
-
var cmClient = new ContactMethodClient();
|
|
93
|
+
var cmClient = new ContactMethodClient(container);
|
|
94
94
|
cmClient.validate(input.form);
|
|
95
95
|
});
|
|
96
96
|
component.actions.create('submit', function (input) {
|
|
97
|
-
var cmClient = new ContactMethodClient();
|
|
97
|
+
var cmClient = new ContactMethodClient(container);
|
|
98
98
|
cmClient.validate(input.form);
|
|
99
99
|
});
|
|
100
100
|
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
101
101
|
return next(input);
|
|
102
102
|
});
|
|
103
103
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
104
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
104
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
105
105
|
httpClient.handlePhrase(input.text);
|
|
106
106
|
return next(input);
|
|
107
107
|
});
|
|
@@ -109,8 +109,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
109
109
|
return next(input);
|
|
110
110
|
});
|
|
111
111
|
component.actions.watch('conversation.action', function (input, next) {
|
|
112
|
-
var chatClient = new ChatClient();
|
|
113
|
-
var cmClient = new ContactMethodClient();
|
|
112
|
+
var chatClient = new ChatClient(container);
|
|
113
|
+
var cmClient = new ContactMethodClient(container);
|
|
114
114
|
// if (input === 'contact' || input.split('/').length > 1) {
|
|
115
115
|
// cmClient.handleContactMethod(input);
|
|
116
116
|
// return next(input);
|
|
@@ -119,8 +119,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
119
119
|
cmClient.handleContactMethod(input);
|
|
120
120
|
return next(input);
|
|
121
121
|
}
|
|
122
|
-
var middlewareClient = new MiddlewareClient();
|
|
123
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
122
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
123
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
124
124
|
// this is an update check, as it requires
|
|
125
125
|
// a lot different logic and no user message
|
|
126
126
|
if (middlewareClient.checkForUpdate(input)) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
import { Message } from '../contract/model/conversation-api-model/message.model';
|
|
2
3
|
import EntryInterface from '../interface/entry.interface';
|
|
3
4
|
export default class ChatClient {
|
|
4
5
|
entryInterface: EntryInterface;
|
|
5
|
-
constructor();
|
|
6
|
+
constructor(container: Container);
|
|
6
7
|
static initialize(user: any, agent: any): void;
|
|
7
8
|
processMessageArrayAndStoreIt(messages: Message[]): void;
|
|
8
9
|
updateMessageArrayAndStoreIt(messages: Message[]): void;
|
|
@@ -4,8 +4,8 @@ import { ChatHelper } from '../helper/chat.helper';
|
|
|
4
4
|
import { StoreHelper } from '../helper/store.helper';
|
|
5
5
|
import EntryInterface from '../interface/entry.interface';
|
|
6
6
|
var ChatClient = /** @class */ (function () {
|
|
7
|
-
function ChatClient() {
|
|
8
|
-
this.entryInterface = new EntryInterface();
|
|
7
|
+
function ChatClient(container) {
|
|
8
|
+
this.entryInterface = new EntryInterface(container);
|
|
9
9
|
}
|
|
10
10
|
// Initialize from setting the user and agent for the Helper
|
|
11
11
|
ChatClient.initialize = function (user, agent) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ContactMethodPlatform } from '@humany/widget-adapters';
|
|
2
2
|
import { DataClient } from '@humany/widget-types-grid';
|
|
3
|
+
import { Container } from '@webprovisions/platform';
|
|
3
4
|
export declare class ContactMethodClient {
|
|
4
5
|
private static dataClient;
|
|
5
6
|
private static contactMethodPlatform;
|
|
@@ -7,6 +8,7 @@ export declare class ContactMethodClient {
|
|
|
7
8
|
private static agent;
|
|
8
9
|
private chatClient;
|
|
9
10
|
private static container;
|
|
11
|
+
constructor(container: Container);
|
|
10
12
|
static initialize(container: any, dataClient: DataClient, contactMethodPlatform: ContactMethodPlatform, agent: any): void;
|
|
11
13
|
handleNewForm: (errors: any, entry: any) => Promise<void>;
|
|
12
14
|
handleContactMethod: (input?: string) => Promise<void>;
|
|
@@ -51,9 +51,8 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
51
51
|
import { StoreHelper } from '../helper/store.helper';
|
|
52
52
|
import ChatClient from './chat.client';
|
|
53
53
|
var ContactMethodClient = /** @class */ (function () {
|
|
54
|
-
function ContactMethodClient() {
|
|
54
|
+
function ContactMethodClient(container) {
|
|
55
55
|
var _this = this;
|
|
56
|
-
this.chatClient = new ChatClient();
|
|
57
56
|
// function for handling forms as contact methods
|
|
58
57
|
this.handleNewForm = function (errors, entry) { return __awaiter(_this, void 0, void 0, function () {
|
|
59
58
|
return __generator(this, function (_a) {
|
|
@@ -134,6 +133,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
134
133
|
}
|
|
135
134
|
return (contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) || {};
|
|
136
135
|
};
|
|
136
|
+
this.chatClient = new ChatClient(container);
|
|
137
137
|
}
|
|
138
138
|
ContactMethodClient.initialize = function (container, dataClient, contactMethodPlatform, agent) {
|
|
139
139
|
this.dataClient = dataClient;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
export declare class HttpClient {
|
|
2
3
|
private endpointUrl;
|
|
3
4
|
private clientId;
|
|
@@ -6,7 +7,7 @@ export declare class HttpClient {
|
|
|
6
7
|
private options;
|
|
7
8
|
private middlewareClient;
|
|
8
9
|
private chatClient;
|
|
9
|
-
constructor(endpoint: string, clientId: string);
|
|
10
|
+
constructor(endpoint: string, clientId: string, container: Container);
|
|
10
11
|
firstHit(): void;
|
|
11
12
|
handleUpdate(action: string): void;
|
|
12
13
|
handleInput(action: string): void;
|
|
@@ -4,7 +4,7 @@ import { StoreHelper } from '../helper/store.helper';
|
|
|
4
4
|
import ChatClient from './chat.client';
|
|
5
5
|
import MiddlewareClient from './middleware.client';
|
|
6
6
|
var HttpClient = /** @class */ (function () {
|
|
7
|
-
function HttpClient(endpoint, clientId) {
|
|
7
|
+
function HttpClient(endpoint, clientId, container) {
|
|
8
8
|
this.options = {
|
|
9
9
|
credentials: HttpHelper.getCredentials(),
|
|
10
10
|
clientId: clientId,
|
|
@@ -13,8 +13,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
13
13
|
this.projectionPath = window.location.href;
|
|
14
14
|
this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, 'conversations');
|
|
15
15
|
this.clientId = this.options.clientId;
|
|
16
|
-
this.middlewareClient = new MiddlewareClient();
|
|
17
|
-
this.chatClient = new ChatClient();
|
|
16
|
+
this.middlewareClient = new MiddlewareClient(container);
|
|
17
|
+
this.chatClient = new ChatClient(container);
|
|
18
18
|
}
|
|
19
19
|
HttpClient.prototype.firstHit = function () {
|
|
20
20
|
var _this = this;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
2
3
|
export default class MiddlewareClient {
|
|
3
4
|
private paging;
|
|
4
5
|
private processor;
|
|
5
6
|
private entryInterface;
|
|
6
7
|
private chatClient;
|
|
7
|
-
|
|
8
|
+
private container;
|
|
9
|
+
constructor(container: Container);
|
|
8
10
|
static initialize(container: any, widget: any): void;
|
|
9
|
-
handleEntries(entries: ServerEntry[], action?: string): void
|
|
10
|
-
handleUpdate(entries: ServerEntry[], action?: string): void
|
|
11
|
+
handleEntries(entries: ServerEntry[], action?: string): Promise<void>;
|
|
12
|
+
handleUpdate(entries: ServerEntry[], action?: string): Promise<void>;
|
|
11
13
|
checkForUpdate(input: string): boolean;
|
|
12
14
|
private executeMiddlewares;
|
|
13
15
|
}
|
|
@@ -1,3 +1,39 @@
|
|
|
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
|
+
};
|
|
1
37
|
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
2
38
|
import { StoreHelper } from '../helper/store.helper';
|
|
3
39
|
import EntryInterface from '../interface/entry.interface';
|
|
@@ -5,11 +41,12 @@ import PagingInterface from '../interface/middleware/paging.interface';
|
|
|
5
41
|
import ProcessorInterface from '../interface/middleware/processor.interface';
|
|
6
42
|
import ChatClient from './chat.client';
|
|
7
43
|
var MiddlewareClient = /** @class */ (function () {
|
|
8
|
-
function MiddlewareClient() {
|
|
44
|
+
function MiddlewareClient(container) {
|
|
9
45
|
this.paging = new PagingInterface();
|
|
10
46
|
this.processor = new ProcessorInterface();
|
|
11
|
-
this.entryInterface = new EntryInterface();
|
|
12
|
-
this.chatClient = new ChatClient();
|
|
47
|
+
this.entryInterface = new EntryInterface(container);
|
|
48
|
+
this.chatClient = new ChatClient(container);
|
|
49
|
+
this.container = container;
|
|
13
50
|
}
|
|
14
51
|
MiddlewareClient.initialize = function (container, widget) {
|
|
15
52
|
MiddlewareHelper.setContainer(container);
|
|
@@ -17,16 +54,38 @@ var MiddlewareClient = /** @class */ (function () {
|
|
|
17
54
|
};
|
|
18
55
|
// called on all standart scenarios like actions and user messages
|
|
19
56
|
MiddlewareClient.prototype.handleEntries = function (entries, action) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var o, messageArray;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
o = this.executeMiddlewares(entries, false, action);
|
|
63
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
64
|
+
case 1:
|
|
65
|
+
messageArray = _a.sent();
|
|
66
|
+
this.chatClient.processMessageArrayAndStoreIt(messageArray);
|
|
67
|
+
return [2 /*return*/];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
23
71
|
};
|
|
24
72
|
// called on situations such as paging changes
|
|
25
73
|
// when no new entries will be printed
|
|
26
74
|
MiddlewareClient.prototype.handleUpdate = function (entries, action) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var o, messageArray;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
o = this.executeMiddlewares(entries, true, action);
|
|
81
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
82
|
+
case 1:
|
|
83
|
+
messageArray = _a.sent();
|
|
84
|
+
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
30
89
|
};
|
|
31
90
|
// checks whether the action was of an update type
|
|
32
91
|
MiddlewareClient.prototype.checkForUpdate = function (input) {
|
|
@@ -1,12 +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
|
-
transformContactMethod(entry: ServerEntry): any
|
|
9
|
-
transformArray(entryArray: ServerEntry[]): Message[]
|
|
8
|
+
constructor(container: Container);
|
|
9
|
+
transform(entry: ServerEntry): Promise<Message | undefined>;
|
|
10
|
+
transformContactMethod(entry: ServerEntry): Promise<any>;
|
|
11
|
+
transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
|
|
10
12
|
getUserMessage(action: string): string | undefined;
|
|
11
13
|
private listTransform;
|
|
12
14
|
private getContentText;
|
|
@@ -1,66 +1,182 @@
|
|
|
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
|
+
};
|
|
1
48
|
import { ConversationMessageListItemType, } from '@humany/widget-conversation';
|
|
49
|
+
import { DataType } from '@humany/widget-types-grid';
|
|
2
50
|
import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
|
|
3
51
|
import { StoreHelper } from '../helper/store.helper';
|
|
4
52
|
import { toContactMethod } from './convert';
|
|
5
53
|
import mocked from './_mocked-contact-method.json';
|
|
6
54
|
// TODO: toContactMethod and mocked.json should be removed
|
|
7
55
|
var EntryInterface = /** @class */ (function () {
|
|
8
|
-
function EntryInterface() {
|
|
56
|
+
function EntryInterface(container) {
|
|
57
|
+
this.container = container;
|
|
9
58
|
this.helpActionKey = 'help';
|
|
10
59
|
this.nextActionKey = 'next';
|
|
11
60
|
}
|
|
12
61
|
// transform the entry based on its type
|
|
13
62
|
EntryInterface.prototype.transform = function (entry) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var entryType, _a, _b;
|
|
65
|
+
return __generator(this, function (_c) {
|
|
66
|
+
switch (_c.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
entryType = ServerEntryTypeEnum[entry.type];
|
|
69
|
+
_a = entryType;
|
|
70
|
+
switch (_a) {
|
|
71
|
+
case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
|
|
72
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
|
|
73
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
|
|
74
|
+
case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
|
|
75
|
+
}
|
|
76
|
+
return [3 /*break*/, 6];
|
|
77
|
+
case 1: return [2 /*return*/, {
|
|
78
|
+
id: entry.id,
|
|
79
|
+
message: this.listTransform(entry),
|
|
80
|
+
entry: entry,
|
|
81
|
+
isUser: false,
|
|
82
|
+
}];
|
|
83
|
+
case 2: return [2 /*return*/, {
|
|
84
|
+
id: entry.id,
|
|
85
|
+
message: this.textTransform(entry),
|
|
86
|
+
entry: entry,
|
|
87
|
+
isUser: false,
|
|
88
|
+
}];
|
|
89
|
+
case 3: return [2 /*return*/, {
|
|
90
|
+
id: entry.id,
|
|
91
|
+
message: this.listTransform(entry),
|
|
92
|
+
entry: entry,
|
|
93
|
+
isUser: false,
|
|
94
|
+
}];
|
|
95
|
+
case 4:
|
|
96
|
+
_b = {
|
|
97
|
+
id: entry.id
|
|
98
|
+
};
|
|
99
|
+
return [4 /*yield*/, this.transformContactMethod(entry)];
|
|
100
|
+
case 5: return [2 /*return*/, (_b.message = _c.sent(),
|
|
101
|
+
_b.entry = entry,
|
|
102
|
+
_b.isUser = false,
|
|
103
|
+
_b)];
|
|
104
|
+
case 6: return [2 /*return*/];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
45
108
|
};
|
|
46
109
|
EntryInterface.prototype.transformContactMethod = function (entry) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
var dataClient, response, contactMethod;
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
|
|
115
|
+
case 1:
|
|
116
|
+
dataClient = _a.sent();
|
|
117
|
+
console.log('fetching contact method with id', entry);
|
|
118
|
+
return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
|
|
119
|
+
contactMethodId: entry.content.id,
|
|
120
|
+
})];
|
|
121
|
+
case 2:
|
|
122
|
+
response = _a.sent();
|
|
123
|
+
console.log('response', response);
|
|
124
|
+
contactMethod = toContactMethod(mocked.ContactMethod);
|
|
125
|
+
contactMethod.expanded = true; // TODO: ?
|
|
126
|
+
return [2 /*return*/, {
|
|
127
|
+
type: 'ace-knowledge-contact-method',
|
|
128
|
+
contactMethods: [contactMethod],
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
53
133
|
};
|
|
54
134
|
// transform an array of entries
|
|
55
135
|
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
|
|
138
|
+
var e_1, _a;
|
|
139
|
+
return __generator(this, function (_b) {
|
|
140
|
+
switch (_b.label) {
|
|
141
|
+
case 0:
|
|
142
|
+
returnArray = [];
|
|
143
|
+
_b.label = 1;
|
|
144
|
+
case 1:
|
|
145
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
146
|
+
entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
|
|
147
|
+
_b.label = 2;
|
|
148
|
+
case 2:
|
|
149
|
+
if (!!entryArray_1_1.done) return [3 /*break*/, 5];
|
|
150
|
+
o = entryArray_1_1.value;
|
|
151
|
+
return [4 /*yield*/, this.transform(o)];
|
|
152
|
+
case 3:
|
|
153
|
+
x = _b.sent();
|
|
154
|
+
if (!!x)
|
|
155
|
+
returnArray.push(x);
|
|
156
|
+
_b.label = 4;
|
|
157
|
+
case 4:
|
|
158
|
+
entryArray_1_1 = entryArray_1.next();
|
|
159
|
+
return [3 /*break*/, 2];
|
|
160
|
+
case 5: return [3 /*break*/, 8];
|
|
161
|
+
case 6:
|
|
162
|
+
e_1_1 = _b.sent();
|
|
163
|
+
e_1 = { error: e_1_1 };
|
|
164
|
+
return [3 /*break*/, 8];
|
|
165
|
+
case 7:
|
|
166
|
+
try {
|
|
167
|
+
if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
|
|
168
|
+
}
|
|
169
|
+
finally { if (e_1) throw e_1.error; }
|
|
170
|
+
return [7 /*endfinally*/];
|
|
171
|
+
case 8:
|
|
172
|
+
// entryArray.forEach((o) => {
|
|
173
|
+
// let x = this.transform(o);
|
|
174
|
+
// if (!!x) returnArray.push(x);
|
|
175
|
+
// });
|
|
176
|
+
return [2 /*return*/, returnArray];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
62
179
|
});
|
|
63
|
-
return returnArray;
|
|
64
180
|
};
|
|
65
181
|
// gets the text that should be printed as a user message on action
|
|
66
182
|
EntryInterface.prototype.getUserMessage = function (action) {
|
package/lib-esm/plugin.js
CHANGED
|
@@ -83,25 +83,25 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
83
83
|
// passes the container and the widget to the Middleware Store
|
|
84
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
85
85
|
// executes to decide on what to do on first load
|
|
86
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
86
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
87
87
|
httpClient.firstHit();
|
|
88
88
|
component.actions.create('evaluate', function (input) {
|
|
89
|
-
var cmClient = new ContactMethodClient();
|
|
89
|
+
var cmClient = new ContactMethodClient(container);
|
|
90
90
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
91
91
|
});
|
|
92
92
|
component.actions.create('validate', function (input) {
|
|
93
|
-
var cmClient = new ContactMethodClient();
|
|
93
|
+
var cmClient = new ContactMethodClient(container);
|
|
94
94
|
cmClient.validate(input.form);
|
|
95
95
|
});
|
|
96
96
|
component.actions.create('submit', function (input) {
|
|
97
|
-
var cmClient = new ContactMethodClient();
|
|
97
|
+
var cmClient = new ContactMethodClient(container);
|
|
98
98
|
cmClient.validate(input.form);
|
|
99
99
|
});
|
|
100
100
|
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
101
101
|
return next(input);
|
|
102
102
|
});
|
|
103
103
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
104
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
104
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
105
105
|
httpClient.handlePhrase(input.text);
|
|
106
106
|
return next(input);
|
|
107
107
|
});
|
|
@@ -109,8 +109,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
109
109
|
return next(input);
|
|
110
110
|
});
|
|
111
111
|
component.actions.watch('conversation.action', function (input, next) {
|
|
112
|
-
var chatClient = new ChatClient();
|
|
113
|
-
var cmClient = new ContactMethodClient();
|
|
112
|
+
var chatClient = new ChatClient(container);
|
|
113
|
+
var cmClient = new ContactMethodClient(container);
|
|
114
114
|
// if (input === 'contact' || input.split('/').length > 1) {
|
|
115
115
|
// cmClient.handleContactMethod(input);
|
|
116
116
|
// return next(input);
|
|
@@ -119,8 +119,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
119
119
|
cmClient.handleContactMethod(input);
|
|
120
120
|
return next(input);
|
|
121
121
|
}
|
|
122
|
-
var middlewareClient = new MiddlewareClient();
|
|
123
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
122
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
123
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
124
124
|
// this is an update check, as it requires
|
|
125
125
|
// a lot different logic and no user message
|
|
126
126
|
if (middlewareClient.checkForUpdate(input)) {
|
package/package.json
CHANGED