@tiledesk/tiledesk-tybot-connector 0.1.87 → 0.1.89

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
@@ -5,8 +5,17 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.89
9
+ - DirWebRequest: fixed sending data: 'null'
10
+ - Improved MockBotsDataSource.js to support search also by intent_id
11
+ - Added test for qapla WebRequest
12
+
13
+ ### 0.1.88
14
+ - Added language parse with accept-language-parser. Now user_language has just the first language ISO code
15
+
8
16
  ### 0.1.87
9
17
  - Fixed commands-merged text in replies (text was empty for non messages with no filters)
18
+ - Renamed env LOG var from API_LOG to TILEBOT_LOG
10
19
 
11
20
  ### 0.1.86
12
21
  - Added OPERATOR "notStartsWith"
package/index.js CHANGED
@@ -12,6 +12,7 @@ const { TiledeskIntentsMachine } = require('./models/TiledeskIntentsMachine.js')
12
12
  const { MockBotsDataSource } = require('./models/MockBotsDataSource.js');
13
13
  const { TiledeskChatbotConst } = require('./models/TiledeskChatbotConst');
14
14
  const { IntentsMachineFactory } = require('./models/IntentsMachineFactory');
15
+ let parser = require('accept-language-parser');
15
16
 
16
17
  router.use(bodyParser.json({limit: '50mb'}));
17
18
  router.use(bodyParser.urlencoded({ extended: true , limit: '50mb'}));
@@ -250,8 +251,17 @@ async function updateRequestVariables(chatbot, message, projectId, requestId) {
250
251
  }
251
252
  // console.log("message.request.language", message.request["language"]);
252
253
  if (message.request) {
254
+ let user_language = message.request["language"];
255
+ if (message.request["language"]) {
256
+ // console.log("HTTP language:", message.request["language"]);
257
+ var languages = parser.parse(message.request["language"]);
258
+ // console.log("languages:", languages);
259
+ if (languages && languages.length > 0 && languages[0].code) {
260
+ user_language = languages[0].code;
261
+ }
262
+ }
253
263
  await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
254
- await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LANGUAGE_KEY, message.request["language"]);
264
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LANGUAGE_KEY, user_language);
255
265
  await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_AGENT_KEY, message.request.userAgent);
256
266
  }
257
267
  // console.log("message.request.language", message.request["language"])
@@ -47,8 +47,26 @@ class MockBotsDataSource {
47
47
  */
48
48
  async getByIntentDisplayName(botId, intentName) {
49
49
  // console.log("this.data_", JSON.stringify(this.data.bots[botId]))
50
- const intent = this.data.bots[botId].intents[intentName];
50
+ // const intent = this.data.bots[botId].intents[intentName];
51
51
  // console.log("got intent:", intent);
52
+ let intent;
53
+ try {
54
+ let key = intentName.trim();
55
+ // console.log("key is:", key);
56
+ if (key.startsWith("#")) {
57
+ let intent_id = key.substring(key.indexOf("#") + 1);
58
+ intent = this.data.bots[botId].intents_by_intent_id[intent_id];
59
+ }
60
+ else {
61
+ // console.log("key is intent name:", key);
62
+ let intent_id = key;
63
+ intent = this.data.bots[botId].intents[intent_id];
64
+ // console.log("Intent found", intent);
65
+ }
66
+ }
67
+ catch(err) {
68
+ console.error("Error is:", err);
69
+ }
52
70
  return intent;
53
71
  }
54
72
 
@@ -190,7 +190,7 @@ class TiledeskChatbotUtil {
190
190
  message.text = commands[i].message.text;
191
191
  }
192
192
  else {
193
- message.text = commands[i].message.text + "\n\n" + message.text;
193
+ message.text = (commands[i].message.text + "\n\n" + message.text).trim();
194
194
  }
195
195
  // console.log("new text:", message.text)
196
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.87",
3
+ "version": "0.1.89",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,6 +29,9 @@
29
29
  "redis": "^3.1.2",
30
30
  "uuid": "^3.3.3",
31
31
  "vm2": "^3.9.13",
32
- "mocha": "^10.2.0"
32
+ "accept-language-parser": "^1.5.0"
33
+ },
34
+ "devDependencies": {
35
+ "mocha": "^8.4.0"
33
36
  }
34
37
  }
@@ -62,7 +62,7 @@ class DirWebRequest {
62
62
  // }
63
63
  }
64
64
  let json = null;
65
- if (action.jsonBody) {
65
+ if (action.jsonBody && action.jsonBody !== "{}") {
66
66
  let jsonBody = filler.fill(action.jsonBody, requestVariables);
67
67
  try {
68
68
  json = JSON.parse(jsonBody);
@@ -79,6 +79,7 @@ class DirWebRequest {
79
79
  json: json,
80
80
  method: action.method
81
81
  };
82
+ if (this.log) {console.log("webRequest HTTPREQUEST", HTTPREQUEST);}
82
83
  this.myrequest(
83
84
  HTTPREQUEST, async (err, resbody) => {
84
85
  if (this.log) {console.log("webRequest resbody:", resbody);}
@@ -127,9 +128,20 @@ class DirWebRequest {
127
128
  if (this.log) {console.log("(webRequest) assignments:", assignments);}
128
129
  for (const [attr_name, attr_eval_expression] of Object.entries(assignments)) {
129
130
  if (this.log) {console.log("", attr_name, attr_eval_expression);}
130
- const attributeValue = TiledeskJSONEval.eval(json_body, attr_eval_expression);
131
- if (this.log) {console.log("(webRequest) Assigning to:", attr_name, "value:", attributeValue);}
132
- await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, attr_name, attributeValue);
131
+ let attributeValue;
132
+ try {
133
+ attributeValue = TiledeskJSONEval.eval(json_body, attr_eval_expression);
134
+ if (this.log) {console.log("(webRequest) Assigning to:", attr_name, "value:", attributeValue);}
135
+ }
136
+ catch(err) {
137
+ console.error("Error:", err);
138
+ }
139
+ try {
140
+ await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, attr_name, attributeValue);
141
+ }
142
+ catch(err) {
143
+ console.error("Error:", err);
144
+ }
133
145
  }
134
146
  if (this.log) {
135
147
  console.log("(webRequest) All attributes:");
@@ -154,10 +166,15 @@ class DirWebRequest {
154
166
  let axios_options = {
155
167
  url: options.url,
156
168
  method: options.method,
157
- data: options.json,
158
169
  params: options.params,
159
170
  headers: options.headers
160
171
  }
172
+ if (options.json !== null) {
173
+ axios_options.data = options.json
174
+ }
175
+ if (this.log) {
176
+ console.log("axios_options:", JSON.stringify(axios_options));
177
+ }
161
178
  if (options.url.startsWith("https:")) {
162
179
  const httpsAgent = new https.Agent({
163
180
  rejectUnauthorized: false,
@@ -182,7 +199,7 @@ class DirWebRequest {
182
199
  }
183
200
  })
184
201
  .catch( (error) => {
185
- // console.error("An error occurred:", JSON.stringify(error));
202
+ console.error("An error occurred:", JSON.stringify(error));
186
203
  if (callback) {
187
204
  callback(error, null);
188
205
  }