@tiledesk/tiledesk-tybot-connector 0.2.29 → 0.2.30
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
package/index.js
CHANGED
|
@@ -37,7 +37,6 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
37
37
|
console.log("Removed req.body.payload.request.snapshot field");
|
|
38
38
|
}
|
|
39
39
|
if (log) {console.log("REQUEST BODY:", JSON.stringify(req.body));}
|
|
40
|
-
res.status(200).send({"success":true});
|
|
41
40
|
|
|
42
41
|
const botId = req.params.botid;
|
|
43
42
|
if (log) {console.log(" :", botId);}
|
|
@@ -53,6 +52,14 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
53
52
|
if (message.request.id_project === null || message.request.id_project === undefined) {
|
|
54
53
|
message.request.id_project = projectId;
|
|
55
54
|
}
|
|
55
|
+
|
|
56
|
+
// let request_check = checkRequest(message.request.request_id, message.id_project);
|
|
57
|
+
// if (request_check === true) {
|
|
58
|
+
// res.status(200).send({ "successs": true });
|
|
59
|
+
// } else {
|
|
60
|
+
// return res.status(400).send({ "success": false, "message": "Invalid request_id"})
|
|
61
|
+
// }
|
|
62
|
+
res.status(200).send({"success":true});
|
|
56
63
|
|
|
57
64
|
const request_botId_key = "tilebot:botId_requests:" + requestId;
|
|
58
65
|
await tdcache.set(
|
|
@@ -541,4 +548,23 @@ async function connectRedis() {
|
|
|
541
548
|
return;
|
|
542
549
|
}
|
|
543
550
|
|
|
551
|
+
async function checkRequest(request_id, id_project) {
|
|
552
|
+
// TO DO CHECK
|
|
553
|
+
|
|
554
|
+
// if (request_id startsWith "support-request-{$project_id}")
|
|
555
|
+
// if (project_id is equal to the id_project)
|
|
556
|
+
// return true;
|
|
557
|
+
// else
|
|
558
|
+
// return (false, motivation)
|
|
559
|
+
// else if (request_id startsWith "automation-request-{$project_id}")
|
|
560
|
+
// if (project_id is equal to the id_project)
|
|
561
|
+
// return true;
|
|
562
|
+
// else
|
|
563
|
+
// return (false, motivation)
|
|
564
|
+
// else
|
|
565
|
+
// return (false, motivation);
|
|
566
|
+
|
|
567
|
+
// WARNING! Move this function in models/TiledeskChatbotUtil.js
|
|
568
|
+
}
|
|
569
|
+
|
|
544
570
|
module.exports = { router: router, startApp: startApp};
|
package/package.json
CHANGED
|
@@ -134,10 +134,23 @@ class DirSetAttributeV2 {
|
|
|
134
134
|
attributes.TiledeskString = TiledeskString;
|
|
135
135
|
const result = new TiledeskExpression().evaluateJavascriptExpression(expression, attributes);
|
|
136
136
|
console.log("filling in setattribute, result:", result);
|
|
137
|
-
await
|
|
137
|
+
let destination = await this.fillDestination(action.destination);
|
|
138
|
+
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, destination, result);
|
|
138
139
|
callback();
|
|
139
140
|
}
|
|
140
141
|
|
|
142
|
+
async fillDestination(destination) {
|
|
143
|
+
if (this.tdcache) {
|
|
144
|
+
// console.log("tdcache in setattribute...", this.tdcache);
|
|
145
|
+
const requestAttributes =
|
|
146
|
+
await TiledeskChatbot.allParametersStatic(this.tdcache, this.context.requestId);
|
|
147
|
+
// console.log("requestAttributes in setattribute...", requestAttributes);
|
|
148
|
+
const filler = new Filler();
|
|
149
|
+
destination = filler.fill(destination, requestAttributes);
|
|
150
|
+
console.log("setattribute, final destination:", destination);
|
|
151
|
+
}
|
|
152
|
+
return destination
|
|
153
|
+
}
|
|
141
154
|
async fillValues(operands) {
|
|
142
155
|
// operation: {
|
|
143
156
|
// operators: ["addAsNumber", "subtractAsNumber", "divideAsNumber", "multiplyAsNumber"],
|
|
@@ -30,65 +30,126 @@ class DirWhatsappByAttribute {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
async go(action, callback) {
|
|
33
|
+
|
|
33
34
|
if (this.log) {
|
|
34
35
|
console.log("whatsapp by attributes action: ", JSON.stringify(action))
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
///////////
|
|
39
|
+
|
|
40
|
+
const whatsapp_api_url_pre = process.env.WHATSAPP_ENDPOINT;
|
|
41
|
+
const server_base_url = process.env.API_URL || process.env.API_ENDPOINT;
|
|
42
|
+
|
|
43
|
+
if (whatsapp_api_url_pre) {
|
|
44
|
+
whatsapp_api_url = whatsapp_api_url_pre;
|
|
41
45
|
} else {
|
|
42
|
-
|
|
46
|
+
whatsapp_api_url = server_base_url + "/modules/whatsapp/api"
|
|
47
|
+
}
|
|
48
|
+
console.log("DirWhatsappByAttribute whatsapp_api_url: ", whatsapp_api_url);
|
|
49
|
+
|
|
50
|
+
if (!action.attributeName) {
|
|
51
|
+
console.error("DirWhatsappByAttribute attributeName is mandatory")
|
|
43
52
|
callback();
|
|
44
53
|
return;
|
|
45
54
|
}
|
|
55
|
+
if (this.log) { console.log("DirWhatsappByAttribute attributeName: ", action.attributeName )};
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let attribute_value = null;
|
|
50
|
-
if (this.context.tdcache) {
|
|
57
|
+
const attribute_value = await TiledeskChatbot.getParameterStatic(this.context.tdcache, this.context.requestId, action.attributeName)
|
|
58
|
+
if (this.log) { console.log("attribute_value:", JSON.stringify(attribute_value)); }
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
if (attribute_value == null) {
|
|
61
|
+
console.error("DirWhatsappByAttribute attribute_value is undefined");
|
|
62
|
+
callback();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
console.error("(Tilebot) attribute_value is undefined");
|
|
57
|
-
callback();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
66
|
+
attribute_value.transaction_id = this.context.requestId;
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
method: 'POST'
|
|
69
|
-
};
|
|
70
|
-
let promise = new Promise((resolve, reject) => {
|
|
71
|
-
DirWhatsappByAttribute.myrequest(
|
|
72
|
-
HTTPREQUEST,
|
|
73
|
-
function (err, resbody) {
|
|
74
|
-
if (err) {
|
|
75
|
-
if (callback) {
|
|
76
|
-
callback(err);
|
|
77
|
-
}
|
|
78
|
-
reject(err);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
if (callback) {
|
|
82
|
-
callback(null, resbody);
|
|
83
|
-
}
|
|
84
|
-
console.log("(tybot) broadcast sent: ", resbody);
|
|
85
|
-
resolve(resbody);
|
|
86
|
-
}
|
|
87
|
-
}, true);
|
|
88
|
-
})
|
|
89
|
-
return promise;
|
|
90
|
-
}
|
|
68
|
+
const HTTPREQUEST = {
|
|
69
|
+
url: whatsapp_api_url + "/tiledesk/broadcast",
|
|
70
|
+
headers: {
|
|
71
|
+
'Content-Type': 'application/json'
|
|
72
|
+
},
|
|
73
|
+
json: attribute_value,
|
|
74
|
+
method: 'POST'
|
|
91
75
|
}
|
|
76
|
+
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
DirWhatsappByAttribute.myrequest(
|
|
79
|
+
HTTPREQUEST,
|
|
80
|
+
function (err, resbody) {
|
|
81
|
+
if (err) {
|
|
82
|
+
if (callback) {
|
|
83
|
+
callback(err);
|
|
84
|
+
}
|
|
85
|
+
reject(err);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (callback) {
|
|
89
|
+
callback(null, resbody);
|
|
90
|
+
}
|
|
91
|
+
console.log("(tybot) broadcast sent: ", resbody);
|
|
92
|
+
resolve(resbody);
|
|
93
|
+
}
|
|
94
|
+
}, true);
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
// if (process.env.API_URL) {
|
|
99
|
+
// whatsapp_api_url = "https://tiledesk-whatsapp-connector.giovannitroisi3.repl.co/api";
|
|
100
|
+
// // whatsapp_api_url = process.env.API_URL + "/modules/whatsapp";
|
|
101
|
+
// console.log("(Tilebot) DirWhatsappByAttribute whatsapp_api_url: ", whatsapp_api_url);
|
|
102
|
+
// } else {
|
|
103
|
+
// console.error("(Tilebot) ERROR Missing whatsapp_api_url. Unable to use action WhatsApp By Attributes");
|
|
104
|
+
// callback();
|
|
105
|
+
// return;
|
|
106
|
+
// }
|
|
107
|
+
// if (action.attributeName) {
|
|
108
|
+
// if (this.log) { console.log("whatsapp attributeName:", action.attributeName); }
|
|
109
|
+
// let attribute_value = null;
|
|
110
|
+
// if (this.context.tdcache) {
|
|
111
|
+
|
|
112
|
+
// const attribute_value = await TiledeskChatbot.getParameterStatic(this.context.tdcache, this.context.requestId, action.attributeName)
|
|
113
|
+
// if (this.log) { console.log("attribute_value:", JSON.stringify(attribute_value)); }
|
|
114
|
+
|
|
115
|
+
// if (attribute_value == null) {
|
|
116
|
+
// console.error("(Tilebot) attribute_value is undefined");
|
|
117
|
+
// callback();
|
|
118
|
+
// return;
|
|
119
|
+
// }
|
|
120
|
+
|
|
121
|
+
// const URL = whatsapp_api_url + '/tiledesk/broadcast';
|
|
122
|
+
// const HTTPREQUEST = {
|
|
123
|
+
// url: URL,
|
|
124
|
+
// headers: {
|
|
125
|
+
// 'Content-Type': 'application/json',
|
|
126
|
+
|
|
127
|
+
// },
|
|
128
|
+
// json: attribute_value,
|
|
129
|
+
// method: 'POST'
|
|
130
|
+
// };
|
|
131
|
+
// let promise = new Promise((resolve, reject) => {
|
|
132
|
+
// DirWhatsappByAttribute.myrequest(
|
|
133
|
+
// HTTPREQUEST,
|
|
134
|
+
// function (err, resbody) {
|
|
135
|
+
// if (err) {
|
|
136
|
+
// if (callback) {
|
|
137
|
+
// callback(err);
|
|
138
|
+
// }
|
|
139
|
+
// reject(err);
|
|
140
|
+
// }
|
|
141
|
+
// else {
|
|
142
|
+
// if (callback) {
|
|
143
|
+
// callback(null, resbody);
|
|
144
|
+
// }
|
|
145
|
+
// console.log("(tybot) broadcast sent: ", resbody);
|
|
146
|
+
// resolve(resbody);
|
|
147
|
+
// }
|
|
148
|
+
// }, true);
|
|
149
|
+
// })
|
|
150
|
+
// return promise;
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
92
153
|
}
|
|
93
154
|
|
|
94
155
|
// HTTP REQUEST
|