@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.
- package/.env +1 -0
- package/CHANGELOG.md +10 -0
- package/ExtApi.js +2 -2
- package/TiledeskExpression.js +1 -1
- package/models/TiledeskChatbotUtil.js +1 -1
- package/models/TiledeskIntentsMachine.js +2 -2
- package/package.json +1 -1
- package/test/conversation-actions-test.js +11 -8
- package/test/conversation-actions_bot.js +53 -76
- package/test/conversation-form-test.js +73 -72
- package/test/conversation-form_bot.js +5 -5
- package/test/expression_evaluator_test.js +26 -26
- package/test/if_online_agents_directive_test.js +44 -0
- package/test/testin.js +24 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +34 -42
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +2 -2
- package/tiledeskChatbotPlugs/directives/{DirIfNotOpenHours.js → DEPRECATED_DirIfNotOpenHours.js} +0 -0
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +89 -0
- package/tiledeskChatbotPlugs/directives/DirAssign.js +15 -13
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -12
- package/tiledeskChatbotPlugs/directives/DirClose.js +6 -6
- package/tiledeskChatbotPlugs/directives/DirCondition.js +26 -21
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +5 -4
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +15 -11
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +172 -0
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +67 -24
- package/tiledeskChatbotPlugs/directives/DirIntent.js +49 -14
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +8 -2
- package/tiledeskChatbotPlugs/directives/DirMessage.js +49 -39
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirOfflineHours.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +11 -9
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +20 -19
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +10 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +5 -5
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
- package/DEPRECATED_MockActions.js +0 -148
- 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) {
|
package/TiledeskExpression.js
CHANGED
|
@@ -53,7 +53,7 @@ class TiledeskExpression {
|
|
|
53
53
|
res = fn.bind(context)()
|
|
54
54
|
}
|
|
55
55
|
catch (err) {
|
|
56
|
-
console.error("
|
|
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
|
@@ -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('
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
"
|
|
142
|
-
"depName": "Support"
|
|
143
|
-
}
|
|
126
|
+
"depName": "Support"
|
|
144
127
|
}, {
|
|
145
128
|
"type": "message",
|
|
146
|
-
"
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
"
|
|
165
|
-
"intentName": "intentAction"
|
|
166
|
-
}
|
|
143
|
+
"intentName": "intentAction"
|
|
167
144
|
}],
|
|
168
145
|
"language": "en",
|
|
169
146
|
"intent_display_name": "Intent"
|