@tiledesk/tiledesk-tybot-connector 0.2.60-rc1 → 0.2.60
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 +5 -11
- package/models/TiledeskChatbotConst.js +1 -1
- package/models/TiledeskChatbotUtil.js +10 -9
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +0 -28
- package/tiledeskChatbotPlugs/directives/Directives.js +3 -10
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +0 -356
package/CHANGELOG.md
CHANGED
|
@@ -5,13 +5,11 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
-
# v0.2.60
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- Added Brevo Action
|
|
14
|
-
- Added support for DTMF Menu (Reply for voice channel)
|
|
8
|
+
# v0.2.60
|
|
9
|
+
- added flow attributes:
|
|
10
|
+
- lastUserDocumentAsAttachmentURL: Document as a downloadable on click
|
|
11
|
+
- lastUserDocumentAsInlineURL: Document as "view inline" on click
|
|
12
|
+
- flow attribute "strongAuthentication" renamed in "strongAuthenticated"
|
|
15
13
|
|
|
16
14
|
# v0.2.59
|
|
17
15
|
- added flow attribute "strongAuthentication" mapped on request.requester.isAuthenticated (true|false)
|
|
@@ -22,11 +20,7 @@ available on:
|
|
|
22
20
|
- added flow attribute "decodedCustomJWT"
|
|
23
21
|
|
|
24
22
|
# v0.2.57
|
|
25
|
-
- Changed env variables for AskGPT actions
|
|
26
|
-
- Added support for temperature, top_k, max_tokens and context for AskGPTV2 action
|
|
27
|
-
- Added support for context with variables for GptTask action
|
|
28
23
|
- fixed catching reply error in index.js: reply = await chatbot.replyToMessage(message);
|
|
29
|
-
- Added support for DTMF Form and Blind Transfer (Reply for voice channel)
|
|
30
24
|
- Added context and top_k parameter in DirAskGPTV2
|
|
31
25
|
|
|
32
26
|
# v0.2.56
|
|
@@ -21,7 +21,7 @@ class TiledeskChatbotConst {
|
|
|
21
21
|
static REQ_LAST_USER_MESSAGE_KEY = "lastUserMessage";
|
|
22
22
|
static REQ_CHAT_CHANNEL = "chatChannel";
|
|
23
23
|
static REQ_DECODED_JWT_KEY = "decodedCustomJWT";
|
|
24
|
-
static REQ_REQUESTER_IS_AUTHENTICATED_KEY = "
|
|
24
|
+
static REQ_REQUESTER_IS_AUTHENTICATED_KEY = "strongAuthenticated";
|
|
25
25
|
|
|
26
26
|
// static REQ_DEPARTMENT_ID_KEY = "tdDepartmentId";
|
|
27
27
|
// static REQ_PROJECT_ID_KEY = "projectId";
|
|
@@ -494,9 +494,16 @@ class TiledeskChatbotUtil {
|
|
|
494
494
|
// "uid": "lo68oz8i"
|
|
495
495
|
// }
|
|
496
496
|
if (message.metadata.src) {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
497
|
+
await chatbot.addParameter("lastUserDocumentURL", message.metadata.src); // legacy. will be deprecated
|
|
498
|
+
const url_as_attachment = message.metadata.src;
|
|
499
|
+
await chatbot.addParameter("lastUserDocumentAsAttachmentURL", url_as_attachment);
|
|
500
|
+
let url_inline = url_as_attachment;
|
|
501
|
+
if (url_as_attachment.match(/.*\/download.*/)) { // removing "/download" removes the "Content-disposion: attachment" HTTP header
|
|
502
|
+
url_inline = url_as_attachment.replace('/download', '/');
|
|
503
|
+
}
|
|
504
|
+
await chatbot.addParameter("lastUserDocumentAsInlineURL", url_inline);
|
|
505
|
+
await chatbot.addParameter("lastUserDocumentName", message.metadata.name);
|
|
506
|
+
await chatbot.addParameter("lastUserDocumentType", message.metadata.type);
|
|
500
507
|
}
|
|
501
508
|
}
|
|
502
509
|
else {
|
|
@@ -590,12 +597,6 @@ class TiledeskChatbotUtil {
|
|
|
590
597
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.request.department._id);
|
|
591
598
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.request.department.name);
|
|
592
599
|
}
|
|
593
|
-
|
|
594
|
-
if (projectId === "641864da99c1fb00131ba495") {
|
|
595
|
-
console.log("641864da99c1fb00131ba495 > for projectId:", JSON.stringify(message))
|
|
596
|
-
}
|
|
597
|
-
// for BUG
|
|
598
|
-
// if (chatbot.log) {console.log("message.request.attributes.payload", JSON.stringify(message.request.attributes.payload))}
|
|
599
600
|
if (message && message.request && message.request.attributes && message.request.attributes.payload) {
|
|
600
601
|
if (!message.attributes) {
|
|
601
602
|
message.attributes = {}
|
package/package.json
CHANGED
|
@@ -44,7 +44,6 @@ const { DirMake } = require('./directives/DirMake');
|
|
|
44
44
|
const { DirReplaceBotV2 } = require('./directives/DirReplaceBotV2');
|
|
45
45
|
const { DirHubspot } = require('./directives/DirHubspot');
|
|
46
46
|
const { DirCustomerio } = require('./directives/DirCustomerio');
|
|
47
|
-
const { DirBrevo } = require('./directives/DirBrevo');
|
|
48
47
|
const { DirAskGPTV2 } = require('./directives/DirAskGPTV2');
|
|
49
48
|
|
|
50
49
|
class DirectivesChatbotPlug {
|
|
@@ -292,27 +291,6 @@ class DirectivesChatbotPlug {
|
|
|
292
291
|
this.process(next_dir);
|
|
293
292
|
});
|
|
294
293
|
}
|
|
295
|
-
else if (directive_name === Directives.DTMF_FORM) {
|
|
296
|
-
// console.log("...DirReply");
|
|
297
|
-
new DirReply(context).execute(directive, async () => {
|
|
298
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
299
|
-
this.process(next_dir);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
else if (directive_name === Directives.DTMF_MENU) {
|
|
303
|
-
// console.log("...DirReply");
|
|
304
|
-
new DirReply(context).execute(directive, async () => {
|
|
305
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
306
|
-
this.process(next_dir);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
else if (directive_name === Directives.BLIND_TRANSFER) {
|
|
310
|
-
// console.log("...DirReply");
|
|
311
|
-
new DirReply(context).execute(directive, async () => {
|
|
312
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
313
|
-
this.process(next_dir);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
294
|
else if (directive_name === Directives.RANDOM_REPLY) {
|
|
317
295
|
// console.log("...DirRandomReply");
|
|
318
296
|
new DirRandomReply(context).execute(directive, async () => {
|
|
@@ -707,12 +685,6 @@ class DirectivesChatbotPlug {
|
|
|
707
685
|
this.process(next_dir);
|
|
708
686
|
})
|
|
709
687
|
}
|
|
710
|
-
else if (directive_name === Directives.BREVO) {
|
|
711
|
-
new DirBrevo(context).execute(directive, async () => {
|
|
712
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
713
|
-
this.process(next_dir);
|
|
714
|
-
})
|
|
715
|
-
}
|
|
716
688
|
else {
|
|
717
689
|
//console.log("Unhandled Post-message Directive:", directive_name);
|
|
718
690
|
let next_dir = await this.nextDirective(this.directives);
|
|
@@ -27,23 +27,16 @@ class Directives {
|
|
|
27
27
|
static RANDOM_REPLY = 'randomreply';
|
|
28
28
|
static CODE = 'code';
|
|
29
29
|
static WHATSAPP_ATTRIBUTE = 'whatsapp_attribute';
|
|
30
|
-
static FORM = "form";
|
|
31
|
-
static CAPTURE_USER_REPLY = "capture_user_reply";
|
|
32
|
-
static REPLACE_BOT_V2 = "replacebotv2";
|
|
33
|
-
/**** AI ****/
|
|
34
30
|
static ASK_GPT = "askgpt";
|
|
35
31
|
static ASK_GPT_V2 = "askgptv2";
|
|
36
32
|
static GPT_TASK = "gpt_task";
|
|
37
|
-
|
|
33
|
+
static FORM = "form";
|
|
34
|
+
static CAPTURE_USER_REPLY = "capture_user_reply";
|
|
38
35
|
static QAPLA = 'qapla';
|
|
39
36
|
static MAKE = 'make';
|
|
37
|
+
static REPLACE_BOT_V2 = "replacebotv2";
|
|
40
38
|
static HUBSPOT = 'hubspot';
|
|
41
39
|
static CUSTOMERIO = 'customerio';
|
|
42
|
-
static BREVO = 'brevo';
|
|
43
|
-
/**** VOICE CHANNEL ****/
|
|
44
|
-
static DTMF_FORM = 'dtmf_form';
|
|
45
|
-
static DTMF_MENU = 'dtmf_menu';
|
|
46
|
-
static BLIND_TRANSFER = 'blind_transfer';
|
|
47
40
|
|
|
48
41
|
// static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
|
|
49
42
|
// static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require("../../models/TiledeskChatbot");
|
|
3
|
-
const { Filler } = require("../Filler");
|
|
4
|
-
const { DirIntent } = require("./DirIntent");
|
|
5
|
-
let https = require("https");
|
|
6
|
-
require('dotenv').config();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class DirBrevo {
|
|
10
|
-
|
|
11
|
-
constructor(context) {
|
|
12
|
-
if (!context) {
|
|
13
|
-
throw new Error('context object is mandatory');
|
|
14
|
-
}
|
|
15
|
-
this.context = context;
|
|
16
|
-
this.tdcache = this.context.tdcache;
|
|
17
|
-
this.requestId = this.context.requestId;
|
|
18
|
-
this.intentDir = new DirIntent(context);
|
|
19
|
-
this.log = context.log;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
execute(directive, callback) {
|
|
23
|
-
if (this.log) { console.log("DirBrevo directive: ", directive); }
|
|
24
|
-
let action;
|
|
25
|
-
if (directive.action) {
|
|
26
|
-
action = directive.action;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
console.error("DirBrevo Incorrect directive: ", JSON.stringify(directive));
|
|
30
|
-
callback();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this.go(action, (stop) => {
|
|
34
|
-
callback(stop);
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async go(action, callback) {
|
|
39
|
-
if (this.log) { console.log("DirBrevo action:", JSON.stringify(action)); }
|
|
40
|
-
if (!this.tdcache) {
|
|
41
|
-
console.error("Error: DirBrevo tdcache is mandatory");
|
|
42
|
-
callback();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let trueIntent = action.trueIntent;
|
|
47
|
-
let falseIntent = action.falseIntent;
|
|
48
|
-
let trueIntentAttributes = action.trueIntentAttributes;
|
|
49
|
-
let falseIntentAttributes = action.falseIntentAttributes;
|
|
50
|
-
|
|
51
|
-
if (this.log) {
|
|
52
|
-
console.log("DirBrevo trueIntent", trueIntent)
|
|
53
|
-
console.log("DirBrevo falseIntent", falseIntent)
|
|
54
|
-
console.log("DirBrevo trueIntentAttributes", trueIntentAttributes)
|
|
55
|
-
console.log("DirBrevo falseIntentAttributes", falseIntentAttributes)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let requestVariables = null;
|
|
59
|
-
requestVariables =
|
|
60
|
-
await TiledeskChatbot.allParametersStatic(
|
|
61
|
-
this.tdcache, this.requestId
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
//let token = action.token;
|
|
65
|
-
let bodyParameters = action.bodyParameters;
|
|
66
|
-
if (this.log) { console.log("DirBrevo bodyParameters: ", bodyParameters); }
|
|
67
|
-
|
|
68
|
-
if (!bodyParameters || bodyParameters === '') {
|
|
69
|
-
if (this.log) { console.error("DirBrevo ERROR - bodyParameters is undefined or null or empty string") };
|
|
70
|
-
callback();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
75
|
-
const brevo_base_url = process.env.BREVO_ENDPOINT || "https://api.brevo.com/v3"
|
|
76
|
-
if (this.log) {
|
|
77
|
-
console.log("DirBrevo server_base_url ", server_base_url);
|
|
78
|
-
console.log("DirBrevo brevo_base_url ", brevo_base_url);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
let key = await this.getKeyFromIntegrations(server_base_url);
|
|
82
|
-
if (this.log) { console.log('DirBrevo key Debug1: ', key) }
|
|
83
|
-
// ONLY FOR DEBUG CANCELLARE!!!!!
|
|
84
|
-
// if (process.env.BREVO_DEBUG == '1') {
|
|
85
|
-
// key = process.env.BREVO_TOKEN;
|
|
86
|
-
// }
|
|
87
|
-
if (!key) {
|
|
88
|
-
if (this.log) { console.log("DirBrevo - Key not found in Integrations."); }
|
|
89
|
-
if (falseIntent) {
|
|
90
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
91
|
-
callback(true);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const filler = new Filler();
|
|
97
|
-
for (const [key, value] of Object.entries(bodyParameters)) {
|
|
98
|
-
if (this.log) { console.log("bodyParam:", key, "value:", value) }
|
|
99
|
-
let filled_value = filler.fill(value, requestVariables);
|
|
100
|
-
bodyParameters[key] = filled_value;
|
|
101
|
-
}
|
|
102
|
-
if (this.log) { console.log('DirBrevo bodyParameters filler: ', bodyParameters) }
|
|
103
|
-
|
|
104
|
-
// CREATE THE JSON FOR BREVO
|
|
105
|
-
let brevo_email = '';
|
|
106
|
-
let brevo_bodyParameters = {};
|
|
107
|
-
for (const [key, value] of Object.entries(bodyParameters)) {
|
|
108
|
-
if (this.log) { console.log("bodyParam:", key, "value:", value) }
|
|
109
|
-
if (key === 'email') {brevo_email = value}
|
|
110
|
-
else { brevo_bodyParameters[key] = value;}
|
|
111
|
-
}
|
|
112
|
-
if (this.log) { console.log('DirBrevo brevo_email: ', brevo_email) }
|
|
113
|
-
if (this.log) { console.log('DirBrevo brevo_bodyParameters: ', brevo_bodyParameters) }
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let json = {
|
|
117
|
-
email: brevo_email,
|
|
118
|
-
attributes: brevo_bodyParameters,
|
|
119
|
-
"emailBlacklisted": false,
|
|
120
|
-
"smsBlacklisted": false,
|
|
121
|
-
"listIds": [
|
|
122
|
-
0
|
|
123
|
-
],
|
|
124
|
-
"updateEnabled": false,
|
|
125
|
-
"smtpBlacklistSender": [
|
|
126
|
-
"info@mytest.com"
|
|
127
|
-
]
|
|
128
|
-
}
|
|
129
|
-
if (this.log) { console.log('DirBrevo key Debug2: ', key) }
|
|
130
|
-
//----------------
|
|
131
|
-
if (this.log) {console.log("DirBrevo brevo_base_url ",brevo_base_url);}
|
|
132
|
-
if (this.log) { console.log('DirBrevo json: ', json) }
|
|
133
|
-
const BREVO_HTTPREQUEST = {
|
|
134
|
-
url: brevo_base_url + '/contacts',
|
|
135
|
-
headers: {
|
|
136
|
-
'api-key': key,
|
|
137
|
-
'Content-Type': 'application/json',
|
|
138
|
-
'Accept': 'application/json'
|
|
139
|
-
},
|
|
140
|
-
json: json,
|
|
141
|
-
method: "POST"
|
|
142
|
-
}
|
|
143
|
-
if (this.log) { console.log("DirBrevo BREVO_HTTPREQUEST", JSON.stringify(BREVO_HTTPREQUEST)); }
|
|
144
|
-
|
|
145
|
-
this.#myrequest(
|
|
146
|
-
BREVO_HTTPREQUEST, async (err, resbody) => {
|
|
147
|
-
if (err) {
|
|
148
|
-
if (callback) {
|
|
149
|
-
if (this.log) {
|
|
150
|
-
console.error("(httprequest) DirBrevo err response:", err.response)
|
|
151
|
-
console.error("(httprequest) DirBrevo err data:", err.response.data)
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
let result = null;
|
|
155
|
-
let status = null;
|
|
156
|
-
let error;
|
|
157
|
-
|
|
158
|
-
if (err.response &&
|
|
159
|
-
err.response.status) {
|
|
160
|
-
status = err.response.status;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (err.response &&
|
|
164
|
-
err.response.data &&
|
|
165
|
-
err.response.data.message) {
|
|
166
|
-
error = err.response.data.message;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (this.log) {
|
|
170
|
-
console.error("(httprequest) DirBrevo err data result:", result); // CONTROLLA IL VALORE
|
|
171
|
-
console.error("(httprequest) DirBrevo err data status:", status);
|
|
172
|
-
console.error("(httprequest) DirBrevo err data error:", error);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
await this.#assignAttributes(action, status, result, error);
|
|
176
|
-
if (falseIntent) {
|
|
177
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
178
|
-
callback(true);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
callback();
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
} else if (callback) {
|
|
185
|
-
if (this.log) { console.log("DirBrevo resbody: ", JSON.stringify(resbody, null, 2).slice(2, -1)); }
|
|
186
|
-
|
|
187
|
-
let status = 201;
|
|
188
|
-
let error = null;
|
|
189
|
-
let result = JSON.stringify(resbody, null, 2).slice(2, -1);
|
|
190
|
-
await this.#assignAttributes(action, status, result, error);
|
|
191
|
-
if (trueIntent) {
|
|
192
|
-
await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes)
|
|
193
|
-
callback(true);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
callback();
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async #assignAttributes(action, status, result, error) {
|
|
205
|
-
if (this.log) {
|
|
206
|
-
console.log("DirBrevo assignAttributes action:", action)
|
|
207
|
-
console.log("DirBrevo assignAttributes status:", status)
|
|
208
|
-
console.log("DirBrevo assignAttributes result:", result)
|
|
209
|
-
console.log("DirBrevo assignAttributes error:", error)
|
|
210
|
-
}
|
|
211
|
-
if (this.context.tdcache) {
|
|
212
|
-
if (action.assignStatusTo) {
|
|
213
|
-
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
|
|
214
|
-
}
|
|
215
|
-
if (action.assignResultTo) {
|
|
216
|
-
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignResultTo, result);
|
|
217
|
-
}
|
|
218
|
-
if (action.assignErrorTo) {
|
|
219
|
-
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Debug log
|
|
223
|
-
if (this.log) {
|
|
224
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
225
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
226
|
-
if (this.log) { console.log("DirBrevo request parameter:", key, "value:", value, "type:", typeof value) }
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
#myrequest(options, callback) {
|
|
233
|
-
if (this.log) {
|
|
234
|
-
console.log("** API URL:", options.url);
|
|
235
|
-
console.log("** Options:", JSON.stringify(options));
|
|
236
|
-
}
|
|
237
|
-
let axios_options = {
|
|
238
|
-
url: options.url,
|
|
239
|
-
method: options.method,
|
|
240
|
-
params: options.params,
|
|
241
|
-
headers: options.headers
|
|
242
|
-
}
|
|
243
|
-
if (options.json !== null) {
|
|
244
|
-
axios_options.data = options.json
|
|
245
|
-
}
|
|
246
|
-
if (this.log) {
|
|
247
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
248
|
-
}
|
|
249
|
-
if (options.url.startsWith("https:")) {
|
|
250
|
-
const httpsAgent = new https.Agent({
|
|
251
|
-
rejectUnauthorized: false,
|
|
252
|
-
});
|
|
253
|
-
axios_options.httpsAgent = httpsAgent;
|
|
254
|
-
}
|
|
255
|
-
axios(axios_options)
|
|
256
|
-
.then((res) => {
|
|
257
|
-
if (this.log) {
|
|
258
|
-
console.log("Response for url:", options.url);
|
|
259
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
260
|
-
console.log("Response status:", JSON.stringify(res.status));
|
|
261
|
-
}
|
|
262
|
-
if (res && (res.status == 200 || res.status == 201) && res.data) {
|
|
263
|
-
if (callback) {
|
|
264
|
-
callback(null, res.data);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
if (callback) {
|
|
269
|
-
callback(new Error("Response status is not 200"), null);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
})
|
|
273
|
-
.catch((error) => {
|
|
274
|
-
if (callback) {
|
|
275
|
-
callback(error, null);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async #executeCondition(result, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, callback) {
|
|
281
|
-
let trueIntentDirective = null;
|
|
282
|
-
|
|
283
|
-
if (trueIntent) {
|
|
284
|
-
trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
285
|
-
}
|
|
286
|
-
let falseIntentDirective = null;
|
|
287
|
-
if (falseIntent) {
|
|
288
|
-
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
289
|
-
}
|
|
290
|
-
if (this.log) { console.log('DirBrevo executeCondition/result', result) }
|
|
291
|
-
if (result === true) {
|
|
292
|
-
if (trueIntentDirective) {
|
|
293
|
-
this.intentDir.execute(trueIntentDirective, () => {
|
|
294
|
-
if (callback) {
|
|
295
|
-
callback();
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
if (this.log) { console.log("No trueIntentDirective specified"); }
|
|
301
|
-
if (callback) {
|
|
302
|
-
callback();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
if (falseIntentDirective) {
|
|
308
|
-
this.intentDir.execute(falseIntentDirective, () => {
|
|
309
|
-
if (callback) {
|
|
310
|
-
callback();
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
if (this.log) { console.log("No falseIntentDirective specified"); }
|
|
316
|
-
if (callback) {
|
|
317
|
-
callback();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
async getKeyFromIntegrations(server_base_url) {
|
|
324
|
-
return new Promise((resolve) => {
|
|
325
|
-
|
|
326
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
327
|
-
url: server_base_url + "/" + this.context.projectId + "/integration/name/Brevo",
|
|
328
|
-
headers: {
|
|
329
|
-
'Content-Type': 'application/json',
|
|
330
|
-
'Authorization': 'JWT ' + this.context.token
|
|
331
|
-
},
|
|
332
|
-
method: "GET"
|
|
333
|
-
}
|
|
334
|
-
if (this.log) { console.log("Brevo INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
335
|
-
|
|
336
|
-
this.#myrequest(
|
|
337
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
338
|
-
if (err) {
|
|
339
|
-
resolve(null);
|
|
340
|
-
} else {
|
|
341
|
-
|
|
342
|
-
if (integration &&
|
|
343
|
-
integration.value) {
|
|
344
|
-
resolve(integration.value.apikey)
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
resolve(null)
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
})
|
|
351
|
-
})
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
module.exports = { DirBrevo }
|