@tiledesk/tiledesk-tybot-connector 0.1.72 → 0.1.73

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/.env CHANGED
@@ -6,4 +6,4 @@ TYBOT_ENDPOINT=http://localhost:10001
6
6
  _TYBOT_ENDPOINT=http://localhost:3000
7
7
  CHATBOT_TOKEN=JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJob29rX2VuYWJsZWQiOmZhbHNlLCJ0eXBlIjoiZXh0ZXJuYWwiLCJsYW5ndWFnZSI6ImVuIiwicHVibGljIjpmYWxzZSwiX2lkIjoiNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwibmFtZSI6IlRoZSBGb3JtIHYyIC0gZXh0IiwidXJsIjoiaHR0cHM6Ly90aWxlYm90LWRldi5oZXJva3VhcHAuY29tL2V4dC82MzhjNzhkNzFkYjQ0OTAwMzUxMTAxYzIiLCJpZF9wcm9qZWN0IjoiNjM4Yzc4YTYxZGI0NDkwMDM1MTBmZjkxIiwidHJhc2hlZCI6ZmFsc2UsImNyZWF0ZWRCeSI6IjVlMDlkMTZkNGQzNjExMDAxNzUwNmQ3ZiIsImNyZWF0ZWRBdCI6IjIwMjItMTItMDRUMTA6NDA6MDQuMjA3WiIsInVwZGF0ZWRBdCI6IjIwMjItMTItMDVUMDc6MjE6MDIuOTIxWiIsIl9fdiI6MCwiZGVzY3JpcHRpb24iOiJPbiBIZXJva3UiLCJpYXQiOjE2NzA2NzE4ODksImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tL2JvdHMvNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJib3QiLCJqdGkiOiJmNDVlZGIwYS0zNzVhLTQ0NjMtYjFhZi1jM2ZiZDg4YmE3ZGQifQ.FbW3csHl1sQgSyRz5Jg0qaTvvpXWXgWHlJ1JWoVbv3s
8
8
  _CHATBOT_ENDPOINT=http://localhost:10001
9
- _API_LOG=1
9
+ API_LOG=1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,9 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.73
9
+ - Bug fixing: WebRequest headersString now is a JSON
10
+
8
11
  ### 0.1.72
9
12
  - Removed error-prone request caching.
10
13
  - Added botId caching on requestId with key: request_botId_key
package/index.js CHANGED
@@ -606,10 +606,6 @@ async function connectRedis() {
606
606
  console.log("(Tilebot) Redis connected.");
607
607
  }
608
608
  return;
609
- // console.info("Tilebot started.");
610
- // if (completionCallback) {
611
- // completionCallback();
612
- // }
613
609
  }
614
610
 
615
611
  module.exports = { router: router, startApp: startApp};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "description": "Tiledesk Tybot connector",
5
+
5
6
  "main": "index.js",
6
7
  "scripts": {
7
8
  "test": "mocha --timeout 60000 --exit",
@@ -66,7 +66,11 @@ const bot = {
66
66
  "actions": [{
67
67
  "_tdActionTitle": "var1",
68
68
  "url": "http://localhost:10002/test/webrequest/get/plain",
69
- "headersString": "{\"Content-Type\":\"application/json\",\"Cache-Control\":\"no-cache\",\"User-Agent\":\"TiledeskBotRuntime\"}",
69
+ "headersString": {
70
+ "Content-Type": "application/json",
71
+ "Cache-Control": "no-cache",
72
+ "User-Agent": "TiledeskBotRuntime"
73
+ },
70
74
  "jsonBody": "{}",
71
75
  "assignTo": "var1",
72
76
  "method": "GET",
@@ -74,7 +78,12 @@ const bot = {
74
78
  }, {
75
79
  "_tdActionTitle": "service_reply",
76
80
  "url": "http://localhost:10002/test/webrequest/post/plain",
77
- "headersString": "{\"Content-Type\":\"application/json\",\"Cache-Control\":\"no-cache\",\"User-Agent\":\"TiledeskBotRuntime\",\"Accept\":\"*/*\"}",
81
+ "headersString": {
82
+ "Content-Type": "application/json",
83
+ "Cache-Control": "no-cache",
84
+ "User-Agent": "TiledeskBotRuntime",
85
+ "Accept": "*/*"
86
+ },
78
87
  "jsonBody": "{\n\t\"name\": \"Andrea\"\n}",
79
88
  "assignTo": "service_reply",
80
89
  "method": "POST",
@@ -59,11 +59,18 @@ describe('Conversation for JSONCondition test', async () => {
59
59
  let endpointServer = express();
60
60
  endpointServer.use(bodyParser.json());
61
61
  endpointServer.get('/test/webrequest/get/plain', async (req, res) => {
62
- // console.log("******/get/plain");
62
+ console.log("/webrequest GET req.headers:", req.headers);
63
+ assert(req.headers["user-agent"] === "TiledeskBotRuntime");
64
+ assert(req.headers["content-type"] === "application/json");
65
+ assert(req.headers["cache-control"] === "no-cache");
63
66
  res.send("Application var");
64
67
  });
65
68
  endpointServer.post('/test/webrequest/post/plain', async (req, res) => {
66
- // console.log("******/post/plain req.body:", req.body);
69
+ console.log("/webrequest POST req.headers:", req.headers);
70
+ assert(req.headers["user-agent"] === "TiledeskBotRuntime");
71
+ assert(req.headers["content-type"] === "application/json");
72
+ assert(req.headers["cache-control"] === "no-cache");
73
+ assert(req.headers["accept"] === "*/*");
67
74
  if (req && req.body && req.body.name) {
68
75
  res.send("Your name is " + req.body.name);
69
76
  }
@@ -42,15 +42,20 @@ class DirWebRequest {
42
42
  const filler = new Filler();
43
43
  const url = filler.fill(action.url, requestVariables);
44
44
 
45
- let headers = null;
45
+ let headers = {};
46
46
  if (action.headersString) {
47
- let headersString = filler.fill(action.headersString, requestVariables);
48
- try {
49
- headers = JSON.parse(headersString);
50
- }
51
- catch(err) {
52
- console.error("Error parsing webRequest headersString as JSON:", headersString);
47
+ let headersDict = action.headersString
48
+ for (const [key, value] of Object.entries(headersDict)) {
49
+ if (this.log) {console.log("header:", key, "value:", value)}
50
+ let filled_value = filler.fill(value, requestVariables);
51
+ headers[key] = filled_value;
53
52
  }
53
+ // try {
54
+ // headers = JSON.parse(headersString);
55
+ // }
56
+ // catch(err) {
57
+ // console.error("Error parsing webRequest headersString as JSON:", headersString);
58
+ // }
54
59
  // for (const [key, value] of Object.entries(action.headers)) {
55
60
  // action.headers[key] = filler.fill(value, requestVariables);
56
61
  // }