@tiledesk/tiledesk-tybot-connector 0.4.2 → 0.5.0-rc2
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 +28 -0
- package/ExtApi.js +3 -13
- package/ExtUtil.js +0 -1
- package/Logger.js +86 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/index.js +87 -273
- package/logs/app.log +12983 -275
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +28864 -0
- package/models/IntentForm.js +30 -44
- package/models/IntentsMachineFactory.js +4 -3
- package/models/MockBotsDataSource.js +1 -17
- package/models/MockTdCache.js +0 -9
- package/models/MongodbBotsDataSource.js +29 -53
- package/models/MongodbIntentsMachine.js +5 -4
- package/models/TiledeskChatbot.js +79 -258
- package/models/TiledeskChatbotConst.js +9 -0
- package/models/TiledeskChatbotUtil.js +180 -232
- package/models/TiledeskIntentsMachine.js +5 -14
- package/models/faqKbService.js +0 -1
- package/package.json +5 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
- package/tiledeskChatbotPlugs/Filler.js +0 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
- package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
- package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
- package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
- package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirForm.js +15 -22
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
- package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
- package/utils/winston.js +42 -0
- package/TdCache copy.js +0 -242
|
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
|
3
3
|
const { DirIntent } = require('./DirIntent');
|
|
4
4
|
const { IntentForm } = require('../../models/IntentForm.js');
|
|
5
5
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
6
|
+
const winston = require('../../utils/winston');
|
|
6
7
|
|
|
7
8
|
class DirForm {
|
|
8
9
|
constructor(context) {
|
|
@@ -28,17 +29,17 @@ class DirForm {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
execute(directive, callback) {
|
|
32
|
+
winston.verbose("Execute Form directive");
|
|
31
33
|
let action;
|
|
32
34
|
if (directive.action) {
|
|
33
35
|
action = directive.action;
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
|
-
|
|
38
|
+
winston.warn("DirForm Incorrect directive: ", directive);
|
|
37
39
|
callback();
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
42
|
this.go(action, (stop) => {
|
|
41
|
-
if (this.log) {console.log("(DirForm, stop?", stop); }
|
|
42
43
|
callback(stop);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -72,18 +73,15 @@ class DirForm {
|
|
|
72
73
|
const trueIntent = action.trueIntent; // edit-end (success)
|
|
73
74
|
const falseIntent = action.falseIntent; // cancel
|
|
74
75
|
let form = action.form;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
76
|
+
winston.debug("(DirForm) IntentForm.isValidForm(intent_form) " + IntentForm.isValidForm(form));
|
|
77
|
+
|
|
78
78
|
let clientUpdateUserFullname = null;
|
|
79
79
|
if (IntentForm.isValidForm(form)) {
|
|
80
80
|
await this.chatbot.lockAction(this.requestId, action.action_id);
|
|
81
81
|
const user_reply = message.text;
|
|
82
82
|
let form_reply = await this.execIntentForm(user_reply, form);
|
|
83
|
-
// console.log("got form reply", form_reply)
|
|
84
83
|
if (!form_reply.canceled && form_reply.message) {
|
|
85
|
-
|
|
86
|
-
if (this.log) {console.log("Sending form reply...", form_reply.message)}
|
|
84
|
+
winston.debug("(DirForm) Sending form reply...", form_reply.message)
|
|
87
85
|
// reply with this message (ex. please enter your fullname)
|
|
88
86
|
if (!form_reply.message.attributes) {
|
|
89
87
|
form_reply.message.attributes = {}
|
|
@@ -98,18 +96,17 @@ class DirForm {
|
|
|
98
96
|
form_reply.message,
|
|
99
97
|
(err) => {
|
|
100
98
|
if (err) {
|
|
101
|
-
|
|
99
|
+
winston.error("(DirForm) Error sending form reply: " + err.message);
|
|
102
100
|
}
|
|
103
|
-
|
|
101
|
+
winston.debug("(DirForm) Form reply message sent.");
|
|
104
102
|
callback(true);
|
|
105
103
|
});
|
|
106
104
|
}
|
|
107
105
|
else if (form_reply.end) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
106
|
+
winston.debug("(DirForm) FORM end.", );
|
|
107
|
+
winston.debug("(DirForm) unlocking intent for request: " + this.requestId);
|
|
108
|
+
winston.debug("(DirForm) populate data on lead: ", lead);
|
|
109
|
+
|
|
113
110
|
this.chatbot.unlockAction(this.requestId);
|
|
114
111
|
|
|
115
112
|
if (callback) {
|
|
@@ -121,16 +118,13 @@ class DirForm {
|
|
|
121
118
|
// if (lead) {
|
|
122
119
|
// this.populatePrechatFormAndLead(lead._id, this.requestId);
|
|
123
120
|
// }
|
|
124
|
-
// else {
|
|
125
|
-
// if (this.log) {console.log("No lead. Skipping populatePrechatFormAndLead()");}
|
|
126
|
-
// }
|
|
127
121
|
// const all_parameters = await this.chatbot.allParameters();
|
|
128
122
|
// if (all_parameters && all_parameters["userFullname"]) {
|
|
129
123
|
// clientUpdateUserFullname = all_parameters["userFullname"];
|
|
130
124
|
// }
|
|
131
125
|
}
|
|
132
126
|
else if (form_reply.canceled) {
|
|
133
|
-
|
|
127
|
+
winston.debug("(DirForm) unlocking intent due to canceling, for request " + this.requestId);
|
|
134
128
|
this.unlockAction(this.requestId);
|
|
135
129
|
|
|
136
130
|
// TODO: INVOKE DIR_INTENT FOR CANCEL.
|
|
@@ -140,7 +134,6 @@ class DirForm {
|
|
|
140
134
|
});
|
|
141
135
|
}
|
|
142
136
|
|
|
143
|
-
// if (this.log) {console.log("sending form 'cancel' reply...", form_reply.message)}
|
|
144
137
|
// TODO: REMOVE CANCEL REPLY
|
|
145
138
|
// reply with this message (ex. please enter your fullname)
|
|
146
139
|
// if (!form_reply.message.attributes) {
|
|
@@ -174,7 +167,7 @@ class DirForm {
|
|
|
174
167
|
});
|
|
175
168
|
}
|
|
176
169
|
else {
|
|
177
|
-
|
|
170
|
+
winston.debug("(DirForm) No trueIntentDirective specified");
|
|
178
171
|
callback();
|
|
179
172
|
}
|
|
180
173
|
}
|
|
@@ -185,7 +178,7 @@ class DirForm {
|
|
|
185
178
|
});
|
|
186
179
|
}
|
|
187
180
|
else {
|
|
188
|
-
|
|
181
|
+
winston.debug("(DirForm) No falseIntentDirective specified");
|
|
189
182
|
callback();
|
|
190
183
|
}
|
|
191
184
|
}
|
|
@@ -6,6 +6,7 @@ const { DirIntent } = require("./DirIntent");
|
|
|
6
6
|
const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
|
|
7
7
|
const { TiledeskChatbotUtil } = require("../../models/TiledeskChatbotUtil");
|
|
8
8
|
require('dotenv').config();
|
|
9
|
+
const winston = require('../../utils/winston');
|
|
9
10
|
|
|
10
11
|
class DirGptTask {
|
|
11
12
|
|
|
@@ -23,13 +24,13 @@ class DirGptTask {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
execute(directive, callback) {
|
|
26
|
-
|
|
27
|
+
winston.verbose("Execute GptTask directive");
|
|
27
28
|
let action;
|
|
28
29
|
if (directive.action) {
|
|
29
30
|
action = directive.action;
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
|
-
|
|
33
|
+
winston.warn("DirGptTask Incorrect directive: ", directive);
|
|
33
34
|
callback();
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
@@ -39,9 +40,9 @@ class DirGptTask {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
async go(action, callback) {
|
|
42
|
-
|
|
43
|
+
winston.debug("(DirGptTask) Action: ", action);
|
|
43
44
|
if (!this.tdcache) {
|
|
44
|
-
|
|
45
|
+
winston.error("(DirGptTask) Error: tdcache is mandatory");
|
|
45
46
|
callback();
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
@@ -53,19 +54,17 @@ class DirGptTask {
|
|
|
53
54
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
54
55
|
let transcript;
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
console.log("DirGptTask falseIntentAttributes", falseIntentAttributes)
|
|
61
|
-
}
|
|
57
|
+
winston.debug("(DirGptTask) trueIntent " + trueIntent)
|
|
58
|
+
winston.debug("(DirGptTask) falseIntent " + falseIntent)
|
|
59
|
+
winston.debug("(DirGptTask) trueIntentAttributes " + trueIntentAttributes)
|
|
60
|
+
winston.debug("(DirGptTask) falseIntentAttributes " + falseIntentAttributes)
|
|
62
61
|
|
|
63
62
|
// default value
|
|
64
63
|
let answer = "No answer.";
|
|
65
64
|
let model = "gpt-3.5-turbo";
|
|
66
65
|
|
|
67
66
|
if (!action.question || action.question === '') {
|
|
68
|
-
|
|
67
|
+
winston.debug("(DirGptTask) Error: question attribute is mandatory. Executing condition false...")
|
|
69
68
|
if (falseIntent) {
|
|
70
69
|
await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
|
|
71
70
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -93,43 +92,41 @@ class DirGptTask {
|
|
|
93
92
|
model = action.model;
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.log("DirGptTask temperature: ", temperature);
|
|
99
|
-
}
|
|
95
|
+
winston.debug("(DirGptTask) max_tokens: " + max_tokens);
|
|
96
|
+
winston.debug("(DirGptTask) temperature: " + temperature);
|
|
100
97
|
|
|
101
98
|
if (action.history) {
|
|
102
99
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
103
100
|
this.context.tdcache,
|
|
104
101
|
this.context.requestId,
|
|
105
102
|
TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
|
|
106
|
-
|
|
103
|
+
winston.debug("(DirGptTask) transcript string: " + transcript_string)
|
|
107
104
|
|
|
108
105
|
if (transcript_string) {
|
|
109
106
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
110
|
-
|
|
107
|
+
winston.debug("(DirGptTask) transcript: ", transcript)
|
|
111
108
|
} else {
|
|
112
|
-
|
|
109
|
+
winston.debug("(DirGptTask) transcript_string is undefined. Skip JSON translation for chat history");
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
117
|
-
|
|
114
|
+
winston.debug("(DirGptTask) openai_url " + openai_url);
|
|
118
115
|
|
|
119
116
|
let key = await this.getKeyFromIntegrations();
|
|
120
117
|
if (!key) {
|
|
121
|
-
|
|
118
|
+
winston.debug("(DirGptTask) - Key not found in Integrations. Searching in kb settings...");
|
|
122
119
|
key = await this.getKeyFromKbSettings();
|
|
123
120
|
}
|
|
124
121
|
|
|
125
122
|
if (!key) {
|
|
126
|
-
|
|
123
|
+
winston.debug("(DirGptTask) - Retrieve public gptkey")
|
|
127
124
|
key = process.env.GPTKEY;
|
|
128
125
|
publicKey = true;
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
if (!key) {
|
|
132
|
-
|
|
129
|
+
winston.error("(DirGptTask) gptkey is mandatory");
|
|
133
130
|
await this.#assignAttributes(action, answer);
|
|
134
131
|
if (falseIntent) {
|
|
135
132
|
await this.chatbot.addParameter("flowError", "GPT Error: gpt apikey is undefined");
|
|
@@ -144,7 +141,7 @@ class DirGptTask {
|
|
|
144
141
|
if (publicKey === true) {
|
|
145
142
|
let keep_going = await this.checkQuoteAvailability();
|
|
146
143
|
if (keep_going === false) {
|
|
147
|
-
|
|
144
|
+
|
|
148
145
|
await this.chatbot.addParameter("flowError", "GPT Error: tokens quota exceeded");
|
|
149
146
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
150
147
|
callback();
|
|
@@ -183,7 +180,7 @@ class DirGptTask {
|
|
|
183
180
|
}
|
|
184
181
|
}
|
|
185
182
|
|
|
186
|
-
|
|
183
|
+
winston.debug("(DirGptTask) json: ", json)
|
|
187
184
|
|
|
188
185
|
const HTTPREQUEST = {
|
|
189
186
|
url: openai_url,
|
|
@@ -194,14 +191,12 @@ class DirGptTask {
|
|
|
194
191
|
json: json,
|
|
195
192
|
method: 'POST'
|
|
196
193
|
}
|
|
197
|
-
|
|
194
|
+
winston.debug("(DirGptTask) HttpRequest: ", HTTPREQUEST);
|
|
198
195
|
this.#myrequest(
|
|
199
196
|
HTTPREQUEST, async (err, resbody) => {
|
|
200
197
|
if (err) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
console.error("(httprequest) DirGptTask openai err:", err.response?.data?.error?.message);
|
|
204
|
-
}
|
|
198
|
+
winston.debug("(DirGptTask) openai err: ", err);
|
|
199
|
+
winston.debug("(DirGptTask) openai err: " + err.response?.data?.error?.message);
|
|
205
200
|
await this.#assignAttributes(action, answer);
|
|
206
201
|
if (falseIntent) {
|
|
207
202
|
await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
|
|
@@ -212,7 +207,7 @@ class DirGptTask {
|
|
|
212
207
|
callback();
|
|
213
208
|
return;
|
|
214
209
|
} else {
|
|
215
|
-
|
|
210
|
+
winston.debug("(DirGptTask) resbody: ", resbody);
|
|
216
211
|
answer = resbody.choices[0].message.content;
|
|
217
212
|
|
|
218
213
|
if (action.formatType === 'json_object' || action.formatType === undefined || action.formatType === null) {
|
|
@@ -274,7 +269,7 @@ class DirGptTask {
|
|
|
274
269
|
})
|
|
275
270
|
}
|
|
276
271
|
else {
|
|
277
|
-
|
|
272
|
+
winston.debug("(DirGptTask) No trueIntentDirective specified");
|
|
278
273
|
if (callback) {
|
|
279
274
|
callback();
|
|
280
275
|
}
|
|
@@ -289,7 +284,7 @@ class DirGptTask {
|
|
|
289
284
|
});
|
|
290
285
|
}
|
|
291
286
|
else {
|
|
292
|
-
|
|
287
|
+
winston.debug("(DirGptTask) No falseIntentDirective specified");
|
|
293
288
|
if (callback) {
|
|
294
289
|
callback();
|
|
295
290
|
}
|
|
@@ -298,29 +293,17 @@ class DirGptTask {
|
|
|
298
293
|
}
|
|
299
294
|
|
|
300
295
|
async #assignAttributes(action, answer) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
296
|
+
winston.debug("(DirGptTask) assignAttributes action: ", action)
|
|
297
|
+
winston.debug("(DirGptTask) assignAttributes answer: " + answer)
|
|
298
|
+
|
|
305
299
|
if (this.context.tdcache) {
|
|
306
300
|
if (action.assignReplyTo && answer) {
|
|
307
301
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
308
302
|
}
|
|
309
|
-
// Debug log
|
|
310
|
-
if (this.log) {
|
|
311
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
312
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
313
|
-
if (this.log) { console.log("(gpttask) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
303
|
}
|
|
317
304
|
}
|
|
318
305
|
|
|
319
306
|
#myrequest(options, callback) {
|
|
320
|
-
if (this.log) {
|
|
321
|
-
console.log("API URL:", options.url);
|
|
322
|
-
console.log("** Options:", JSON.stringify(options));
|
|
323
|
-
}
|
|
324
307
|
let axios_options = {
|
|
325
308
|
url: options.url,
|
|
326
309
|
method: options.method,
|
|
@@ -330,9 +313,6 @@ class DirGptTask {
|
|
|
330
313
|
if (options.json !== null) {
|
|
331
314
|
axios_options.data = options.json
|
|
332
315
|
}
|
|
333
|
-
if (this.log) {
|
|
334
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
335
|
-
}
|
|
336
316
|
if (options.url.startsWith("https:")) {
|
|
337
317
|
const httpsAgent = new https.Agent({
|
|
338
318
|
rejectUnauthorized: false,
|
|
@@ -341,10 +321,6 @@ class DirGptTask {
|
|
|
341
321
|
}
|
|
342
322
|
axios(axios_options)
|
|
343
323
|
.then((res) => {
|
|
344
|
-
if (this.log) {
|
|
345
|
-
console.log("Response for url:", options.url);
|
|
346
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
347
|
-
}
|
|
348
324
|
if (res && res.status == 200 && res.data) {
|
|
349
325
|
if (callback) {
|
|
350
326
|
callback(null, res.data);
|
|
@@ -357,7 +333,7 @@ class DirGptTask {
|
|
|
357
333
|
}
|
|
358
334
|
})
|
|
359
335
|
.catch((error) => {
|
|
360
|
-
|
|
336
|
+
winston.error("(DirGptTask) Axios error: ", JSON.stringify(error));
|
|
361
337
|
if (callback) {
|
|
362
338
|
callback(error, null);
|
|
363
339
|
}
|
|
@@ -375,7 +351,7 @@ class DirGptTask {
|
|
|
375
351
|
},
|
|
376
352
|
method: "GET"
|
|
377
353
|
}
|
|
378
|
-
|
|
354
|
+
winston.debug("(DirGptTask) Integrations HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
379
355
|
|
|
380
356
|
this.#myrequest(
|
|
381
357
|
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
@@ -406,15 +382,12 @@ class DirGptTask {
|
|
|
406
382
|
},
|
|
407
383
|
method: "GET"
|
|
408
384
|
}
|
|
409
|
-
|
|
385
|
+
winston.debug("(DirGptTask) KB HttpRequest ", KB_HTTPREQUEST);
|
|
410
386
|
|
|
411
387
|
this.#myrequest(
|
|
412
388
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
413
389
|
if (err) {
|
|
414
|
-
|
|
415
|
-
if (this.log) {
|
|
416
|
-
console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
|
|
417
|
-
}
|
|
390
|
+
winston.error("(DirGptTask) Get KnowledgeBase err:", err.message);
|
|
418
391
|
resolve(null);
|
|
419
392
|
} else {
|
|
420
393
|
if (!resbody.gptkey) {
|
|
@@ -439,7 +412,7 @@ class DirGptTask {
|
|
|
439
412
|
},
|
|
440
413
|
method: "GET"
|
|
441
414
|
}
|
|
442
|
-
|
|
415
|
+
winston.debug("(DirGptTask) check quote availability HttpRequest ", HTTPREQUEST);
|
|
443
416
|
|
|
444
417
|
this.#myrequest(
|
|
445
418
|
HTTPREQUEST, async (err, resbody) => {
|
|
@@ -469,15 +442,15 @@ class DirGptTask {
|
|
|
469
442
|
json: tokens_usage,
|
|
470
443
|
method: "POST"
|
|
471
444
|
}
|
|
472
|
-
|
|
445
|
+
winston.debug("(DirGptTask) update quote HttpRequest ", HTTPREQUEST);
|
|
473
446
|
|
|
474
447
|
this.#myrequest(
|
|
475
448
|
HTTPREQUEST, async (err, resbody) => {
|
|
476
449
|
if (err) {
|
|
477
|
-
|
|
450
|
+
winston.debug("(DirGptTask) Increment tokens quote err: ", err);
|
|
478
451
|
reject(false)
|
|
479
452
|
} else {
|
|
480
|
-
|
|
453
|
+
winston.debug("(DirGptTask) Increment token quote resbody: ", resbody);
|
|
481
454
|
resolve(true);
|
|
482
455
|
}
|
|
483
456
|
}
|
|
@@ -4,7 +4,7 @@ const { Filler } = require("../Filler");
|
|
|
4
4
|
const { DirIntent } = require("./DirIntent");
|
|
5
5
|
let https = require("https");
|
|
6
6
|
require('dotenv').config();
|
|
7
|
-
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
8
|
|
|
9
9
|
class DirHubspot {
|
|
10
10
|
|
|
@@ -21,13 +21,13 @@ class DirHubspot {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
execute(directive, callback) {
|
|
24
|
-
|
|
24
|
+
winston.verbose("Execute Hubspot directive");
|
|
25
25
|
let action;
|
|
26
26
|
if (directive.action) {
|
|
27
27
|
action = directive.action;
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
|
|
30
|
+
winston.warn("DirHubspot Incorrect directive: ", directive);
|
|
31
31
|
callback();
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -37,9 +37,9 @@ class DirHubspot {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
async go(action, callback) {
|
|
40
|
-
|
|
40
|
+
winston.debug("(DirHubspot) Action: ", action);
|
|
41
41
|
if (!this.tdcache) {
|
|
42
|
-
|
|
42
|
+
winston.error("(DirHubspot) Error: tdcache is mandatory");
|
|
43
43
|
callback();
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
@@ -49,12 +49,10 @@ class DirHubspot {
|
|
|
49
49
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
50
50
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.log("DirAskGPT falseIntentAttributes", falseIntentAttributes)
|
|
57
|
-
}
|
|
52
|
+
winston.debug("(DirHubspot) trueIntent " + trueIntent)
|
|
53
|
+
winston.debug("(DirHubspot) falseIntent " + falseIntent)
|
|
54
|
+
winston.debug("(DirHubspot) trueIntentAttributes " + trueIntentAttributes)
|
|
55
|
+
winston.debug("(DirHubspot) falseIntentAttributes " + falseIntentAttributes)
|
|
58
56
|
|
|
59
57
|
let requestVariables = null;
|
|
60
58
|
requestVariables =
|
|
@@ -64,20 +62,20 @@ class DirHubspot {
|
|
|
64
62
|
|
|
65
63
|
//let token = action.token;
|
|
66
64
|
let bodyParameters = action.bodyParameters;
|
|
67
|
-
|
|
65
|
+
winston.debug("(DirHubspot) bodyParameters: ", bodyParameters);
|
|
68
66
|
|
|
69
67
|
if (!bodyParameters || bodyParameters === '') {
|
|
70
|
-
|
|
68
|
+
winston.error("(DirHubspot) Error: bodyParameters is undefined or null or empty string");
|
|
71
69
|
callback();
|
|
72
70
|
return;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
const hubspot_base_url = process.env.HUBSPOT_ENDPOINT || "https://api.hubapi.com/crm/v3/";
|
|
76
|
-
|
|
74
|
+
winston.debug("(DirHubspot) hubspot_base_url " + hubspot_base_url);
|
|
77
75
|
|
|
78
76
|
let key = await this.getKeyFromIntegrations();
|
|
79
77
|
if (!key) {
|
|
80
|
-
|
|
78
|
+
winston.debug("(DirHubspot) - Key not found in Integrations.");
|
|
81
79
|
if (falseIntent) {
|
|
82
80
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
83
81
|
callback(true);
|
|
@@ -87,11 +85,10 @@ class DirHubspot {
|
|
|
87
85
|
|
|
88
86
|
const filler = new Filler();
|
|
89
87
|
for (const [key, value] of Object.entries(bodyParameters)) {
|
|
90
|
-
if (this.log) { console.log("bodyParam:", key, "value:", value) }
|
|
91
88
|
let filled_value = filler.fill(value, requestVariables);
|
|
92
89
|
bodyParameters[key] = filled_value;
|
|
93
90
|
}
|
|
94
|
-
|
|
91
|
+
winston.debug("(DirHubspot) bodyParameters filled: ", bodyParameters);
|
|
95
92
|
|
|
96
93
|
let json = {
|
|
97
94
|
inputs: [
|
|
@@ -107,17 +104,13 @@ class DirHubspot {
|
|
|
107
104
|
json: json,
|
|
108
105
|
method: "POST"
|
|
109
106
|
}
|
|
110
|
-
|
|
107
|
+
winston.debug("(DirHubspot) HttpRequest ", HUBSPOT_HTTPREQUEST);
|
|
111
108
|
|
|
112
109
|
this.#myrequest(
|
|
113
110
|
HUBSPOT_HTTPREQUEST, async (err, resbody) => {
|
|
114
111
|
if (err) {
|
|
115
112
|
if (callback) {
|
|
116
|
-
|
|
117
|
-
console.error("(httprequest) DirHubspot err response:", err.response)
|
|
118
|
-
console.error("(httprequest) DirHubspot err data:", err.response.data)
|
|
119
|
-
};
|
|
120
|
-
|
|
113
|
+
winston.error("(DirHubspot) err response: ", err.response.data)
|
|
121
114
|
let result = null;
|
|
122
115
|
let status = null;
|
|
123
116
|
let error;
|
|
@@ -133,11 +126,9 @@ class DirHubspot {
|
|
|
133
126
|
error = err.response.data.message;
|
|
134
127
|
}
|
|
135
128
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
console.error("(httprequest) DirHubspot err data error:", error);
|
|
140
|
-
}
|
|
129
|
+
winston.debug("(DirHubspot) err data result: " + result);
|
|
130
|
+
winston.debug("(DirHubspot) err data status: " + status);
|
|
131
|
+
winston.debug("(DirHubspot) err data error: ", error);
|
|
141
132
|
|
|
142
133
|
await this.#assignAttributes(action, status, result, error);
|
|
143
134
|
if (falseIntent) {
|
|
@@ -149,7 +140,7 @@ class DirHubspot {
|
|
|
149
140
|
return;
|
|
150
141
|
}
|
|
151
142
|
} else if (callback) {
|
|
152
|
-
|
|
143
|
+
winston.debug("(DirHubspot) resbody: ", resbody);
|
|
153
144
|
|
|
154
145
|
let status = 201;
|
|
155
146
|
let error = null;
|
|
@@ -169,12 +160,10 @@ class DirHubspot {
|
|
|
169
160
|
}
|
|
170
161
|
|
|
171
162
|
async #assignAttributes(action, status, result, error) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
console.log("DirHubspot assignAttributes error:", error)
|
|
177
|
-
}
|
|
163
|
+
winston.debug("(DirHubspot) assignAttributes action: ", action)
|
|
164
|
+
winston.debug("(DirHubspot) assignAttributes status: " + status)
|
|
165
|
+
winston.debug("(DirHubspot) assignAttributes result: ", result)
|
|
166
|
+
winston.debug("(DirHubspot) assignAttributes error: ", error)
|
|
178
167
|
if (this.context.tdcache) {
|
|
179
168
|
if (action.assignStatusTo) {
|
|
180
169
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
|
|
@@ -185,22 +174,10 @@ class DirHubspot {
|
|
|
185
174
|
if (action.assignErrorTo) {
|
|
186
175
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
|
|
187
176
|
}
|
|
188
|
-
|
|
189
|
-
// Debug log
|
|
190
|
-
if (this.log) {
|
|
191
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
192
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
193
|
-
if (this.log) { console.log("DirHubspot request parameter:", key, "value:", value, "type:", typeof value) }
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
177
|
}
|
|
197
178
|
}
|
|
198
179
|
|
|
199
180
|
#myrequest(options, callback) {
|
|
200
|
-
if (this.log) {
|
|
201
|
-
console.log("** API URL:", options.url);
|
|
202
|
-
console.log("** Options:", JSON.stringify(options));
|
|
203
|
-
}
|
|
204
181
|
let axios_options = {
|
|
205
182
|
url: options.url,
|
|
206
183
|
method: options.method,
|
|
@@ -210,9 +187,6 @@ class DirHubspot {
|
|
|
210
187
|
if (options.json !== null) {
|
|
211
188
|
axios_options.data = options.json
|
|
212
189
|
}
|
|
213
|
-
if (this.log) {
|
|
214
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
215
|
-
}
|
|
216
190
|
if (options.url.startsWith("https:")) {
|
|
217
191
|
const httpsAgent = new https.Agent({
|
|
218
192
|
rejectUnauthorized: false,
|
|
@@ -221,10 +195,6 @@ class DirHubspot {
|
|
|
221
195
|
}
|
|
222
196
|
axios(axios_options)
|
|
223
197
|
.then((res) => {
|
|
224
|
-
if (this.log) {
|
|
225
|
-
console.log("Response for url:", options.url);
|
|
226
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
227
|
-
}
|
|
228
198
|
if (res && (res.status == 200 || res.status == 201) && res.data) {
|
|
229
199
|
if (callback) {
|
|
230
200
|
callback(null, res.data);
|
|
@@ -253,7 +223,6 @@ class DirHubspot {
|
|
|
253
223
|
if (falseIntent) {
|
|
254
224
|
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
255
225
|
}
|
|
256
|
-
if (this.log) { console.log('DirHubspot executeCondition/result', result) }
|
|
257
226
|
if (result === true) {
|
|
258
227
|
if (trueIntentDirective) {
|
|
259
228
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
@@ -263,7 +232,7 @@ class DirHubspot {
|
|
|
263
232
|
});
|
|
264
233
|
}
|
|
265
234
|
else {
|
|
266
|
-
|
|
235
|
+
winston.debug("(DirHubspot) No trueIntentDirective specified");
|
|
267
236
|
if (callback) {
|
|
268
237
|
callback();
|
|
269
238
|
}
|
|
@@ -278,7 +247,7 @@ class DirHubspot {
|
|
|
278
247
|
});
|
|
279
248
|
}
|
|
280
249
|
else {
|
|
281
|
-
|
|
250
|
+
winston.debug("(DirHubspot) No falseIntentDirective specified");
|
|
282
251
|
if (callback) {
|
|
283
252
|
callback();
|
|
284
253
|
}
|
|
@@ -297,7 +266,7 @@ class DirHubspot {
|
|
|
297
266
|
},
|
|
298
267
|
method: "GET"
|
|
299
268
|
}
|
|
300
|
-
|
|
269
|
+
winston.debug("(DirHubspot) Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
301
270
|
|
|
302
271
|
this.#myrequest(
|
|
303
272
|
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|