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

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.
@@ -248,7 +248,6 @@ var ContactMethodClient = /** @class */ (function () {
248
248
  return matchingClient.customRequest('/contactmethods', 'GET', {});
249
249
  })
250
250
  .then(function (contactMethods) {
251
- console.log('contactmethodsxxx', contactMethods);
252
251
  return contactMethods;
253
252
  });
254
253
  // return ContactMethodClient.dataClient
@@ -7,8 +7,9 @@ export declare class HttpClient {
7
7
  private options;
8
8
  private middlewareClient;
9
9
  private chatClient;
10
+ private container;
10
11
  constructor(endpoint: string, clientId: string, container: Container);
11
- firstHit(): void;
12
+ firstHit(): Promise<any>;
12
13
  handleUpdate(action: string): void;
13
14
  handleInput(action: string): void;
14
15
  handlePhrase(phrase: string): void;
@@ -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 { HttpHelper } from '../helper/http.helper';
2
38
  import { MiddlewareHelper } from '../helper/middleware.helper';
3
39
  import { StoreHelper } from '../helper/store.helper';
@@ -15,20 +51,32 @@ var HttpClient = /** @class */ (function () {
15
51
  this.clientId = this.options.clientId;
16
52
  this.middlewareClient = new MiddlewareClient(container);
17
53
  this.chatClient = new ChatClient(container);
54
+ this.container = container;
18
55
  }
19
56
  HttpClient.prototype.firstHit = function () {
20
57
  var _this = this;
58
+ MiddlewareHelper.setContainer(this.container);
59
+ MiddlewareHelper.setWidget(this.container.get('$widget'));
21
60
  // On first hit if there are entries stored in the storage, use them
22
61
  // Otherwise start a new session
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
- var response = _this.postAndHandleTheData(envelope);
29
- console.log('response from first hit', response);
30
- }
31
- });
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
+ }); });
32
80
  };
33
81
  // for updates, such as paging changes
34
82
  HttpClient.prototype.handleUpdate = function (action) {
package/lib/plugin.js CHANGED
@@ -71,20 +71,28 @@ 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'));
85
74
  // executes to decide on what to do on first load
86
75
  var httpClient = new HttpClient(endpoint, clientId, container);
87
- httpClient.firstHit();
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
+ });
88
96
  component.actions.create('evaluate', function (input) {
89
97
  var cmClient = new ContactMethodClient(container);
90
98
  cmClient.handleNewForm(input.form, input.form.id);
@@ -248,7 +248,6 @@ var ContactMethodClient = /** @class */ (function () {
248
248
  return matchingClient.customRequest('/contactmethods', 'GET', {});
249
249
  })
250
250
  .then(function (contactMethods) {
251
- console.log('contactmethodsxxx', contactMethods);
252
251
  return contactMethods;
253
252
  });
254
253
  // return ContactMethodClient.dataClient
@@ -7,8 +7,9 @@ export declare class HttpClient {
7
7
  private options;
8
8
  private middlewareClient;
9
9
  private chatClient;
10
+ private container;
10
11
  constructor(endpoint: string, clientId: string, container: Container);
11
- firstHit(): void;
12
+ firstHit(): Promise<any>;
12
13
  handleUpdate(action: string): void;
13
14
  handleInput(action: string): void;
14
15
  handlePhrase(phrase: string): void;
@@ -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 { HttpHelper } from '../helper/http.helper';
2
38
  import { MiddlewareHelper } from '../helper/middleware.helper';
3
39
  import { StoreHelper } from '../helper/store.helper';
@@ -15,20 +51,32 @@ var HttpClient = /** @class */ (function () {
15
51
  this.clientId = this.options.clientId;
16
52
  this.middlewareClient = new MiddlewareClient(container);
17
53
  this.chatClient = new ChatClient(container);
54
+ this.container = container;
18
55
  }
19
56
  HttpClient.prototype.firstHit = function () {
20
57
  var _this = this;
58
+ MiddlewareHelper.setContainer(this.container);
59
+ MiddlewareHelper.setWidget(this.container.get('$widget'));
21
60
  // On first hit if there are entries stored in the storage, use them
22
61
  // Otherwise start a new session
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
- var response = _this.postAndHandleTheData(envelope);
29
- console.log('response from first hit', response);
30
- }
31
- });
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
+ }); });
32
80
  };
33
81
  // for updates, such as paging changes
34
82
  HttpClient.prototype.handleUpdate = function (action) {
package/lib-esm/plugin.js CHANGED
@@ -71,20 +71,28 @@ 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'));
85
74
  // executes to decide on what to do on first load
86
75
  var httpClient = new HttpClient(endpoint, clientId, container);
87
- httpClient.firstHit();
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
+ });
88
96
  component.actions.create('evaluate', function (input) {
89
97
  var cmClient = new ContactMethodClient(container);
90
98
  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.30",
3
+ "version": "0.0.1-alpha.33",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",