@tiledesk/tiledesk-tybot-connector 0.5.0-rc2 → 0.5.1-rc1
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 +7 -0
- package/ExtApi.js +2 -71
- package/Logger.js +32 -5
- package/{models → engine}/IntentsMachineFactory.js +1 -1
- package/{models → engine}/MongodbBotsDataSource.js +2 -2
- package/{models → engine}/MongodbIntentsMachine.js +1 -1
- package/{models → engine}/TiledeskChatbot.js +3 -1
- package/{models → engine}/TiledeskIntentsMachine.js +1 -2
- package/{models → engine/mock}/MockBotsDataSource.js +1 -2
- package/index.js +23 -111
- package/logs/app.log +3041 -4469
- package/logs/app3.log +2822 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +1 -1
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -1
- package/{models/faqService.js → services/FaqService.js} +4 -3
- package/services/IntegrationService.js +43 -0
- package/services/TilebotService.js +47 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +2 -3
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -1
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +8 -42
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +9 -74
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +14 -83
- package/tiledeskChatbotPlugs/directives/DirAssign.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +13 -106
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +5 -34
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirCode.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +3 -72
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +5 -33
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirForm.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +13 -76
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +5 -34
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +3 -39
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -38
- package/tiledeskChatbotPlugs/directives/DirIntent.js +2 -77
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +3 -72
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirQapla.js +7 -72
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -38
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +3 -39
- package/tiledeskChatbotPlugs/directives/DirReply.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +3 -29
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +3 -38
- package/tiledeskChatbotPlugs/directives/DirWait.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +32 -22
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +23 -64
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +3 -29
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +8 -50
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine}/IntentForm.js +0 -0
- /package/{models → engine}/TiledeskChatbotConst.js +0 -0
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
- /package/{models → engine/mock}/MockTdCache.js +0 -0
package/models/faq.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
var mongoose = require('mongoose');
|
|
2
2
|
var Schema = mongoose.Schema;
|
|
3
3
|
var { nanoid } = require("nanoid");
|
|
4
|
+
const winston = require('../utils/winston')
|
|
4
5
|
//const { v4: uuidv4 } = require('uuid');
|
|
5
6
|
var defaultFullTextLanguage = process.env.DEFAULT_FULLTEXT_INDEX_LANGUAGE || "none";
|
|
6
7
|
|
|
@@ -105,14 +106,10 @@ FaqSchema.index({ id_project: 1, id_faq_kb: 1, intent_display_name: 1 }, { uniq
|
|
|
105
106
|
|
|
106
107
|
var faq = mongoose.model('faq', FaqSchema);
|
|
107
108
|
|
|
108
|
-
//faq.on('index', function(error) {
|
|
109
|
-
// "_id index cannot be sparse"
|
|
110
|
-
//console.debug('index:', error);
|
|
111
|
-
//});
|
|
112
109
|
|
|
113
110
|
if (process.env.MONGOOSE_SYNCINDEX) {
|
|
114
111
|
faq.syncIndexes();
|
|
115
|
-
|
|
112
|
+
winston.verbose("faq syncIndexes")
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const httpUtils = require("../utils/HttpUtils");
|
|
2
|
+
|
|
2
3
|
class AiService {
|
|
3
4
|
|
|
4
5
|
constructor(options){
|
|
@@ -13,7 +14,7 @@ class AiService {
|
|
|
13
14
|
url: `${this.APIURL}/${this.PROJECT_ID}/llm/transcription`,
|
|
14
15
|
headers: {
|
|
15
16
|
'Content-Type' : 'application/json',
|
|
16
|
-
'Authorization':
|
|
17
|
+
'Authorization': httpUtils.fixToken(this.TOKEN)
|
|
17
18
|
},
|
|
18
19
|
json: {
|
|
19
20
|
url: url
|
|
@@ -21,7 +22,7 @@ class AiService {
|
|
|
21
22
|
method: 'POST',
|
|
22
23
|
httpsOptions: this.httpsOptions
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
httpUtils.request(
|
|
25
26
|
HTTPREQUEST,
|
|
26
27
|
function(err, resbody) {
|
|
27
28
|
if (err) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var Faq = require("
|
|
2
|
-
var Faq_kb = require("
|
|
1
|
+
var Faq = require("../models/faq");
|
|
2
|
+
var Faq_kb = require("../models/faq_kb");
|
|
3
|
+
const winston = require('../utils/winston');
|
|
3
4
|
|
|
4
5
|
class FaqService {
|
|
5
6
|
|
|
6
7
|
async getAll(faq_kb_id) {
|
|
7
|
-
|
|
8
|
+
winston.verbose("(Service) GET ALL FAQ OF THE BOT ID (req.query): " + faq_kb_id);
|
|
8
9
|
return new Promise((resolve, reject) => {
|
|
9
10
|
let query = { id_faq_kb: faq_kb_id};
|
|
10
11
|
Faq.find(query).lean().exec( (err, faqs) => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const httpUtils = require('../utils/HttpUtils');
|
|
2
|
+
const winston = require('../utils/winston');
|
|
3
|
+
let API_ENDPOINT = process.env.API_ENDPOINT;
|
|
4
|
+
|
|
5
|
+
class IntegrationService {
|
|
6
|
+
|
|
7
|
+
constructor() {}
|
|
8
|
+
|
|
9
|
+
async getKeyFromIntegrations(id_project, integration_name, token) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
|
|
12
|
+
const INTEGRATIONS_HTTPREQUEST = {
|
|
13
|
+
url: API_ENDPOINT + "/" + id_project + "/integration/name/" + integration_name,
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
'Authorization': 'JWT ' + token
|
|
17
|
+
},
|
|
18
|
+
method: "GET"
|
|
19
|
+
}
|
|
20
|
+
winston.debug("Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
21
|
+
|
|
22
|
+
httpUtils.request(
|
|
23
|
+
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
resolve(null);
|
|
26
|
+
} else {
|
|
27
|
+
|
|
28
|
+
if (integration &&
|
|
29
|
+
integration.value) {
|
|
30
|
+
resolve(integration.value.apikey)
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
resolve(null)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const integrationService = new IntegrationService();
|
|
43
|
+
module.exports = integrationService;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const httpUtils = require("../utils/HttpUtils");
|
|
2
|
+
const winston = require('../utils/winston');
|
|
3
|
+
const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT;
|
|
4
|
+
|
|
5
|
+
class TilebotService {
|
|
6
|
+
|
|
7
|
+
constructor() { }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
|
|
11
|
+
* /${TILEBOT_ROUTE}/ext/${botId}
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} message. The message to send
|
|
14
|
+
* @param {string} botId. Tiledesk botId
|
|
15
|
+
* @param {string} token. User token
|
|
16
|
+
*/
|
|
17
|
+
sendMessageToBot(message, botId, callback) {
|
|
18
|
+
const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
|
|
19
|
+
winston.verbose("sendMessageToBot URL" + url);
|
|
20
|
+
const HTTPREQUEST = {
|
|
21
|
+
url: url,
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json'
|
|
24
|
+
},
|
|
25
|
+
json: message,
|
|
26
|
+
method: 'POST'
|
|
27
|
+
};
|
|
28
|
+
httpUtils.request(
|
|
29
|
+
HTTPREQUEST,
|
|
30
|
+
function (err, resbody) {
|
|
31
|
+
if (err) {
|
|
32
|
+
if (callback) {
|
|
33
|
+
callback(err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (callback) {
|
|
38
|
+
callback(null, resbody);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}, false
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let tilebotService = new TilebotService();
|
|
47
|
+
module.exports = tilebotService;
|
|
@@ -32,7 +32,7 @@ const { DirWhatsappByAttribute } = require('./directives/DirWhatsappByAttribute'
|
|
|
32
32
|
const { DirAskGPT } = require('./directives/DirAskGPT');
|
|
33
33
|
const { DirQapla } = require('./directives/DirQapla');
|
|
34
34
|
|
|
35
|
-
const { TiledeskChatbot } = require('../
|
|
35
|
+
const { TiledeskChatbot } = require('../engine/TiledeskChatbot');
|
|
36
36
|
const { DirIfOnlineAgents } = require('./directives/DirIfOnlineAgents');
|
|
37
37
|
const { DirReply } = require('./directives/DirReply');
|
|
38
38
|
const { DirRandomReply } = require('./directives/DirRandomReply');
|
|
@@ -578,9 +578,8 @@ class DirectivesChatbotPlug {
|
|
|
578
578
|
}
|
|
579
579
|
else if (directive_name === Directives.AI_PROMPT) {
|
|
580
580
|
new DirAiPrompt(context).execute(directive, async (stop) => {
|
|
581
|
-
if (context.log) { console.log("AiPrompt stop?", stop);}
|
|
582
581
|
if (stop == true) {
|
|
583
|
-
|
|
582
|
+
winston.debug("(DirectivesChatbotPlug) DirAskGPTV2 Stopping Actions on: ", directive);
|
|
584
583
|
this.theend();
|
|
585
584
|
}
|
|
586
585
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
|
-
const { TiledeskChatbot } = require('../
|
|
2
|
+
const { TiledeskChatbot } = require('../engine/TiledeskChatbot.js');
|
|
3
3
|
const { Filler } = require('./Filler');
|
|
4
4
|
const winston = require('../utils/winston.js');
|
|
5
5
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require("../../
|
|
2
|
+
const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
let https = require("https");
|
|
5
5
|
const { DirIntent } = require("./DirIntent");
|
|
6
|
-
const { TiledeskChatbotConst } = require("../../
|
|
7
|
-
const { TiledeskChatbotUtil } = require("../../
|
|
6
|
+
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
7
|
+
const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
8
8
|
const req = require("express/lib/request");
|
|
9
9
|
const { update } = require("../../models/faq");
|
|
10
10
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
11
11
|
require('dotenv').config();
|
|
12
12
|
const winston = require('../../utils/winston');
|
|
13
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
13
14
|
|
|
14
15
|
class DirAddTags {
|
|
15
16
|
|
|
@@ -155,42 +156,6 @@ class DirAddTags {
|
|
|
155
156
|
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
#myrequest(options, callback) {
|
|
159
|
-
let axios_options = {
|
|
160
|
-
url: options.url,
|
|
161
|
-
method: options.method,
|
|
162
|
-
params: options.params,
|
|
163
|
-
headers: options.headers
|
|
164
|
-
}
|
|
165
|
-
if (options.json !== null) {
|
|
166
|
-
axios_options.data = options.json
|
|
167
|
-
}
|
|
168
|
-
if (options.url.startsWith("https:")) {
|
|
169
|
-
const httpsAgent = new https.Agent({
|
|
170
|
-
rejectUnauthorized: false,
|
|
171
|
-
});
|
|
172
|
-
axios_options.httpsAgent = httpsAgent;
|
|
173
|
-
}
|
|
174
|
-
axios(axios_options)
|
|
175
|
-
.then((res) => {
|
|
176
|
-
if (res && res.status == 200 && res.data) {
|
|
177
|
-
if (callback) {
|
|
178
|
-
callback(null, res.data);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
if (callback) {
|
|
183
|
-
callback(new Error("Response status is not 200"), null);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
})
|
|
187
|
-
.catch((error) => {
|
|
188
|
-
if (callback) {
|
|
189
|
-
callback(error, null);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
159
|
async addNewTag(tag){
|
|
195
160
|
return new Promise((resolve, reject)=> {
|
|
196
161
|
const HTTPREQUEST = {
|
|
@@ -205,7 +170,8 @@ class DirAddTags {
|
|
|
205
170
|
color: '#f0806f'
|
|
206
171
|
}
|
|
207
172
|
}
|
|
208
|
-
|
|
173
|
+
|
|
174
|
+
httpUtils.request(
|
|
209
175
|
HTTPREQUEST, async (err, resbody) => {
|
|
210
176
|
if (err) {
|
|
211
177
|
winston.error("(httprequest) DirAddTags add tags to list err: ", err);
|
|
@@ -239,7 +205,7 @@ class DirAddTags {
|
|
|
239
205
|
json: json
|
|
240
206
|
}
|
|
241
207
|
|
|
242
|
-
|
|
208
|
+
httpUtils.request(
|
|
243
209
|
HTTPREQUEST, async (err, resbody) => {
|
|
244
210
|
if (err) {
|
|
245
211
|
winston.error("(httprequest) DirAddTags patch request with new tags err: ", err);
|
|
@@ -268,7 +234,7 @@ class DirAddTags {
|
|
|
268
234
|
json: tags
|
|
269
235
|
}
|
|
270
236
|
|
|
271
|
-
|
|
237
|
+
httpUtils.request(
|
|
272
238
|
HTTPREQUEST, async (err, resbody) => {
|
|
273
239
|
if (err) {
|
|
274
240
|
winston.error("(httprequest) DirAddTags put lead with new tags err: ", err);
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require("../../
|
|
2
|
+
const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
let https = require("https");
|
|
5
5
|
const { DirIntent } = require("./DirIntent");
|
|
6
|
-
const { TiledeskChatbotConst } = require("../../
|
|
7
|
-
const { TiledeskChatbotUtil } = require("../../
|
|
6
|
+
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
7
|
+
const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
8
8
|
require('dotenv').config();
|
|
9
|
+
const winston = require('../../utils/winston');
|
|
10
|
+
const Utils = require("../../utils/HttpUtils");
|
|
11
|
+
const utils = require("../../utils/HttpUtils");
|
|
12
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
13
|
+
const integrationService = require("../../services/IntegrationService");
|
|
14
|
+
|
|
9
15
|
|
|
10
16
|
class DirAiPrompt {
|
|
11
17
|
|
|
@@ -17,19 +23,21 @@ class DirAiPrompt {
|
|
|
17
23
|
this.chatbot = this.context.chatbot;
|
|
18
24
|
this.tdcache = this.context.tdcache;
|
|
19
25
|
this.requestId = this.context.requestId;
|
|
26
|
+
this.projectId = this.context.projectId;
|
|
27
|
+
this.token = this.context.token;
|
|
20
28
|
this.intentDir = new DirIntent(context);
|
|
21
29
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
22
30
|
this.log = context.log;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
execute(directive, callback) {
|
|
26
|
-
|
|
34
|
+
winston.verbose("Execute AiPrompt directive");
|
|
27
35
|
let action;
|
|
28
36
|
if (directive.action) {
|
|
29
37
|
action = directive.action;
|
|
30
38
|
}
|
|
31
39
|
else {
|
|
32
|
-
|
|
40
|
+
winston.debug("DirAiPrompt Incorrect directive: ", directive);
|
|
33
41
|
callback();
|
|
34
42
|
return;
|
|
35
43
|
}
|
|
@@ -39,9 +47,9 @@ class DirAiPrompt {
|
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
async go(action, callback) {
|
|
42
|
-
|
|
50
|
+
winston.debug("DirAiPrompt action:", action);
|
|
43
51
|
if (!this.tdcache) {
|
|
44
|
-
|
|
52
|
+
winston.error("Error: DirAiPrompt tdcache is mandatory");
|
|
45
53
|
callback();
|
|
46
54
|
return;
|
|
47
55
|
}
|
|
@@ -53,10 +61,8 @@ class DirAiPrompt {
|
|
|
53
61
|
let transcript;
|
|
54
62
|
let answer = "No answer"
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
console.log("DirAiPrompt falseIntent", falseIntent)
|
|
59
|
-
}
|
|
64
|
+
winston.debug("DirAskGPTV2 trueIntent", trueIntent)
|
|
65
|
+
winston.debug("DirAskGPTV2 falseIntent", falseIntent)
|
|
60
66
|
|
|
61
67
|
await this.checkMandatoryParameters(action).catch( async (missing_param) => {
|
|
62
68
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: '" + missing_param + "' attribute is undefined");
|
|
@@ -84,23 +90,23 @@ class DirAiPrompt {
|
|
|
84
90
|
this.context.tdcache,
|
|
85
91
|
this.context.requestId,
|
|
86
92
|
TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
|
|
87
|
-
|
|
93
|
+
winston.debug("DirAiPrompt transcript string: " + transcript_string)
|
|
88
94
|
|
|
89
95
|
if (transcript_string) {
|
|
90
96
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
91
|
-
|
|
97
|
+
winston.debug("DirAiPrompt transcript: ", transcript)
|
|
92
98
|
} else {
|
|
93
|
-
|
|
99
|
+
winston.verbose("DirAiPrompt transcript_string is undefined. Skip JSON translation for chat history")
|
|
94
100
|
}
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
const AI_endpoint = process.env.AI_ENDPOINT
|
|
98
|
-
|
|
104
|
+
winston.verbose("DirAiPrompt AI_endpoint " + AI_endpoint);
|
|
99
105
|
|
|
100
|
-
let key = await
|
|
106
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
|
|
101
107
|
|
|
102
108
|
if (!key) {
|
|
103
|
-
|
|
109
|
+
winston.error("Error: DirAiPrompt llm key not found in integrations");
|
|
104
110
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
|
|
105
111
|
if (falseIntent) {
|
|
106
112
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -127,7 +133,7 @@ class DirAiPrompt {
|
|
|
127
133
|
json.chat_history_dict = await this.transcriptToLLM(transcript);
|
|
128
134
|
}
|
|
129
135
|
|
|
130
|
-
|
|
136
|
+
winston.debug("DirAiPrompt json: ", json);
|
|
131
137
|
|
|
132
138
|
const HTTPREQUEST = {
|
|
133
139
|
url: AI_endpoint + '/ask',
|
|
@@ -137,14 +143,12 @@ class DirAiPrompt {
|
|
|
137
143
|
json: json,
|
|
138
144
|
method: 'POST'
|
|
139
145
|
}
|
|
140
|
-
|
|
146
|
+
winston.debug("DirAiPrompt HttpRequest: ", HTTPREQUEST);
|
|
141
147
|
|
|
142
|
-
|
|
148
|
+
httpUtils.request(
|
|
143
149
|
HTTPREQUEST, async (err, resbody) => {
|
|
144
150
|
if (err) {
|
|
145
|
-
|
|
146
|
-
console.error("(httprequest) DirAiPrompt openai err:", err.response.data);
|
|
147
|
-
}
|
|
151
|
+
winston.error("DirAiPrompt openai err:", err.response.data);
|
|
148
152
|
await this.#assignAttributes(action, answer);
|
|
149
153
|
let error;
|
|
150
154
|
if (err.response?.data?.detail[0]) {
|
|
@@ -164,7 +168,7 @@ class DirAiPrompt {
|
|
|
164
168
|
return;
|
|
165
169
|
} else {
|
|
166
170
|
|
|
167
|
-
|
|
171
|
+
winston.debug("DirAiPrompt resbody: ", resbody);
|
|
168
172
|
answer = resbody.answer;
|
|
169
173
|
|
|
170
174
|
await this.#assignAttributes(action, answer);
|
|
@@ -260,7 +264,7 @@ class DirAiPrompt {
|
|
|
260
264
|
})
|
|
261
265
|
}
|
|
262
266
|
else {
|
|
263
|
-
|
|
267
|
+
winston.debug("DirAiPrompt No trueIntentDirective specified");
|
|
264
268
|
if (callback) {
|
|
265
269
|
callback();
|
|
266
270
|
}
|
|
@@ -275,7 +279,7 @@ class DirAiPrompt {
|
|
|
275
279
|
});
|
|
276
280
|
}
|
|
277
281
|
else {
|
|
278
|
-
|
|
282
|
+
winston.debug("DirAiPrompt No falseIntentDirective specified");
|
|
279
283
|
if (callback) {
|
|
280
284
|
callback();
|
|
281
285
|
}
|
|
@@ -284,103 +288,16 @@ class DirAiPrompt {
|
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
async #assignAttributes(action, answer) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
+
winston.debug("DirAiPrompt assignAttributes action: ", action)
|
|
292
|
+
winston.debug("DirAiPrompt assignAttributes answer: " + answer)
|
|
293
|
+
|
|
291
294
|
if (this.context.tdcache) {
|
|
292
295
|
if (action.assignReplyTo && answer) {
|
|
293
296
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
294
297
|
}
|
|
295
|
-
// Debug log
|
|
296
|
-
if (this.log) {
|
|
297
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
298
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
299
|
-
if (this.log) { console.log("(gpttask) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
298
|
}
|
|
303
299
|
}
|
|
304
300
|
|
|
305
|
-
#myrequest(options, callback) {
|
|
306
|
-
if (this.log) {
|
|
307
|
-
console.log("API URL:", options.url);
|
|
308
|
-
console.log("** Options:", JSON.stringify(options));
|
|
309
|
-
}
|
|
310
|
-
let axios_options = {
|
|
311
|
-
url: options.url,
|
|
312
|
-
method: options.method,
|
|
313
|
-
params: options.params,
|
|
314
|
-
headers: options.headers
|
|
315
|
-
}
|
|
316
|
-
if (options.json !== null) {
|
|
317
|
-
axios_options.data = options.json
|
|
318
|
-
}
|
|
319
|
-
if (this.log) {
|
|
320
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
321
|
-
}
|
|
322
|
-
if (options.url.startsWith("https:")) {
|
|
323
|
-
const httpsAgent = new https.Agent({
|
|
324
|
-
rejectUnauthorized: false,
|
|
325
|
-
});
|
|
326
|
-
axios_options.httpsAgent = httpsAgent;
|
|
327
|
-
}
|
|
328
|
-
axios(axios_options)
|
|
329
|
-
.then((res) => {
|
|
330
|
-
if (this.log) {
|
|
331
|
-
console.log("Response for url:", options.url);
|
|
332
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
333
|
-
}
|
|
334
|
-
if (res && res.status == 200 && res.data) {
|
|
335
|
-
if (callback) {
|
|
336
|
-
callback(null, res.data);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
if (callback) {
|
|
341
|
-
callback(new Error("Response status is not 200"), null);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
})
|
|
345
|
-
.catch((error) => {
|
|
346
|
-
console.error("(DirAiPrompt) Axios error: ", JSON.stringify(error));
|
|
347
|
-
if (callback) {
|
|
348
|
-
callback(error, null);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
async getKeyFromIntegrations(model) {
|
|
354
|
-
return new Promise((resolve) => {
|
|
355
|
-
|
|
356
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
357
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/" + model,
|
|
358
|
-
headers: {
|
|
359
|
-
'Content-Type': 'application/json',
|
|
360
|
-
'Authorization': 'JWT ' + this.context.token
|
|
361
|
-
},
|
|
362
|
-
method: "GET"
|
|
363
|
-
}
|
|
364
|
-
if (this.log) { console.log("DirAiPrompt INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
365
|
-
|
|
366
|
-
this.#myrequest(
|
|
367
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
368
|
-
if (err) {
|
|
369
|
-
resolve(null);
|
|
370
|
-
} else {
|
|
371
|
-
|
|
372
|
-
if (integration &&
|
|
373
|
-
integration.value) {
|
|
374
|
-
resolve(integration.value.apikey)
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
resolve(null)
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
})
|
|
381
|
-
})
|
|
382
|
-
}
|
|
383
|
-
|
|
384
301
|
async getKeyFromKbSettings() {
|
|
385
302
|
return new Promise((resolve) => {
|
|
386
303
|
|
|
@@ -392,15 +309,12 @@ class DirAiPrompt {
|
|
|
392
309
|
},
|
|
393
310
|
method: "GET"
|
|
394
311
|
}
|
|
395
|
-
|
|
312
|
+
winston.debug("DirAiPrompt KB HttpRequest", KB_HTTPREQUEST);
|
|
396
313
|
|
|
397
|
-
|
|
314
|
+
httpUtils.request(
|
|
398
315
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
399
316
|
if (err) {
|
|
400
|
-
|
|
401
|
-
if (this.log) {
|
|
402
|
-
console.error("(httprequest) DirAiPrompt Get KnowledgeBase full err", err);
|
|
403
|
-
}
|
|
317
|
+
winston.error("(httprequest) DirAiPrompt Get KnowledgeBase err: " + err.message);
|
|
404
318
|
resolve(null);
|
|
405
319
|
} else {
|
|
406
320
|
if (!resbody.gptkey) {
|
|
@@ -425,9 +339,9 @@ class DirAiPrompt {
|
|
|
425
339
|
},
|
|
426
340
|
method: "GET"
|
|
427
341
|
}
|
|
428
|
-
|
|
342
|
+
winston.debug("DirAiPrompt check quote availability HttpRequest", HTTPREQUEST);
|
|
429
343
|
|
|
430
|
-
|
|
344
|
+
httpUtils.request(
|
|
431
345
|
HTTPREQUEST, async (err, resbody) => {
|
|
432
346
|
if (err) {
|
|
433
347
|
resolve(true)
|
|
@@ -455,15 +369,15 @@ class DirAiPrompt {
|
|
|
455
369
|
json: tokens_usage,
|
|
456
370
|
method: "POST"
|
|
457
371
|
}
|
|
458
|
-
|
|
372
|
+
winston.debug("DirAiPrompt update quote HttpRequest", HTTPREQUEST);
|
|
459
373
|
|
|
460
|
-
|
|
374
|
+
httpUtils.request(
|
|
461
375
|
HTTPREQUEST, async (err, resbody) => {
|
|
462
376
|
if (err) {
|
|
463
|
-
|
|
377
|
+
winston.error("(httprequest) DirAiPrompt Increment tokens quote err: ", err);
|
|
464
378
|
reject(false)
|
|
465
379
|
} else {
|
|
466
|
-
|
|
380
|
+
winston.debug("(httprequest) DirAiPrompt Increment token quote resbody: ", resbody);
|
|
467
381
|
resolve(true);
|
|
468
382
|
}
|
|
469
383
|
}
|