@tiledesk/tiledesk-tybot-connector 0.1.45 → 0.1.47

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.
Files changed (38) hide show
  1. package/.env +1 -0
  2. package/CHANGELOG.md +10 -0
  3. package/ExtApi.js +2 -2
  4. package/TiledeskExpression.js +1 -1
  5. package/models/TiledeskChatbotUtil.js +1 -1
  6. package/models/TiledeskIntentsMachine.js +2 -2
  7. package/package.json +1 -1
  8. package/test/conversation-actions-test.js +11 -8
  9. package/test/conversation-actions_bot.js +53 -76
  10. package/test/conversation-form-test.js +73 -72
  11. package/test/conversation-form_bot.js +5 -5
  12. package/test/expression_evaluator_test.js +26 -26
  13. package/test/if_online_agents_directive_test.js +44 -0
  14. package/test/testin.js +24 -0
  15. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +34 -42
  16. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +2 -2
  17. package/tiledeskChatbotPlugs/directives/{DirIfNotOpenHours.js → DEPRECATED_DirIfNotOpenHours.js} +0 -0
  18. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +89 -0
  19. package/tiledeskChatbotPlugs/directives/DirAssign.js +15 -13
  20. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -12
  21. package/tiledeskChatbotPlugs/directives/DirClose.js +6 -6
  22. package/tiledeskChatbotPlugs/directives/DirCondition.js +26 -21
  23. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +5 -4
  24. package/tiledeskChatbotPlugs/directives/DirDepartment.js +15 -11
  25. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +172 -0
  26. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +67 -24
  27. package/tiledeskChatbotPlugs/directives/DirIntent.js +49 -14
  28. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +8 -2
  29. package/tiledeskChatbotPlugs/directives/DirMessage.js +49 -39
  30. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +14 -13
  31. package/tiledeskChatbotPlugs/directives/DirOfflineHours.js +1 -0
  32. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +11 -9
  33. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +20 -19
  34. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +10 -3
  35. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -5
  36. package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
  37. package/DEPRECATED_MockActions.js +0 -148
  38. package/test/conversation1-test copy.js_ +0 -816
package/.env CHANGED
@@ -3,6 +3,7 @@ mongoUrl=mongodb://tiledesk-user1:YB62b7gQNGg3G9OW@tiledesk-prod-shard-00-00-vmv
3
3
  REDIS_HOST=localhost
4
4
  REDIS_PORT=6379
5
5
  TYBOT_ENDPOINT=http://localhost:10001
6
+ _TYBOT_ENDPOINT=http://localhost:3000
6
7
  CHATBOT_TOKEN=JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJob29rX2VuYWJsZWQiOmZhbHNlLCJ0eXBlIjoiZXh0ZXJuYWwiLCJsYW5ndWFnZSI6ImVuIiwicHVibGljIjpmYWxzZSwiX2lkIjoiNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwibmFtZSI6IlRoZSBGb3JtIHYyIC0gZXh0IiwidXJsIjoiaHR0cHM6Ly90aWxlYm90LWRldi5oZXJva3VhcHAuY29tL2V4dC82MzhjNzhkNzFkYjQ0OTAwMzUxMTAxYzIiLCJpZF9wcm9qZWN0IjoiNjM4Yzc4YTYxZGI0NDkwMDM1MTBmZjkxIiwidHJhc2hlZCI6ZmFsc2UsImNyZWF0ZWRCeSI6IjVlMDlkMTZkNGQzNjExMDAxNzUwNmQ3ZiIsImNyZWF0ZWRBdCI6IjIwMjItMTItMDRUMTA6NDA6MDQuMjA3WiIsInVwZGF0ZWRBdCI6IjIwMjItMTItMDVUMDc6MjE6MDIuOTIxWiIsIl9fdiI6MCwiZGVzY3JpcHRpb24iOiJPbiBIZXJva3UiLCJpYXQiOjE2NzA2NzE4ODksImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tL2JvdHMvNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJib3QiLCJqdGkiOiJmNDVlZGIwYS0zNzVhLTQ0NjMtYjFhZi1jM2ZiZDg4YmE3ZGQifQ.FbW3csHl1sQgSyRz5Jg0qaTvvpXWXgWHlJ1JWoVbv3s
7
8
  _CHATBOT_ENDPOINT=http://localhost:10001
8
9
  _API_LOG=1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.47
9
+ - Introduced _tdIfOnlineAgents --trueIntent -- falseIntent
10
+ - Refactored _tdIfOpenHours --trueIntent -- falseIntent
11
+ - Removed DirIfNotOpenHours
12
+ - Refactored *context* passing *tdclient* object
13
+ - bug fixing
14
+
15
+ ### 0.1.46
16
+ - weird npm import fix
17
+
8
18
  ### 0.1.45
9
19
  - DirLockIntent added varibleName parameter
10
20
 
package/ExtApi.js CHANGED
@@ -108,7 +108,7 @@ class ExtApi {
108
108
  myrequest(options, callback, log) {
109
109
  if (this.log) {
110
110
  console.log("API URL:", options.url);
111
- console.log("** Options:", options);
111
+ console.log("** Options:", JSON.stringify(options));
112
112
  }
113
113
  let axios_options = {
114
114
  url: options.url,
@@ -127,7 +127,7 @@ class ExtApi {
127
127
  .then((res) => {
128
128
  if (this.log) {
129
129
  console.log("Response for url:", options.url);
130
- console.log("Response headers:\n", res.headers);
130
+ console.log("Response headers:\n", JSON.stringify(res.headers));
131
131
  }
132
132
  if (res && res.status == 200 && res.data) {
133
133
  if (callback) {
@@ -53,7 +53,7 @@ class TiledeskExpression {
53
53
  res = fn.bind(context)()
54
54
  }
55
55
  catch (err) {
56
- console.error("Error:", err.message, "evaluating expression: '" + expression + "'");
56
+ console.error("TiledeskExpression.evaluate() error:", err.message, "evaluating expression: '" + expression + "'");
57
57
  }
58
58
  // let fn = Function(`let $data = this;console.log('data', $data);return (${conditionExpression})`);
59
59
  return res;
@@ -17,7 +17,7 @@ class TiledeskChatbotUtil {
17
17
  }
18
18
  if (parts.length > 1) {
19
19
  let json_string = explicit_intent_name.substring(parts[0].length);
20
- console.log("json_string (params)", json_string);
20
+ // console.log("json_string (params)", json_string);
21
21
  try {
22
22
  intent.parameters = JSON.parse(json_string);
23
23
  }
@@ -95,7 +95,7 @@ class TiledeskIntentsMachine {
95
95
  myrequest(options, callback, log) {
96
96
  if (this.log) {
97
97
  console.log("API URL:", options.url);
98
- console.log("** Options:", options);
98
+ console.log("** Options:", JSON.stringify(options));
99
99
  }
100
100
  axios(
101
101
  {
@@ -108,7 +108,7 @@ class TiledeskIntentsMachine {
108
108
  .then((res) => {
109
109
  if (this.log) {
110
110
  console.log("Response for url:", options.url);
111
- console.log("Response headers:\n", res.headers);
111
+ console.log("Response headers:\n", JSON.stringify(res.headers));
112
112
  //console.log("******** Response for url:", res);
113
113
  }
114
114
  if (res && res.status == 200 && res.data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.45",
3
+ "version": "0.1.47",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,6 +5,9 @@ const tybotRoute = tybot.router;
5
5
  var express = require('express');
6
6
  var app = express();
7
7
  app.use("/", tybotRoute);
8
+ app.use((err, req, res, next) => {
9
+ console.error("General error", err);
10
+ });
8
11
  require('dotenv').config();
9
12
  const bodyParser = require('body-parser');
10
13
  const { v4: uuidv4 } = require('uuid');
@@ -13,9 +16,9 @@ const bots_data = require('./conversation-actions_bot.js').bots_data;
13
16
  const PROJECT_ID = "projectID"; //process.env.TEST_ACTIONS_PROJECT_ID;
14
17
  const REQUEST_ID = "support-group-" + PROJECT_ID + "-" + uuidv4().replace(/-/g, "");
15
18
  const BOT_ID = "botID"; //process.env.TEST_ACTIONS_BOT_ID;
16
- const CHATBOT_TOKEN = process.env.ACTIONS_CHATBOT_TOKEN;
19
+ const CHATBOT_TOKEN = "XXX"; //process.env.ACTIONS_CHATBOT_TOKEN;
17
20
 
18
- describe('Conversation1', async () => {
21
+ describe('Conversation for actions test', async () => {
19
22
 
20
23
  let app_listener;
21
24
 
@@ -108,7 +111,7 @@ describe('Conversation1', async () => {
108
111
  },
109
112
  "token": CHATBOT_TOKEN
110
113
  }
111
- sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
114
+ sendMessageToBot(request, BOT_ID, () => {
112
115
  // console.log("Message sent:\n", request);
113
116
  });
114
117
  });
@@ -166,7 +169,7 @@ describe('Conversation1', async () => {
166
169
  },
167
170
  "token": CHATBOT_TOKEN
168
171
  }
169
- sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
172
+ sendMessageToBot(request, BOT_ID, () => {
170
173
  // console.log("Message sent.");
171
174
  });
172
175
  });
@@ -229,7 +232,7 @@ describe('Conversation1', async () => {
229
232
  },
230
233
  "token": CHATBOT_TOKEN
231
234
  }
232
- sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
235
+ sendMessageToBot(request, BOT_ID, () => {
233
236
  // console.log("Message sent.");
234
237
  });
235
238
  });
@@ -245,7 +248,7 @@ describe('Conversation1', async () => {
245
248
  * @param {string} botId. Tiledesk botId
246
249
  * @param {string} token. User token
247
250
  */
248
- function sendMessageToBot(message, botId, token, callback) {
251
+ function sendMessageToBot(message, botId, callback) {
249
252
  // const jwt_token = this.fixToken(token);
250
253
  const url = `${process.env.TYBOT_ENDPOINT}/ext/${botId}`;
251
254
  // console.log("sendMessageToBot URL", url);
@@ -310,7 +313,7 @@ function getChatbotParameters(requestId, callback) {
310
313
  function myrequest(options, callback, log) {
311
314
  if (log) {
312
315
  console.log("API URL:", options.url);
313
- console.log("** Options:", options);
316
+ console.log("** Options:", JSON.stringify(options));
314
317
  }
315
318
  axios(
316
319
  {
@@ -323,7 +326,7 @@ function myrequest(options, callback, log) {
323
326
  .then((res) => {
324
327
  if (log) {
325
328
  console.log("Response for url:", options.url);
326
- console.log("Response headers:\n", res.headers);
329
+ console.log("Response headers:\n", JSON.stringify(res.headers));
327
330
  //console.log("******** Response for url:", res);
328
331
  }
329
332
  if (res && res.status == 200 && res.data) {
@@ -22,36 +22,32 @@ const bot = {
22
22
  "question": "***",
23
23
  "actions": [{
24
24
  "type": "message",
25
- "body": {
26
- "message": {
27
- "attributes": {
28
- "commands": [{
29
- "type": "message",
30
- "message": {
31
- "text": "Hello by message directive!",
32
- "type": "text"
33
- }
34
- }, {
35
- "type": "wait",
36
- "time": 500
37
- }, {
38
- "type": "message",
39
- "message": {
40
- "text": "Ciao",
41
- "type": "text",
42
- "attributes": {
43
- "attachment": {
44
- "type": "template",
45
- "buttons": [{
46
- "type": "text",
47
- "value": "/start"
48
- }]
49
- }
50
- }
25
+ "attributes": {
26
+ "commands": [{
27
+ "type": "message",
28
+ "message": {
29
+ "text": "Hello by message directive!",
30
+ "type": "text"
31
+ }
32
+ }, {
33
+ "type": "wait",
34
+ "time": 500
35
+ }, {
36
+ "type": "message",
37
+ "message": {
38
+ "text": "Ciao",
39
+ "type": "text",
40
+ "attributes": {
41
+ "attachment": {
42
+ "type": "template",
43
+ "buttons": [{
44
+ "type": "text",
45
+ "value": "/start"
46
+ }]
51
47
  }
52
- }]
48
+ }
53
49
  }
54
- }
50
+ }]
55
51
  }
56
52
  }],
57
53
  "language": "en",
@@ -63,18 +59,14 @@ const bot = {
63
59
  "answer": "***",
64
60
  "actions": [{
65
61
  "type": "message",
66
- "body": {
67
- "message": {
68
- "attributes": {
69
- "commands": [{
70
- "type": "message",
71
- "message": {
72
- "text": "Moving you to an agent...",
73
- "type": "text"
74
- }
75
- }]
62
+ "attributes": {
63
+ "commands": [{
64
+ "type": "message",
65
+ "message": {
66
+ "text": "Moving you to an agent...",
67
+ "type": "text"
76
68
  }
77
- }
69
+ }]
78
70
  }
79
71
  }, {
80
72
  "type": "agent"
@@ -87,19 +79,15 @@ const bot = {
87
79
  "question": "***",
88
80
  "answer": "***",
89
81
  "actions": [{
90
- "type": "message",
91
- "body": {
92
- "message": {
93
- "attributes": {
94
- "commands": [{
95
- "type": "message",
96
- "message": {
97
- "text": "Looking for an agent online...",
98
- "type": "text"
99
- }
100
- }]
82
+ "type": "message",
83
+ "attributes": {
84
+ "commands": [{
85
+ "type": "message",
86
+ "message": {
87
+ "text": "Looking for an agent online...",
88
+ "type": "text"
101
89
  }
102
- }
90
+ }]
103
91
  }
104
92
  }, {
105
93
  "type": "whenonlinemovetoagent"
@@ -113,18 +101,14 @@ const bot = {
113
101
  "answer": "***",
114
102
  "actions": [{
115
103
  "type": "message",
116
- "body": {
117
- "message": {
118
- "attributes": {
119
- "commands": [{
120
- "type": "message",
121
- "message": {
122
- "text": "Closing...",
123
- "type": "text"
124
- }
125
- }]
104
+ "attributes": {
105
+ "commands": [{
106
+ "type": "message",
107
+ "message": {
108
+ "text": "Closing...",
109
+ "type": "text"
126
110
  }
127
- }
111
+ }]
128
112
  }
129
113
  }, {
130
114
  "type": "close"
@@ -136,20 +120,15 @@ const bot = {
136
120
  "enabled": true,
137
121
  "question": "***",
138
122
  "answer": "***",
139
- "actions": [{
123
+ "actions": [
124
+ {
140
125
  "type": "department",
141
- "body": {
142
- "depName": "Support"
143
- }
126
+ "depName": "Support"
144
127
  }, {
145
128
  "type": "message",
146
- "body": {
147
- "message": {
148
- "text": "/start",
149
- "attributes": {
150
- "subtype": "info"
151
- }
152
- }
129
+ "text": "/start",
130
+ "attributes": {
131
+ "subtype": "info"
153
132
  }
154
133
  }],
155
134
  "language": "en",
@@ -161,9 +140,7 @@ const bot = {
161
140
  "answer": "***",
162
141
  "actions": [{
163
142
  "type": "intent",
164
- "body": {
165
- "intentName": "intentAction"
166
- }
143
+ "intentName": "intentAction"
167
144
  }],
168
145
  "language": "en",
169
146
  "intent_display_name": "Intent"