@tiledesk/tiledesk-tybot-connector 0.2.139-rc4 → 0.2.139-rc6
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 +2 -5
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +7 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +20 -125
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +162 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -17,11 +17,8 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
-
# v0.2.139-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
# v0.2.139-rc1
|
|
24
|
-
- Improved ReplaceBotV2
|
|
20
|
+
# v0.2.139-rc5
|
|
21
|
+
- Added ReplaceBotV3 action
|
|
25
22
|
|
|
26
23
|
# v0.2.138
|
|
27
24
|
- Bug-fixed: hiddenMessage not blocked
|
package/package.json
CHANGED
|
@@ -53,6 +53,7 @@ const { DirClearTranscript } = require('./directives/DirClearTranscript');
|
|
|
53
53
|
const { DirMoveToUnassigned } = require('./directives/DirMoveToUnassigned');
|
|
54
54
|
const { DirAddTags } = require('./directives/DirAddTags');
|
|
55
55
|
const { DirSendWhatsapp } = require('./directives/DirSendWhatsapp');
|
|
56
|
+
const { DirReplaceBotV3 } = require('./directives/DirReplaceBotV3');
|
|
56
57
|
|
|
57
58
|
class DirectivesChatbotPlug {
|
|
58
59
|
|
|
@@ -489,6 +490,12 @@ class DirectivesChatbotPlug {
|
|
|
489
490
|
this.process(next_dir);
|
|
490
491
|
});
|
|
491
492
|
}
|
|
493
|
+
else if (directive_name === Directives.REPLACE_BOT_V3) {
|
|
494
|
+
new DirReplaceBotV3(context).execute(directive, async () => {
|
|
495
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
496
|
+
this.process(next_dir);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
492
499
|
else if (directive_name === Directives.WAIT) {
|
|
493
500
|
// console.log("........ DirWait");
|
|
494
501
|
new DirWait(context).execute(directive, async () => {
|
|
@@ -2,9 +2,6 @@ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
4
|
|
|
5
|
-
const axios = require("axios").default;
|
|
6
|
-
let https = require("https");
|
|
7
|
-
|
|
8
5
|
class DirReplaceBotV2 {
|
|
9
6
|
|
|
10
7
|
constructor(context) {
|
|
@@ -55,132 +52,30 @@ class DirReplaceBotV2 {
|
|
|
55
52
|
);
|
|
56
53
|
const filler = new Filler();
|
|
57
54
|
botName = filler.fill(botName, variables);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const HTTPREQUEST = {
|
|
67
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + "/replace",
|
|
68
|
-
headers: {
|
|
69
|
-
'Content-Type': 'application/json',
|
|
70
|
-
'Authorization': 'JWT ' + this.context.token
|
|
71
|
-
},
|
|
72
|
-
json: data,
|
|
73
|
-
method: 'PUT'
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.#myrequest(
|
|
77
|
-
HTTPREQUEST, async (err, resbody) => {
|
|
78
|
-
if (err) {
|
|
79
|
-
console.log("DirReplaceBot error: ", err);
|
|
80
|
-
if (callback) {
|
|
81
|
-
callback();
|
|
82
|
-
return;
|
|
55
|
+
this.tdClient.replaceBotByName(this.requestId, botName, () => {
|
|
56
|
+
if (blockName) {
|
|
57
|
+
if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
58
|
+
const message = {
|
|
59
|
+
type: "text",
|
|
60
|
+
text: "/" + blockName,
|
|
61
|
+
attributes : {
|
|
62
|
+
subtype: "info"
|
|
83
63
|
}
|
|
84
64
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
type: "text",
|
|
91
|
-
text: "/" + blockName,
|
|
92
|
-
attributes: {
|
|
93
|
-
subtype: "info"
|
|
65
|
+
this.tdClient.sendSupportMessage(
|
|
66
|
+
this.requestId,
|
|
67
|
+
message, (err) => {
|
|
68
|
+
if (err) {
|
|
69
|
+
console.error("Error sending hidden message:", err.message);
|
|
94
70
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
message, (err) => {
|
|
99
|
-
if (err) {
|
|
100
|
-
console.error("Error sending hidden message:", err.message);
|
|
101
|
-
}
|
|
102
|
-
if (this.log) { console.log("Hidden message sent."); }
|
|
103
|
-
callback();
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
callback();
|
|
108
|
-
}
|
|
71
|
+
if (this.log) {console.log("Hidden message sent.");}
|
|
72
|
+
callback();
|
|
73
|
+
});
|
|
109
74
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
115
|
-
// const message = {
|
|
116
|
-
// type: "text",
|
|
117
|
-
// text: "/" + blockName,
|
|
118
|
-
// attributes : {
|
|
119
|
-
// subtype: "info"
|
|
120
|
-
// }
|
|
121
|
-
// }
|
|
122
|
-
// this.tdClient.sendSupportMessage(
|
|
123
|
-
// this.requestId,
|
|
124
|
-
// message, (err) => {
|
|
125
|
-
// if (err) {
|
|
126
|
-
// console.error("Error sending hidden message:", err.message);
|
|
127
|
-
// }
|
|
128
|
-
// if (this.log) {console.log("Hidden message sent.");}
|
|
129
|
-
// callback();
|
|
130
|
-
// });
|
|
131
|
-
// }
|
|
132
|
-
// else {
|
|
133
|
-
// callback();
|
|
134
|
-
// }
|
|
135
|
-
// });
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
#myrequest(options, callback) {
|
|
139
|
-
if (this.log) {
|
|
140
|
-
console.log("API URL:", options.url);
|
|
141
|
-
console.log("** Options:", JSON.stringify(options));
|
|
142
|
-
}
|
|
143
|
-
let axios_options = {
|
|
144
|
-
url: options.url,
|
|
145
|
-
method: options.method,
|
|
146
|
-
params: options.params,
|
|
147
|
-
headers: options.headers
|
|
148
|
-
}
|
|
149
|
-
if (options.json !== null) {
|
|
150
|
-
axios_options.data = options.json
|
|
151
|
-
}
|
|
152
|
-
if (this.log) {
|
|
153
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
154
|
-
}
|
|
155
|
-
if (options.url.startsWith("https:")) {
|
|
156
|
-
const httpsAgent = new https.Agent({
|
|
157
|
-
rejectUnauthorized: false,
|
|
158
|
-
});
|
|
159
|
-
axios_options.httpsAgent = httpsAgent;
|
|
160
|
-
}
|
|
161
|
-
axios(axios_options)
|
|
162
|
-
.then((res) => {
|
|
163
|
-
if (this.log) {
|
|
164
|
-
console.log("Response for url:", options.url);
|
|
165
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
166
|
-
}
|
|
167
|
-
if (res && res.status == 200 && res.data) {
|
|
168
|
-
if (callback) {
|
|
169
|
-
callback(null, res.data);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
if (callback) {
|
|
174
|
-
callback(new Error("Response status is not 200"), null);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
.catch((error) => {
|
|
179
|
-
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
180
|
-
if (callback) {
|
|
181
|
-
callback(error, null);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
75
|
+
else {
|
|
76
|
+
callback();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
184
79
|
}
|
|
185
80
|
}
|
|
186
81
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
|
+
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
|
+
const { Filler } = require('../Filler');
|
|
4
|
+
|
|
5
|
+
const axios = require("axios").default;
|
|
6
|
+
let https = require("https");
|
|
7
|
+
|
|
8
|
+
class DirReplaceBotV3 {
|
|
9
|
+
|
|
10
|
+
constructor(context) {
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('context object is mandatory.');
|
|
13
|
+
}
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.requestId = context.requestId;
|
|
16
|
+
this.log = context.log;
|
|
17
|
+
|
|
18
|
+
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
19
|
+
this.tdClient = new TiledeskClient({
|
|
20
|
+
projectId: this.context.projectId,
|
|
21
|
+
token: this.context.token,
|
|
22
|
+
APIURL: this.API_ENDPOINT,
|
|
23
|
+
APIKEY: "___",
|
|
24
|
+
log: this.log
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
execute(directive, callback) {
|
|
29
|
+
if (this.log) {console.log("Replacing bot");}
|
|
30
|
+
let action;
|
|
31
|
+
if (directive.action) {
|
|
32
|
+
action = directive.action;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.error("DirReplaceBot Incorrect directive: ", JSON.stringify(directive));
|
|
36
|
+
callback();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.go(action, () => {
|
|
40
|
+
callback();
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async go(action, callback) {
|
|
45
|
+
let botName = action.botName;
|
|
46
|
+
let botSlug = action.botSlug;
|
|
47
|
+
let useSlug = action.useSlug;
|
|
48
|
+
let blockName = action.blockName;
|
|
49
|
+
let variables = null;
|
|
50
|
+
variables =
|
|
51
|
+
await TiledeskChatbot.allParametersStatic(
|
|
52
|
+
this.context.tdcache, this.context.requestId
|
|
53
|
+
);
|
|
54
|
+
const filler = new Filler();
|
|
55
|
+
botName = filler.fill(botName, variables);
|
|
56
|
+
botSlug = filler.fill(botSlug, variables);
|
|
57
|
+
|
|
58
|
+
let data = {};
|
|
59
|
+
if (useSlug && useSlug === true) {
|
|
60
|
+
data.slug = botSlug;
|
|
61
|
+
} else {
|
|
62
|
+
data.name = botName;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const HTTPREQUEST = {
|
|
66
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + "/replace",
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
'Authorization': 'JWT ' + this.context.token
|
|
70
|
+
},
|
|
71
|
+
json: data,
|
|
72
|
+
method: 'PUT'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.#myrequest(
|
|
76
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
77
|
+
if (err) {
|
|
78
|
+
console.log("DirReplaceBot error: ", err);
|
|
79
|
+
if (callback) {
|
|
80
|
+
callback();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.log) { console.log("DirReplaceBot replace resbody: ", resbody) };
|
|
86
|
+
if (blockName) {
|
|
87
|
+
if (this.log) { console.log("Sending hidden /start message to bot in dept"); }
|
|
88
|
+
const message = {
|
|
89
|
+
type: "text",
|
|
90
|
+
text: "/" + blockName,
|
|
91
|
+
attributes: {
|
|
92
|
+
subtype: "info"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.tdClient.sendSupportMessage(
|
|
96
|
+
this.requestId,
|
|
97
|
+
message, (err) => {
|
|
98
|
+
if (err) {
|
|
99
|
+
console.error("Error sending hidden message:", err.message);
|
|
100
|
+
}
|
|
101
|
+
if (this.log) { console.log("Hidden message sent."); }
|
|
102
|
+
callback();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
callback();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#myrequest(options, callback) {
|
|
113
|
+
if (this.log) {
|
|
114
|
+
console.log("API URL:", options.url);
|
|
115
|
+
console.log("** Options:", JSON.stringify(options));
|
|
116
|
+
}
|
|
117
|
+
let axios_options = {
|
|
118
|
+
url: options.url,
|
|
119
|
+
method: options.method,
|
|
120
|
+
params: options.params,
|
|
121
|
+
headers: options.headers
|
|
122
|
+
}
|
|
123
|
+
if (options.json !== null) {
|
|
124
|
+
axios_options.data = options.json
|
|
125
|
+
}
|
|
126
|
+
if (this.log) {
|
|
127
|
+
console.log("axios_options:", JSON.stringify(axios_options));
|
|
128
|
+
}
|
|
129
|
+
if (options.url.startsWith("https:")) {
|
|
130
|
+
const httpsAgent = new https.Agent({
|
|
131
|
+
rejectUnauthorized: false,
|
|
132
|
+
});
|
|
133
|
+
axios_options.httpsAgent = httpsAgent;
|
|
134
|
+
}
|
|
135
|
+
axios(axios_options)
|
|
136
|
+
.then((res) => {
|
|
137
|
+
if (this.log) {
|
|
138
|
+
console.log("Response for url:", options.url);
|
|
139
|
+
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
140
|
+
}
|
|
141
|
+
if (res && res.status == 200 && res.data) {
|
|
142
|
+
if (callback) {
|
|
143
|
+
callback(null, res.data);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
if (callback) {
|
|
148
|
+
callback(new Error("Response status is not 200"), null);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
.catch((error) => {
|
|
153
|
+
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
154
|
+
if (callback) {
|
|
155
|
+
callback(error, null);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = { DirReplaceBotV3 };
|
|
@@ -31,6 +31,7 @@ class Directives {
|
|
|
31
31
|
static FORM = "form";
|
|
32
32
|
static CAPTURE_USER_REPLY = "capture_user_reply";
|
|
33
33
|
static REPLACE_BOT_V2 = "replacebotv2";
|
|
34
|
+
static REPLACE_BOT_V3 = "replacebotv3";
|
|
34
35
|
/**** AI ****/
|
|
35
36
|
static ASK_GPT = "askgpt";
|
|
36
37
|
static ASK_GPT_V2 = "askgptv2";
|