@tiledesk/tiledesk-tybot-connector 0.2.4 → 0.2.6
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
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
### 0.2.5 - prod debug
|
|
9
|
+
|
|
8
10
|
### 0.2.1 - online
|
|
9
11
|
- bug fix: /ext/parameters/requests/:requestid replies with res.send([]);
|
|
10
12
|
- bug fix: allParameterStatic() => check for attributes not null before iterating Object.entries()
|
|
@@ -22,28 +22,33 @@ class MongodbBotsDataSource {
|
|
|
22
22
|
async getBotByIdCache(botId, tdcache) {
|
|
23
23
|
let bot = null;
|
|
24
24
|
if (tdcache) {
|
|
25
|
+
console.log("getBotByIdCache cache ok");
|
|
25
26
|
let botCacheKey = "cacheman:cachegoose-cache:faq_kbs:id:" + botId;
|
|
26
27
|
try {
|
|
27
28
|
let _bot_as_string = await tdcache.get(botCacheKey);
|
|
28
29
|
const value_type = typeof _bot_as_string;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
console.log("__bot_as_string found in chache:", _bot_as_string);
|
|
31
|
+
// if (this.log) {
|
|
32
|
+
// console.log("__bot_as_string found in chache:", _bot_as_string);
|
|
33
|
+
// console.log("value_type:", value_type);
|
|
34
|
+
// }
|
|
33
35
|
if (_bot_as_string) {
|
|
34
36
|
bot = JSON.parse(_bot_as_string);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
console.log("got bot from cache:", JSON.stringify(bot));
|
|
38
|
+
// if (this.log) {
|
|
39
|
+
// console.log("got bot from cache:", JSON.stringify(bot));
|
|
40
|
+
// }
|
|
38
41
|
}
|
|
39
42
|
else {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
console.log("bot not found, getting from datasource...");
|
|
44
|
+
// if (this.log) {
|
|
45
|
+
// console.log("bot not found, getting from datasource...");
|
|
46
|
+
// }
|
|
43
47
|
bot = await this.getBotById(botId);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
console.log("bot found in datasource:", JSON.stringify(bot));
|
|
49
|
+
// if (this.log) {
|
|
50
|
+
// console.log("bot found in datasource:", JSON.stringify(bot));
|
|
51
|
+
// }
|
|
47
52
|
await tdcache.set(botCacheKey, JSON.stringify(bot));
|
|
48
53
|
// DEBUG CODE REMOVE
|
|
49
54
|
// let bot_ = await tdcache.get(botCacheKey);
|
|
@@ -55,13 +60,13 @@ class MongodbBotsDataSource {
|
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
58
|
-
if (this.log) {
|
|
63
|
+
// if (this.log) {
|
|
59
64
|
console.log("no chache. getting bot from datasource...");
|
|
60
|
-
}
|
|
65
|
+
// }
|
|
61
66
|
bot = await this.getBotById(botId);
|
|
62
|
-
if (this.log) {
|
|
67
|
+
// if (this.log) {
|
|
63
68
|
console.log("bot found in datasource:", JSON.stringify(bot));
|
|
64
|
-
}
|
|
69
|
+
// }
|
|
65
70
|
}
|
|
66
71
|
return bot;
|
|
67
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { Filler } = require('../Filler');
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
3
|
const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
|
|
4
|
+
let axios = require('axios');
|
|
4
5
|
|
|
5
6
|
class DirReply {
|
|
6
7
|
|
|
@@ -97,29 +98,100 @@ class DirReply {
|
|
|
97
98
|
}
|
|
98
99
|
// send!
|
|
99
100
|
if (this.log) {console.log("Reply:", JSON.stringify(message))};
|
|
100
|
-
this.context.tdclient.sendSupportMessage(
|
|
101
|
+
// this.context.tdclient.sendSupportMessage(
|
|
102
|
+
// this.requestId,
|
|
103
|
+
// message,
|
|
104
|
+
// (err) => {
|
|
105
|
+
// if (err) {
|
|
106
|
+
// console.error("Error sending reply:", err.message);
|
|
107
|
+
// }
|
|
108
|
+
// if (this.log) {console.log("Reply message sent.");}
|
|
109
|
+
// callback();
|
|
110
|
+
// });
|
|
111
|
+
|
|
112
|
+
this.sendSupportMessage(
|
|
101
113
|
this.requestId,
|
|
102
114
|
message,
|
|
103
115
|
(err) => {
|
|
104
116
|
if (err) {
|
|
105
117
|
console.error("Error sending reply:", err.message);
|
|
106
118
|
}
|
|
107
|
-
if (this.log) {console.log("Reply message sent.");}
|
|
119
|
+
// if (this.log) {console.log("Reply message sent.");}
|
|
120
|
+
console.log("Reply message sent.");
|
|
108
121
|
callback();
|
|
109
|
-
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
sendSupportMessage(requestId, message, callback) {
|
|
126
|
+
// const jwt_token = TiledeskClient.fixToken(this.token);
|
|
127
|
+
//const url = `${this.APIURL}/${this.projectId}/requests/${requestId}/messages`;
|
|
128
|
+
const url = `${this.context.tdclient.APIURL}/${this.projectId}/requests/${requestId}/messages`
|
|
129
|
+
const HTTPREQUEST = {
|
|
130
|
+
url: url,
|
|
131
|
+
headers: {
|
|
132
|
+
'Content-Type' : 'application/json',
|
|
133
|
+
'Authorization': "JWT " + this.token
|
|
134
|
+
},
|
|
135
|
+
json: message,
|
|
136
|
+
method: 'POST'
|
|
137
|
+
};
|
|
138
|
+
this.myrequest(
|
|
139
|
+
HTTPREQUEST,
|
|
140
|
+
function(err, response, resbody) {
|
|
141
|
+
if (response.status === 200) {
|
|
142
|
+
if (callback) {
|
|
143
|
+
callback(null, resbody)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (callback) {
|
|
147
|
+
callback(err);
|
|
148
|
+
}
|
|
149
|
+
}, this.log
|
|
150
|
+
);
|
|
110
151
|
}
|
|
111
152
|
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// buttons.forEach(button => {
|
|
117
|
-
// if (button.link) {
|
|
118
|
-
// button.link = filler.fill(button.link, variables);
|
|
119
|
-
// }
|
|
120
|
-
// });
|
|
121
|
-
// }
|
|
153
|
+
myrequest(options, callback, log) {
|
|
154
|
+
// if (log) {
|
|
155
|
+
console.log("API URL:", options.url);
|
|
156
|
+
console.log("** Options:", JSON.stringify(options));
|
|
122
157
|
// }
|
|
158
|
+
axios(
|
|
159
|
+
{
|
|
160
|
+
url: options.url,
|
|
161
|
+
method: options.method,
|
|
162
|
+
data: options.json,
|
|
163
|
+
params: options.params,
|
|
164
|
+
headers: options.headers
|
|
165
|
+
})
|
|
166
|
+
.then((res) => {
|
|
167
|
+
// if (log) {
|
|
168
|
+
console.log("Reply: Response for url:", options.url);
|
|
169
|
+
console.log("Reply: Response headers:\n", JSON.stringify(res.headers));
|
|
170
|
+
console.log("Reply: Status:", res.status);
|
|
171
|
+
console.log("Reply: Data:", res.data);
|
|
172
|
+
|
|
173
|
+
//console.log("******** Response for url:", res);
|
|
174
|
+
// }
|
|
175
|
+
if (res && res.status == 200 && res.data) {
|
|
176
|
+
console.error("Status 200 OK");
|
|
177
|
+
if (callback) {
|
|
178
|
+
callback(null, res.data);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (callback) {
|
|
183
|
+
console.error("Status ! 200");
|
|
184
|
+
callback({ message: "Response status not 200" });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
.catch((error) => {
|
|
189
|
+
console.error("An error occurred:", error);
|
|
190
|
+
if (callback) {
|
|
191
|
+
callback(error, null, null);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
123
195
|
|
|
124
196
|
}
|
|
125
197
|
|