@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.33 → 0.0.1-alpha.36

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.
@@ -7,9 +7,8 @@ export declare class HttpClient {
7
7
  private options;
8
8
  private middlewareClient;
9
9
  private chatClient;
10
- private container;
11
10
  constructor(endpoint: string, clientId: string, container: Container);
12
- firstHit(): Promise<any>;
11
+ firstHit(): void;
13
12
  handleUpdate(action: string): void;
14
13
  handleInput(action: string): void;
15
14
  handlePhrase(phrase: string): void;
@@ -1,39 +1,3 @@
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
1
  import { HttpHelper } from '../helper/http.helper';
38
2
  import { MiddlewareHelper } from '../helper/middleware.helper';
39
3
  import { StoreHelper } from '../helper/store.helper';
@@ -51,32 +15,19 @@ var HttpClient = /** @class */ (function () {
51
15
  this.clientId = this.options.clientId;
52
16
  this.middlewareClient = new MiddlewareClient(container);
53
17
  this.chatClient = new ChatClient(container);
54
- this.container = container;
55
18
  }
56
19
  HttpClient.prototype.firstHit = function () {
57
20
  var _this = this;
58
- MiddlewareHelper.setContainer(this.container);
59
- MiddlewareHelper.setWidget(this.container.get('$widget'));
60
21
  // On first hit if there are entries stored in the storage, use them
61
22
  // Otherwise start a new session
62
- return MiddlewareHelper.getEntrySessionStorage().then(function (o) { return __awaiter(_this, void 0, void 0, function () {
63
- var envelope, response;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0:
67
- if (!(o && o.length > 0)) return [3 /*break*/, 1];
68
- this.chatClient.processMessageArrayAndStoreIt(o);
69
- return [3 /*break*/, 3];
70
- case 1:
71
- envelope = this.constructFirstHitEnvelope();
72
- return [4 /*yield*/, this.postAndHandleTheData(envelope)];
73
- case 2:
74
- response = _a.sent();
75
- return [2 /*return*/, response];
76
- case 3: return [2 /*return*/];
77
- }
78
- });
79
- }); });
23
+ MiddlewareHelper.getEntrySessionStorage().then(function (o) {
24
+ if (o && o.length > 0)
25
+ _this.chatClient.processMessageArrayAndStoreIt(o);
26
+ else {
27
+ var envelope = _this.constructFirstHitEnvelope();
28
+ _this.postAndHandleTheData(envelope);
29
+ }
30
+ });
80
31
  };
81
32
  // for updates, such as paging changes
82
33
  HttpClient.prototype.handleUpdate = function (action) {
@@ -106,7 +57,6 @@ var HttpClient = /** @class */ (function () {
106
57
  })
107
58
  .then(function (data) {
108
59
  _this.handleResponseData(data, action);
109
- return data;
110
60
  })
111
61
  .catch(function (err) { return console.log(err); });
112
62
  };
@@ -34,6 +34,7 @@ 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 { ChatHelper } from '../helper/chat.helper';
37
38
  import { MiddlewareHelper } from '../helper/middleware.helper';
38
39
  import { StoreHelper } from '../helper/store.helper';
39
40
  import EntryInterface from '../interface/entry.interface';
@@ -51,13 +52,24 @@ var MiddlewareClient = /** @class */ (function () {
51
52
  MiddlewareHelper.setContainer(container);
52
53
  MiddlewareHelper.setWidget(widget);
53
54
  };
54
- // called on all standart scenarios like actions and user messages
55
+ // called on all standard scenarios like actions and user messages
55
56
  MiddlewareClient.prototype.handleEntries = function (entries, action) {
56
57
  return __awaiter(this, void 0, void 0, function () {
57
- var o, messageArray;
58
+ var widgetEntry, agent, o, messageArray;
58
59
  return __generator(this, function (_a) {
59
60
  switch (_a.label) {
60
61
  case 0:
62
+ widgetEntry = (entries || []).find(function (e) { return e.type === 'Widget'; });
63
+ console.log('widgetentry', widgetEntry);
64
+ if (widgetEntry) {
65
+ agent = ChatHelper.getAgent();
66
+ if (agent) {
67
+ agent.update({
68
+ name: widgetEntry.content.agent.name,
69
+ avatar: widgetEntry.content.agent.avatar,
70
+ });
71
+ }
72
+ }
61
73
  o = this.executeMiddlewares(entries, false, action);
62
74
  return [4 /*yield*/, this.entryInterface.transformArray(o)];
63
75
  case 1:
package/lib/plugin.js CHANGED
@@ -71,28 +71,20 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
71
71
  platform.registerProvider('chat.bot', function (conversation, component) {
72
72
  var endpoint = getKnowledgeBotEndpoint(container, component);
73
73
  var clientId = v4();
74
+ var agent = conversation.createAgent({
75
+ // TODO: needs to be fixed asap
76
+ name: 'John Doe',
77
+ avatar: 'https://www.site.com/avatar.jpg',
78
+ });
79
+ // passes the user and the agent to the Chat Helper
80
+ ChatClient.initialize(conversation.user, agent);
81
+ // passes the conversation provider to the Contact Method Client
82
+ ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
83
+ // passes the container and the widget to the Middleware Store
84
+ MiddlewareClient.initialize(container, container.get('$widget'));
74
85
  // executes to decide on what to do on first load
75
86
  var httpClient = new HttpClient(endpoint, clientId, container);
76
- httpClient.firstHit().then(function (response) {
77
- if (response) {
78
- console.log('response from first hit', response);
79
- var widgetEntry = ((response === null || response === void 0 ? void 0 : response.entries) || []).find(function (e) { return e.type === 'Widget'; });
80
- if (widgetEntry) {
81
- var agent = conversation.createAgent({
82
- // TODO: needs to be fixed asap
83
- name: 'John Doe',
84
- avatar: 'https://www.site.com/avatar.jpg',
85
- });
86
- console.log('widget entry', widgetEntry);
87
- // passes the container and the widget to the Middleware Store
88
- MiddlewareClient.initialize(container, container.get('$widget'));
89
- // passes the user and the agent to the Chat Helper
90
- ChatClient.initialize(conversation.user, agent);
91
- // passes the conversation provider to the Contact Method Client
92
- ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
93
- }
94
- }
95
- });
87
+ httpClient.firstHit();
96
88
  component.actions.create('evaluate', function (input) {
97
89
  var cmClient = new ContactMethodClient(container);
98
90
  cmClient.handleNewForm(input.form, input.form.id);
@@ -7,9 +7,8 @@ export declare class HttpClient {
7
7
  private options;
8
8
  private middlewareClient;
9
9
  private chatClient;
10
- private container;
11
10
  constructor(endpoint: string, clientId: string, container: Container);
12
- firstHit(): Promise<any>;
11
+ firstHit(): void;
13
12
  handleUpdate(action: string): void;
14
13
  handleInput(action: string): void;
15
14
  handlePhrase(phrase: string): void;
@@ -1,39 +1,3 @@
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
1
  import { HttpHelper } from '../helper/http.helper';
38
2
  import { MiddlewareHelper } from '../helper/middleware.helper';
39
3
  import { StoreHelper } from '../helper/store.helper';
@@ -51,32 +15,19 @@ var HttpClient = /** @class */ (function () {
51
15
  this.clientId = this.options.clientId;
52
16
  this.middlewareClient = new MiddlewareClient(container);
53
17
  this.chatClient = new ChatClient(container);
54
- this.container = container;
55
18
  }
56
19
  HttpClient.prototype.firstHit = function () {
57
20
  var _this = this;
58
- MiddlewareHelper.setContainer(this.container);
59
- MiddlewareHelper.setWidget(this.container.get('$widget'));
60
21
  // On first hit if there are entries stored in the storage, use them
61
22
  // Otherwise start a new session
62
- return MiddlewareHelper.getEntrySessionStorage().then(function (o) { return __awaiter(_this, void 0, void 0, function () {
63
- var envelope, response;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0:
67
- if (!(o && o.length > 0)) return [3 /*break*/, 1];
68
- this.chatClient.processMessageArrayAndStoreIt(o);
69
- return [3 /*break*/, 3];
70
- case 1:
71
- envelope = this.constructFirstHitEnvelope();
72
- return [4 /*yield*/, this.postAndHandleTheData(envelope)];
73
- case 2:
74
- response = _a.sent();
75
- return [2 /*return*/, response];
76
- case 3: return [2 /*return*/];
77
- }
78
- });
79
- }); });
23
+ MiddlewareHelper.getEntrySessionStorage().then(function (o) {
24
+ if (o && o.length > 0)
25
+ _this.chatClient.processMessageArrayAndStoreIt(o);
26
+ else {
27
+ var envelope = _this.constructFirstHitEnvelope();
28
+ _this.postAndHandleTheData(envelope);
29
+ }
30
+ });
80
31
  };
81
32
  // for updates, such as paging changes
82
33
  HttpClient.prototype.handleUpdate = function (action) {
@@ -106,7 +57,6 @@ var HttpClient = /** @class */ (function () {
106
57
  })
107
58
  .then(function (data) {
108
59
  _this.handleResponseData(data, action);
109
- return data;
110
60
  })
111
61
  .catch(function (err) { return console.log(err); });
112
62
  };
@@ -34,6 +34,7 @@ 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 { ChatHelper } from '../helper/chat.helper';
37
38
  import { MiddlewareHelper } from '../helper/middleware.helper';
38
39
  import { StoreHelper } from '../helper/store.helper';
39
40
  import EntryInterface from '../interface/entry.interface';
@@ -51,13 +52,24 @@ var MiddlewareClient = /** @class */ (function () {
51
52
  MiddlewareHelper.setContainer(container);
52
53
  MiddlewareHelper.setWidget(widget);
53
54
  };
54
- // called on all standart scenarios like actions and user messages
55
+ // called on all standard scenarios like actions and user messages
55
56
  MiddlewareClient.prototype.handleEntries = function (entries, action) {
56
57
  return __awaiter(this, void 0, void 0, function () {
57
- var o, messageArray;
58
+ var widgetEntry, agent, o, messageArray;
58
59
  return __generator(this, function (_a) {
59
60
  switch (_a.label) {
60
61
  case 0:
62
+ widgetEntry = (entries || []).find(function (e) { return e.type === 'Widget'; });
63
+ console.log('widgetentry', widgetEntry);
64
+ if (widgetEntry) {
65
+ agent = ChatHelper.getAgent();
66
+ if (agent) {
67
+ agent.update({
68
+ name: widgetEntry.content.agent.name,
69
+ avatar: widgetEntry.content.agent.avatar,
70
+ });
71
+ }
72
+ }
61
73
  o = this.executeMiddlewares(entries, false, action);
62
74
  return [4 /*yield*/, this.entryInterface.transformArray(o)];
63
75
  case 1:
package/lib-esm/plugin.js CHANGED
@@ -71,28 +71,20 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
71
71
  platform.registerProvider('chat.bot', function (conversation, component) {
72
72
  var endpoint = getKnowledgeBotEndpoint(container, component);
73
73
  var clientId = v4();
74
+ var agent = conversation.createAgent({
75
+ // TODO: needs to be fixed asap
76
+ name: 'John Doe',
77
+ avatar: 'https://www.site.com/avatar.jpg',
78
+ });
79
+ // passes the user and the agent to the Chat Helper
80
+ ChatClient.initialize(conversation.user, agent);
81
+ // passes the conversation provider to the Contact Method Client
82
+ ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
83
+ // passes the container and the widget to the Middleware Store
84
+ MiddlewareClient.initialize(container, container.get('$widget'));
74
85
  // executes to decide on what to do on first load
75
86
  var httpClient = new HttpClient(endpoint, clientId, container);
76
- httpClient.firstHit().then(function (response) {
77
- if (response) {
78
- console.log('response from first hit', response);
79
- var widgetEntry = ((response === null || response === void 0 ? void 0 : response.entries) || []).find(function (e) { return e.type === 'Widget'; });
80
- if (widgetEntry) {
81
- var agent = conversation.createAgent({
82
- // TODO: needs to be fixed asap
83
- name: 'John Doe',
84
- avatar: 'https://www.site.com/avatar.jpg',
85
- });
86
- console.log('widget entry', widgetEntry);
87
- // passes the container and the widget to the Middleware Store
88
- MiddlewareClient.initialize(container, container.get('$widget'));
89
- // passes the user and the agent to the Chat Helper
90
- ChatClient.initialize(conversation.user, agent);
91
- // passes the conversation provider to the Contact Method Client
92
- ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
93
- }
94
- }
95
- });
87
+ httpClient.firstHit();
96
88
  component.actions.create('evaluate', function (input) {
97
89
  var cmClient = new ContactMethodClient(container);
98
90
  cmClient.handleNewForm(input.form, input.form.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/knowledge-widget-bot-provider",
3
- "version": "0.0.1-alpha.33",
3
+ "version": "0.0.1-alpha.36",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",