@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.29 → 0.0.1-alpha.31

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
@@ -8,7 +8,7 @@ export declare class HttpClient {
8
8
  private middlewareClient;
9
9
  private chatClient;
10
10
  constructor(endpoint: string, clientId: string, container: Container);
11
- firstHit(): void;
11
+ firstHit(): Promise<any>;
12
12
  handleUpdate(action: string): void;
13
13
  handleInput(action: string): void;
14
14
  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';
@@ -20,14 +56,24 @@ var HttpClient = /** @class */ (function () {
20
56
  var _this = this;
21
57
  // On first hit if there are entries stored in the storage, use them
22
58
  // 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
- _this.postAndHandleTheData(envelope);
29
- }
30
- });
59
+ return MiddlewareHelper.getEntrySessionStorage().then(function (o) { return __awaiter(_this, void 0, void 0, function () {
60
+ var envelope, response;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ if (!(o && o.length > 0)) return [3 /*break*/, 1];
65
+ this.chatClient.processMessageArrayAndStoreIt(o);
66
+ return [3 /*break*/, 3];
67
+ case 1:
68
+ envelope = this.constructFirstHitEnvelope();
69
+ return [4 /*yield*/, this.postAndHandleTheData(envelope)];
70
+ case 2:
71
+ response = _a.sent();
72
+ return [2 /*return*/, response];
73
+ case 3: return [2 /*return*/];
74
+ }
75
+ });
76
+ }); });
31
77
  };
32
78
  // for updates, such as paging changes
33
79
  HttpClient.prototype.handleUpdate = function (action) {
@@ -57,6 +103,7 @@ var HttpClient = /** @class */ (function () {
57
103
  })
58
104
  .then(function (data) {
59
105
  _this.handleResponseData(data, action);
106
+ return data;
60
107
  })
61
108
  .catch(function (err) { return console.log(err); });
62
109
  };
@@ -49,7 +49,6 @@ import { ConversationMessageListItemType, } from '@humany/widget-conversation';
49
49
  import { DataType } from '@humany/widget-types-grid';
50
50
  import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
51
51
  import { StoreHelper } from '../helper/store.helper';
52
- // TODO: toContactMethod and mocked.json should be removed
53
52
  var EntryInterface = /** @class */ (function () {
54
53
  function EntryInterface(container) {
55
54
  this.container = container;
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
74
  // passes the container and the widget to the Middleware Store
84
75
  MiddlewareClient.initialize(container, container.get('$widget'));
85
76
  // executes to decide on what to do on first load
86
77
  var httpClient = new HttpClient(endpoint, clientId, container);
87
- httpClient.firstHit();
78
+ httpClient.firstHit().then(function (response) {
79
+ if (response) {
80
+ console.log('response from first hit', response);
81
+ var widgetEntry = ((response === null || response === void 0 ? void 0 : response.entries) || []).find(function (e) { return e.type === 'Widget'; });
82
+ if (widgetEntry) {
83
+ var agent = conversation.createAgent({
84
+ // TODO: needs to be fixed asap
85
+ name: 'John Doe',
86
+ avatar: 'https://www.site.com/avatar.jpg',
87
+ });
88
+ console.log('widget entry', widgetEntry);
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
@@ -8,7 +8,7 @@ export declare class HttpClient {
8
8
  private middlewareClient;
9
9
  private chatClient;
10
10
  constructor(endpoint: string, clientId: string, container: Container);
11
- firstHit(): void;
11
+ firstHit(): Promise<any>;
12
12
  handleUpdate(action: string): void;
13
13
  handleInput(action: string): void;
14
14
  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';
@@ -20,14 +56,24 @@ var HttpClient = /** @class */ (function () {
20
56
  var _this = this;
21
57
  // On first hit if there are entries stored in the storage, use them
22
58
  // 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
- _this.postAndHandleTheData(envelope);
29
- }
30
- });
59
+ return MiddlewareHelper.getEntrySessionStorage().then(function (o) { return __awaiter(_this, void 0, void 0, function () {
60
+ var envelope, response;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ if (!(o && o.length > 0)) return [3 /*break*/, 1];
65
+ this.chatClient.processMessageArrayAndStoreIt(o);
66
+ return [3 /*break*/, 3];
67
+ case 1:
68
+ envelope = this.constructFirstHitEnvelope();
69
+ return [4 /*yield*/, this.postAndHandleTheData(envelope)];
70
+ case 2:
71
+ response = _a.sent();
72
+ return [2 /*return*/, response];
73
+ case 3: return [2 /*return*/];
74
+ }
75
+ });
76
+ }); });
31
77
  };
32
78
  // for updates, such as paging changes
33
79
  HttpClient.prototype.handleUpdate = function (action) {
@@ -57,6 +103,7 @@ var HttpClient = /** @class */ (function () {
57
103
  })
58
104
  .then(function (data) {
59
105
  _this.handleResponseData(data, action);
106
+ return data;
60
107
  })
61
108
  .catch(function (err) { return console.log(err); });
62
109
  };
@@ -49,7 +49,6 @@ import { ConversationMessageListItemType, } from '@humany/widget-conversation';
49
49
  import { DataType } from '@humany/widget-types-grid';
50
50
  import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
51
51
  import { StoreHelper } from '../helper/store.helper';
52
- // TODO: toContactMethod and mocked.json should be removed
53
52
  var EntryInterface = /** @class */ (function () {
54
53
  function EntryInterface(container) {
55
54
  this.container = container;
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
74
  // passes the container and the widget to the Middleware Store
84
75
  MiddlewareClient.initialize(container, container.get('$widget'));
85
76
  // executes to decide on what to do on first load
86
77
  var httpClient = new HttpClient(endpoint, clientId, container);
87
- httpClient.firstHit();
78
+ httpClient.firstHit().then(function (response) {
79
+ if (response) {
80
+ console.log('response from first hit', response);
81
+ var widgetEntry = ((response === null || response === void 0 ? void 0 : response.entries) || []).find(function (e) { return e.type === 'Widget'; });
82
+ if (widgetEntry) {
83
+ var agent = conversation.createAgent({
84
+ // TODO: needs to be fixed asap
85
+ name: 'John Doe',
86
+ avatar: 'https://www.site.com/avatar.jpg',
87
+ });
88
+ console.log('widget entry', widgetEntry);
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.29",
3
+ "version": "0.0.1-alpha.31",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",