@tiledesk/tiledesk-tybot-connector 0.1.9 → 0.1.11

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/CHANGELOG.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Tiledesk tybotRoute
2
2
 
3
- **npm @tiledesk/tiledesk-tybot-connector@0.1.9**
3
+ **npm @tiledesk/tiledesk-tybot-connector@0.1.11**
4
4
 
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.11 online - logs update for debug deflect to help center directive parsing
9
+
8
10
  ### 0.1.9 online - set log on ExtApi class
9
11
 
10
12
  ### 0.1.8 online - fixed: import minimist-string fix
package/ExtApi.js CHANGED
@@ -24,11 +24,21 @@ class ExtApi {
24
24
  return 'JWT ' + token;
25
25
  }
26
26
  }
27
-
27
+
28
+ /**
29
+ * A stub to send message to the "ext" endpoint, hosted by tilebot on:
30
+ * /${TILEBOT_ROUTE}/ext/${projectId}/requests/${requestId}/messages
31
+ *
32
+ * @param {Object} message. The message to send
33
+ * @param {string} projectId. Tiledesk projectId
34
+ * @param {string} requestId. Tiledesk requestId
35
+ * @param {string} token. User token
36
+ */
28
37
  sendSupportMessageExt(message, projectId, requestId, token, callback) {
29
38
  const jwt_token = this.fixToken(token);
30
39
  const url = `${this.ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
31
40
  if (this.log) {console.log("sendSupportMessageExt URL", url);}
41
+ console.log("sendSupportMessageExt:", url);
32
42
  const HTTPREQUEST = {
33
43
  url: url,
34
44
  headers: {
@@ -41,6 +51,7 @@ class ExtApi {
41
51
  this.myrequest(
42
52
  HTTPREQUEST,
43
53
  function(err, resbody) {
54
+ console.log("sendSupportMessageExt resbody:", resbody);
44
55
  if (err) {
45
56
  if (callback) {
46
57
  callback(err);
package/index.js CHANGED
@@ -153,7 +153,8 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
153
153
  log: false
154
154
  });
155
155
  tdclient.getRequestById(requestId, async (err, request) => {
156
- let directivesPlug = new DirectivesChatbotPlug(request, APIURL, token, log);
156
+ console.log("got remote request:", request);
157
+ let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, TILEDESK_API_ENDPOINT: APIURL, token: token, log: log, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT});
157
158
  // PIPELINE-EXT
158
159
  const bot_answer = await ExtUtil.execPipelineExt(answer, directivesPlug);
159
160
  /*if (!validMessage(bot_answer)) {
@@ -171,11 +172,11 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
171
172
  });
172
173
 
173
174
  async function execFaq(req, res, faqs, botId, message, token, bot) {
175
+ console.log("execFaq.", faqs, botId);
174
176
  let sender = 'bot_' + botId;
175
177
  var answerObj;
176
178
  answerObj = faqs[0];
177
179
  answerObj.score = 100; //exact search not set score
178
- //console.debug("answerObj.score", answerObj.score);
179
180
 
180
181
  const context = {
181
182
  payload: {
@@ -430,7 +431,7 @@ function startApp(settings, completionCallback) {
430
431
  log = true;
431
432
  }*/
432
433
 
433
- console.log("Starting Tilebot connector.....");
434
+ console.log("Starting Tilebot connector v0.1.10 ...");
434
435
  console.log("(Tilebot) Connecting to mongodb...");
435
436
 
436
437
  connection = mongoose.connect(settings.MONGODB_URI, { "useNewUrlParser": true, "autoIndex": false }, function(err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,11 +17,12 @@ class DirectivesChatbotPlug {
17
17
  *
18
18
  */
19
19
 
20
- constructor(supportRequest, API_URL, token, log) {
21
- this.supportRequest = supportRequest;
22
- this.API_URL = API_URL;
23
- this.token = token;
24
- this.log = log;
20
+ constructor(config) {
21
+ this.supportRequest = config.supportRequest;
22
+ this.API_URL = config.TILEDESK_API_ENDPOINT;
23
+ this.token = config.token;
24
+ this.log = config.log;
25
+ this.HELP_CENTER_API_ENDPOINT = config.HELP_CENTER_API_ENDPOINT;
25
26
  }
26
27
 
27
28
  exec(pipeline) {
@@ -102,7 +103,8 @@ class DirectivesChatbotPlug {
102
103
  const API_URL = this.API_URL;
103
104
 
104
105
  const requestId = supportRequest.request_id
105
- const depId = supportRequest.department._id;
106
+ //const depId = supportRequest.department._id;
107
+ const depId = supportRequest.attributes.departmentId;
106
108
  const projectId = supportRequest.id_project;
107
109
  const tdclient = new TiledeskClient({
108
110
  projectId: projectId,
@@ -222,8 +224,10 @@ class DirectivesChatbotPlug {
222
224
  const token = this.token;
223
225
  const API_URL = this.API_URL;
224
226
 
227
+ console.log("supportRequest", supportRequest)
225
228
  const requestId = supportRequest.request_id
226
- const depId = supportRequest.department._id;
229
+ //const depId = supportRequest.department._id;
230
+ const depId = supportRequest.attributes.departmentId;
227
231
  const projectId = supportRequest.id_project;
228
232
  const tdclient = new TiledeskClient({
229
233
  projectId: projectId,
@@ -252,23 +256,13 @@ class DirectivesChatbotPlug {
252
256
  process(nextDirective());
253
257
  });
254
258
  }
255
- /*else if (directive_name === Directives.WHEN_OFFLINE_HOURS_REPLACE_MESSAGE) {
256
- directive.replaceMessage = true;
257
- tdclient.log = false;
258
- const offlineHoursDir = new DirOfflineHours(tdclient);
259
- offlineHoursDir.execute(directive, pipeline, () => {
260
- process(nextDirective());
261
- });
262
- }*/
263
259
  else if (directive_name === Directives.DEFLECT_TO_HELP_CENTER) {
264
- const helpcenter_api_endpoint = "https://tiledesk-cms-server-prod.herokuapp.com";
265
- const helpDir = new DirDeflectToHelpCenter(helpcenter_api_endpoint, projectId);
260
+ const helpDir = new DirDeflectToHelpCenter({HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT, projectId: projectId});
266
261
  helpDir.execute(directive, pipeline, 3, () => {
267
262
  process(nextDirective());
268
263
  });
269
264
  }
270
265
  else {
271
- //console.log("Unhandled Inline Directive:", directive_name);
272
266
  process(nextDirective());
273
267
  }
274
268
  }
@@ -4,15 +4,15 @@ const ms = require('minimist-string');
4
4
 
5
5
  class DirDeflectToHelpCenter {
6
6
 
7
- constructor(helpcenter_api_endpoint, projectId) {
8
- if (!helpcenter_api_endpoint) {
9
- throw new Error('helpcenter_api_endpoint is mandatory.');
10
- }
11
- if (!projectId) {
7
+ constructor(config) {
8
+ if (!config.projectId) {
12
9
  throw new Error('projectId is mandatory.');
13
10
  }
14
- this.helpcenter_api_endpoint = helpcenter_api_endpoint;
15
- this.projectId = projectId;
11
+ if (config.HELP_CENTER_API_ENDPOINT) {
12
+ this.helpcenter_api_endpoint = config.HELP_CENTER_API_ENDPOINT;
13
+ }
14
+ console.log("Using helpcenter_api_endpoint:", this.helpcenter_api_endpoint)
15
+ this.projectId = config.projectId;
16
16
  }
17
17
 
18
18
  async execute(directive, pipeline, maxresults, completion) {
@@ -20,11 +20,14 @@ class DirDeflectToHelpCenter {
20
20
  let default_hc_reply = "No matching reply but...\n\nI found something interesting in the Help Center 🧐\n\nTake a look 👇";
21
21
  let hc_reply = default_hc_reply;
22
22
  if (directive.parameter) {
23
- //console.log("processing parameters")
23
+ console.log("processing parameters")
24
24
  const params = this.parseParams(directive.parameter);
25
+ console.log("parameters found", params);
25
26
  workspace_id = params.workspace_id;
27
+ console.log("workspaceid found", workspace_id);
26
28
  if (params.hc_reply) {
27
29
  hc_reply = params.hc_reply;
30
+ console.log("hc_reply found", hc_reply);
28
31
  }
29
32
  }
30
33
  else {
@@ -39,6 +42,7 @@ class DirDeflectToHelpCenter {
39
42
  if (original_text && original_text.trim() != '') {
40
43
  const helpcenter = new HelpCenterQuery({
41
44
  APIKEY: "__",
45
+ APIURL: this.helpcenter_api_endpoint,
42
46
  projectId: this.projectId,
43
47
  log: false
44
48
  });
@@ -89,7 +93,9 @@ class DirDeflectToHelpCenter {
89
93
  parseParams(directive_parameter) {
90
94
  let workspace_id = null;
91
95
  let hc_reply = null;
96
+ console.log("ms found:", ms)
92
97
  const params = ms(directive_parameter);
98
+ console.log("ms decoded params:", params)
93
99
  if (params.w) {
94
100
  workspace_id = params.w
95
101
  }
@@ -98,12 +104,14 @@ class DirDeflectToHelpCenter {
98
104
  }
99
105
 
100
106
  if (params.m) {
101
- //console.log("_param m", params.m)
107
+ console.log("_params.m:", params.m)
102
108
  hc_reply = params.m.replaceAll("\\n", "\n");
109
+ console.log("hc_reply with replaced slash n", hc_reply)
103
110
  }
104
111
  if (params.message) {
105
- //console.log("_param message", params.message)
112
+ console.log("_params.message:", params.message)
106
113
  hc_reply = params.message.replaceAll("\\n", "\n");
114
+ console.log("hc_reply -message with replaced slash n", hc_reply)
107
115
  }
108
116
  return {
109
117
  workspace_id: workspace_id,