@tiledesk/tiledesk-tybot-connector 0.2.143 → 0.2.145
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 +7 -1
- package/ExtApi.js +5 -5
- package/index.js +16 -12
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +4 -11
- package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -11
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -16
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +4 -10
- package/tiledeskChatbotPlugs/directives/DirReply.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,12 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
+
# v0.2.145
|
|
21
|
+
- added: TILEBOT_ENDPOINT env variable to startApp method
|
|
22
|
+
|
|
23
|
+
# v0.2.144
|
|
24
|
+
- Removed userFlowAttributes from message.attributes (fix message too long issue)
|
|
25
|
+
|
|
20
26
|
# v0.2.143
|
|
21
27
|
- Changed: env var TILEBOT_ENDPOINT replaced with TILEBOT_ENDPOINT
|
|
22
28
|
|
|
@@ -24,7 +30,7 @@ available on:
|
|
|
24
30
|
- Bug-fix: action.isInfo added in DirMessage fo fix test
|
|
25
31
|
|
|
26
32
|
# v0.2.141
|
|
27
|
-
- Bug-fix: message.attributes.payload not
|
|
33
|
+
- Bug-fix: message.attributes.payload not visible on first message
|
|
28
34
|
|
|
29
35
|
# v0.2.140
|
|
30
36
|
- Bug-fix: block hidden message for non-dev conversation
|
package/ExtApi.js
CHANGED
|
@@ -4,9 +4,9 @@ let https = require("https");
|
|
|
4
4
|
class ExtApi {
|
|
5
5
|
|
|
6
6
|
constructor(options) {
|
|
7
|
-
if (!options.
|
|
8
|
-
throw new Error("options.
|
|
9
|
-
//this.extEndpoint = `${options.
|
|
7
|
+
if (!options.TILEBOT_ENDPOINT) {
|
|
8
|
+
throw new Error("options.TILEBOT_ENDPOINT is mandatory");
|
|
9
|
+
//this.extEndpoint = `${options.TILEBOT_ENDPOINT}/;
|
|
10
10
|
}
|
|
11
11
|
if (options.log) {
|
|
12
12
|
this.log = options.log;
|
|
@@ -14,7 +14,7 @@ class ExtApi {
|
|
|
14
14
|
else {
|
|
15
15
|
this.log = false;
|
|
16
16
|
}
|
|
17
|
-
this.
|
|
17
|
+
this.TILEBOT_ENDPOINT = options.TILEBOT_ENDPOINT;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
fixToken(token) {
|
|
@@ -37,7 +37,7 @@ class ExtApi {
|
|
|
37
37
|
*/
|
|
38
38
|
sendSupportMessageExt(message, projectId, requestId, token, callback) {
|
|
39
39
|
const jwt_token = this.fixToken(token);
|
|
40
|
-
const url = `${this.
|
|
40
|
+
const url = `${this.TILEBOT_ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
|
|
41
41
|
if (this.log) {console.log("sendSupportMessageExt URL", url);}
|
|
42
42
|
const HTTPREQUEST = {
|
|
43
43
|
url: url,
|
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ let mongoose = require('mongoose');
|
|
|
33
33
|
// const { Directives } = require('./tiledeskChatbotPlugs/directives/Directives.js');
|
|
34
34
|
const { TiledeskChatbotUtil } = require('./models/TiledeskChatbotUtil.js'); //require('@tiledesk/tiledesk-chatbot-util');
|
|
35
35
|
let API_ENDPOINT = null;
|
|
36
|
+
let TILEBOT_ENDPOINT = null;
|
|
36
37
|
let staticBots;
|
|
37
38
|
|
|
38
39
|
router.post('/ext/:botid', async (req, res) => {
|
|
@@ -211,7 +212,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
211
212
|
chatbot: chatbot,
|
|
212
213
|
supportRequest: message.request,
|
|
213
214
|
API_ENDPOINT: API_ENDPOINT,
|
|
214
|
-
TILEBOT_ENDPOINT:
|
|
215
|
+
TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
215
216
|
token: token,
|
|
216
217
|
log: log,
|
|
217
218
|
// HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT,
|
|
@@ -236,12 +237,9 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
236
237
|
reply.attributes.splits = true;
|
|
237
238
|
reply.attributes.markbot = true;
|
|
238
239
|
reply.attributes.fillParams = true;
|
|
239
|
-
|
|
240
|
-
if (process.env.TILEBOT_ENDPOINT) {
|
|
241
|
-
extEndpoint = `${process.env.TILEBOT_ENDPOINT}`;
|
|
242
|
-
}
|
|
240
|
+
|
|
243
241
|
const apiext = new ExtApi({
|
|
244
|
-
|
|
242
|
+
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
245
243
|
log: false
|
|
246
244
|
});
|
|
247
245
|
apiext.sendSupportMessageExt(reply, projectId, requestId, token, () => {
|
|
@@ -314,9 +312,9 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
314
312
|
if (log) {
|
|
315
313
|
console.log("/ext request....", JSON.stringify(request));
|
|
316
314
|
console.log("/ext API_ENDPOINT....", API_ENDPOINT);
|
|
317
|
-
console.log("/ext process.env.TILEBOT_ENDPOINT....",
|
|
315
|
+
console.log("/ext process.env.TILEBOT_ENDPOINT....", TILEBOT_ENDPOINT);
|
|
318
316
|
}
|
|
319
|
-
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT:
|
|
317
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT: TILEBOT_ENDPOINT, token: token, log: log, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT, cache: tdcache});
|
|
320
318
|
// let directivesPlug = null;
|
|
321
319
|
// PIPELINE-EXT
|
|
322
320
|
// if (log) {console.log("answer to process:", JSON.stringify(answer));}
|
|
@@ -601,7 +599,7 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
601
599
|
"token": "NO-TOKEN"
|
|
602
600
|
}
|
|
603
601
|
if (this.log) {console.log("sendMessageToBot()...", JSON.stringify(request));}
|
|
604
|
-
sendMessageToBot(
|
|
602
|
+
sendMessageToBot(TILEBOT_ENDPOINT, request, bot_id, async () => {
|
|
605
603
|
res.status(200).send({"success":true});
|
|
606
604
|
return;
|
|
607
605
|
});
|
|
@@ -627,6 +625,15 @@ async function startApp(settings, completionCallback) {
|
|
|
627
625
|
console.log("(Tilebot) settings.API_ENDPOINT:", API_ENDPOINT);
|
|
628
626
|
}
|
|
629
627
|
|
|
628
|
+
if (!settings.TILEBOT_ENDPOINT) {
|
|
629
|
+
TILEBOT_ENDPOINT = `${API_ENDPOINT}/modules/tilebot`
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
TILEBOT_ENDPOINT = settings.TILEBOT_ENDPOINT
|
|
633
|
+
}
|
|
634
|
+
console.log("(Tilebot) settings.TILEBOT_ENDPOINT:", TILEBOT_ENDPOINT);
|
|
635
|
+
|
|
636
|
+
|
|
630
637
|
if (settings.REDIS_HOST && settings.REDIS_PORT) {
|
|
631
638
|
tdcache = new TdCache({
|
|
632
639
|
host: settings.REDIS_HOST,
|
|
@@ -746,9 +753,6 @@ async function checkRequest(request_id, id_project) {
|
|
|
746
753
|
*/
|
|
747
754
|
function sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
|
|
748
755
|
// const jwt_token = this.fixToken(token);
|
|
749
|
-
if (!TILEBOT_ENDPOINT) {
|
|
750
|
-
TILEBOT_ENDPOINT = `${API_ENDPOINT}/modules/tilebot`
|
|
751
|
-
}
|
|
752
756
|
const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
|
|
753
757
|
console.log("sendMessageToBot URL", url);
|
|
754
758
|
const HTTPREQUEST = {
|
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//const { ExtApi } = require('../../ExtApi.js');
|
|
2
1
|
let axios = require('axios');
|
|
3
2
|
let https = require("https");
|
|
4
3
|
const { v4: uuidv4 } = require('uuid');
|
|
@@ -63,14 +62,8 @@ class DirConnectBlock {
|
|
|
63
62
|
"token": this.token
|
|
64
63
|
}
|
|
65
64
|
if (this.log) {console.log("move to intent message:", intent_command_request);}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
TILEBOT_ENDPOINT = `${this.API_ENDPOINT}/modules/tilebot`
|
|
72
|
-
}
|
|
73
|
-
this.sendMessageToBot(TILEBOT_ENDPOINT, intent_command_request, botId, () => {
|
|
65
|
+
|
|
66
|
+
this.sendMessageToBot(this.TILEBOT_ENDPOINT, intent_command_request, botId, () => {
|
|
74
67
|
callback();
|
|
75
68
|
});
|
|
76
69
|
}
|
|
@@ -114,9 +107,9 @@ class DirConnectBlock {
|
|
|
114
107
|
* @param {string} botId. Tiledesk botId
|
|
115
108
|
* @param {string} token. User token
|
|
116
109
|
*/
|
|
117
|
-
sendMessageToBot(
|
|
110
|
+
sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
|
|
118
111
|
// const jwt_token = this.fixToken(token);
|
|
119
|
-
const url = `${
|
|
112
|
+
const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
|
|
120
113
|
// console.log("sendMessageToBot URL", url);
|
|
121
114
|
const HTTPREQUEST = {
|
|
122
115
|
url: url,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//const { ExtApi } = require('../../ExtApi.js');
|
|
2
1
|
let axios = require('axios');
|
|
3
2
|
let https = require("https");
|
|
4
3
|
const { v4: uuidv4 } = require('uuid');
|
|
@@ -81,14 +80,9 @@ class DirIntent {
|
|
|
81
80
|
"token": this.token
|
|
82
81
|
}
|
|
83
82
|
if (this.log) {console.log("move to intent message:", intent_command_request);}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
TILEBOT_ENDPOINT = `${this.API_ENDPOINT}/modules/tilebot`
|
|
90
|
-
}
|
|
91
|
-
this.sendMessageToBot(TILEBOT_ENDPOINT, intent_command_request, botId, () => {
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
this.sendMessageToBot(this.TILEBOT_ENDPOINT, intent_command_request, botId, () => {
|
|
92
86
|
// console.log("sendMessageToBot() req_body sent:", intent_command_request);
|
|
93
87
|
callback(true);
|
|
94
88
|
});
|
|
@@ -138,9 +132,9 @@ class DirIntent {
|
|
|
138
132
|
* @param {string} botId. Tiledesk botId
|
|
139
133
|
* @param {string} token. User token
|
|
140
134
|
*/
|
|
141
|
-
sendMessageToBot(
|
|
135
|
+
sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
|
|
142
136
|
// const jwt_token = this.fixToken(token);
|
|
143
|
-
const url = `${
|
|
137
|
+
const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
|
|
144
138
|
// console.log("sendMessageToBot URL", url);
|
|
145
139
|
const HTTPREQUEST = {
|
|
146
140
|
url: url,
|
|
@@ -3,17 +3,6 @@ const { Directives } = require('./Directives.js');
|
|
|
3
3
|
|
|
4
4
|
class DirMessage {
|
|
5
5
|
|
|
6
|
-
// constructor(settings) {
|
|
7
|
-
// if (!settings.API_ENDPOINT) {
|
|
8
|
-
// throw new Error("settings.API_ENDPOINT is mandatory!");
|
|
9
|
-
// }
|
|
10
|
-
// this.API_ENDPOINT = settings.API_ENDPOINT;
|
|
11
|
-
// this.TILEBOT_ENDPOINT = settings.TILEBOT_ENDPOINT;
|
|
12
|
-
// this.projectId = settings.projectId;
|
|
13
|
-
// this.requestId = settings.requestId;
|
|
14
|
-
// this.token = settings.token;
|
|
15
|
-
// }
|
|
16
|
-
|
|
17
6
|
constructor(context) {
|
|
18
7
|
if (!context) {
|
|
19
8
|
throw new Error('context object is mandatory.');
|
|
@@ -110,12 +99,8 @@ class DirMessage {
|
|
|
110
99
|
// }
|
|
111
100
|
// }
|
|
112
101
|
|
|
113
|
-
let extEndpoint = `${this.API_ENDPOINT}/modules/tilebot`;
|
|
114
|
-
if (this.TILEBOT_ENDPOINT) {
|
|
115
|
-
extEndpoint = `${this.TILEBOT_ENDPOINT}`;
|
|
116
|
-
}
|
|
117
102
|
const apiext = new ExtApi({
|
|
118
|
-
|
|
103
|
+
TILEBOT_ENDPOINT: this.TILEBOT_ENDPOINT,
|
|
119
104
|
log: false
|
|
120
105
|
});
|
|
121
106
|
if (message.text) {
|
|
@@ -45,14 +45,8 @@ class DirMessageToBot {
|
|
|
45
45
|
"token": this.token
|
|
46
46
|
}
|
|
47
47
|
if (this.log) {console.log("sending message:", JSON.stringify(outgoing_message));}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
TILEBOT_ENDPOINT = `${this.API_ENDPOINT}/modules/tilebot`
|
|
54
|
-
}
|
|
55
|
-
this.sendMessageToBot(TILEBOT_ENDPOINT, outgoing_message, botId, () => {
|
|
48
|
+
|
|
49
|
+
this.sendMessageToBot(this.TILEBOT_ENDPOINT, outgoing_message, botId, () => {
|
|
56
50
|
// console.log("(DirMessageToBot) sendMessageToBot() req_body sent");
|
|
57
51
|
callback(true);
|
|
58
52
|
});
|
|
@@ -66,9 +60,9 @@ class DirMessageToBot {
|
|
|
66
60
|
* @param {string} botId. Tiledesk botId
|
|
67
61
|
* @param {string} token. User token
|
|
68
62
|
*/
|
|
69
|
-
sendMessageToBot(
|
|
63
|
+
sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
|
|
70
64
|
// const jwt_token = this.fixToken(token);
|
|
71
|
-
const url = `${
|
|
65
|
+
const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
|
|
72
66
|
// console.log("sendMessageToBot URL", url);
|
|
73
67
|
const HTTPREQUEST = {
|
|
74
68
|
url: url,
|
|
@@ -121,10 +121,12 @@ class DirReply {
|
|
|
121
121
|
message.attributes.intentName = this.context.reply.attributes.intent_info.intent_name;
|
|
122
122
|
}
|
|
123
123
|
// userFlowAttributes
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
if (this.projectId === "656054000410fa00132e5dcc") {
|
|
125
|
+
let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
|
|
126
|
+
if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
|
|
127
|
+
if (userFlowAttributes) {
|
|
128
|
+
message.attributes["flowAttributes"] = userFlowAttributes;
|
|
129
|
+
}
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
// send!
|
|
@@ -255,11 +255,14 @@ class DirReplyV2 {
|
|
|
255
255
|
message.attributes.intentName = this.context.reply.attributes.intent_info.intent_name;
|
|
256
256
|
}
|
|
257
257
|
// userFlowAttributes
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
258
|
+
if (this.projectId === "656054000410fa00132e5dcc") {
|
|
259
|
+
let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
|
|
260
|
+
if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
|
|
261
|
+
if (userFlowAttributes) {
|
|
262
|
+
message.attributes["flowAttributes"] = userFlowAttributes;
|
|
263
|
+
}
|
|
262
264
|
}
|
|
265
|
+
|
|
263
266
|
}
|
|
264
267
|
// send!
|
|
265
268
|
let cleanMessage = message;
|