@tiledesk/tiledesk-tybot-connector 2.0.12-rc4 → 2.0.12-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/ExtApi.js +1 -8
- package/ExtUtil.js +5 -6
- package/engine/IntentForm.js +0 -1
- package/engine/IntentsMachineFactory.js +4 -4
- package/engine/MongodbBotsDataSource.js +0 -1
- package/engine/MongodbIntentsMachine.js +0 -1
- package/engine/TiledeskChatbot.js +11 -16
- package/engine/TiledeskIntentsMachine.js +1 -2
- package/index.js +11 -23
- package/logs/app.log +573 -0
- package/package.json +1 -1
- package/services/AIService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +10 -10
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
- package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +333 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -54
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -15
- package/tiledeskChatbotPlugs/directives/DirMessage.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -15
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
- package/utils/TiledeskChatbotUtil.js +15 -29
package/package.json
CHANGED
package/services/AIService.js
CHANGED
|
@@ -74,7 +74,6 @@ class DirectivesChatbotPlug {
|
|
|
74
74
|
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
75
75
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
76
76
|
this.token = config.token;
|
|
77
|
-
this.log = config.log;
|
|
78
77
|
this.HELP_CENTER_API_ENDPOINT = config.HELP_CENTER_API_ENDPOINT;
|
|
79
78
|
this.tdcache = config.cache;
|
|
80
79
|
this.directives = config.directives;
|
|
@@ -143,8 +142,7 @@ class DirectivesChatbotPlug {
|
|
|
143
142
|
projectId: projectId,
|
|
144
143
|
token: token,
|
|
145
144
|
APIURL: API_ENDPOINT,
|
|
146
|
-
APIKEY: "___"
|
|
147
|
-
log: this.log
|
|
145
|
+
APIKEY: "___"
|
|
148
146
|
});
|
|
149
147
|
}
|
|
150
148
|
catch(err) {
|
|
@@ -163,8 +161,7 @@ class DirectivesChatbotPlug {
|
|
|
163
161
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
164
162
|
departmentId: depId,
|
|
165
163
|
tdcache: tdcache,
|
|
166
|
-
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
167
|
-
log: this.log
|
|
164
|
+
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
168
165
|
}
|
|
169
166
|
winston.debug("(DirectivesChatbotPlug) this.context.departmentId: " + this.context.departmentId);
|
|
170
167
|
|
|
@@ -178,9 +175,7 @@ class DirectivesChatbotPlug {
|
|
|
178
175
|
|
|
179
176
|
async nextDirective(directives) {
|
|
180
177
|
winston.debug("(DirectivesChatbotPlug) ....nextDirective() checkStep()");
|
|
181
|
-
const go_on = await TiledeskChatbot.checkStep(
|
|
182
|
-
this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME, this.log
|
|
183
|
-
);
|
|
178
|
+
const go_on = await TiledeskChatbot.checkStep(this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME);
|
|
184
179
|
|
|
185
180
|
if (go_on.error) {
|
|
186
181
|
winston.debug("(DirectivesChatbotPlug) go_on == false! nextDirective() Stopped!");
|
|
@@ -566,6 +561,12 @@ class DirectivesChatbotPlug {
|
|
|
566
561
|
}
|
|
567
562
|
});
|
|
568
563
|
}
|
|
564
|
+
else if (directive_name === Directives.ADD_KB_CONTENT) {
|
|
565
|
+
new DirAddKbContent(context).execute(directive, async () => {
|
|
566
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
567
|
+
this.process(next_dir);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
569
570
|
else if (directive_name === Directives.GPT_TASK) {
|
|
570
571
|
new DirGptTask(context).execute(directive, async (stop) => {
|
|
571
572
|
if (stop == true) {
|
|
@@ -740,8 +741,7 @@ class DirectivesChatbotPlug {
|
|
|
740
741
|
projectId: projectId,
|
|
741
742
|
token: token,
|
|
742
743
|
APIURL: API_ENDPOINT,
|
|
743
|
-
APIKEY: "___"
|
|
744
|
-
log: false
|
|
744
|
+
APIKEY: "___"
|
|
745
745
|
});
|
|
746
746
|
let i = -1;
|
|
747
747
|
winston.debug("(DirectivesChatbotPlug) processing Inline directives: ", directives);
|
|
@@ -3,11 +3,10 @@ const winston = require('../utils/winston');
|
|
|
3
3
|
|
|
4
4
|
class WebhookChatbotPlug {
|
|
5
5
|
|
|
6
|
-
constructor(supportRequest, webhookurl, token
|
|
6
|
+
constructor(supportRequest, webhookurl, token) {
|
|
7
7
|
this.supportRequest = supportRequest;
|
|
8
8
|
this.webhookurl = webhookurl;
|
|
9
9
|
this.token = token;
|
|
10
|
-
this.log = log;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
exec(pipeline) {
|
|
@@ -101,19 +100,18 @@ class WebhookChatbotPlug {
|
|
|
101
100
|
callback(null, res.data);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
}
|
|
105
|
-
);
|
|
103
|
+
});
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
// ************************************************
|
|
109
107
|
// ****************** HTTP REQUEST ****************
|
|
110
108
|
// ************************************************
|
|
111
109
|
|
|
112
|
-
static myrequest(options, callback
|
|
113
|
-
|
|
110
|
+
static myrequest(options, callback) {
|
|
111
|
+
|
|
114
112
|
winston.debug("(WebhookChatbotPlug) myrequest API URL:" + options.url);
|
|
115
113
|
winston.debug("(WebhookChatbotPlug) myrequest Options:", options);
|
|
116
|
-
|
|
114
|
+
|
|
117
115
|
axios(
|
|
118
116
|
{
|
|
119
117
|
url: options.url,
|
|
@@ -122,11 +120,11 @@ class WebhookChatbotPlug {
|
|
|
122
120
|
headers: options.headers
|
|
123
121
|
})
|
|
124
122
|
.then(function (res) {
|
|
125
|
-
|
|
123
|
+
|
|
126
124
|
winston.debug("(WebhookChatbotPlug) myrequest Response for url:", options.url);
|
|
127
125
|
winston.debug("(WebhookChatbotPlug) myrequest Response headers:\n", res.headers);
|
|
128
126
|
winston.debug("(WebhookChatbotPlug) myrequest Response body:\n", res.data);
|
|
129
|
-
|
|
127
|
+
|
|
130
128
|
if (callback) {
|
|
131
129
|
callback(null, res);
|
|
132
130
|
}
|
|
@@ -12,8 +12,7 @@ class DirIfNotOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
16
|
-
log: context.log
|
|
15
|
+
APIKEY: "___"
|
|
17
16
|
});
|
|
18
17
|
// this.intentDir = config.intentDir;
|
|
19
18
|
// let context = {
|
|
@@ -22,19 +21,16 @@ class DirIfNotOpenHours {
|
|
|
22
21
|
// requestId: supportRequest,
|
|
23
22
|
// APIURL: API_URL,
|
|
24
23
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
25
|
-
// departmentId: depId
|
|
26
|
-
// log: false
|
|
24
|
+
// departmentId: depId
|
|
27
25
|
// }
|
|
28
26
|
this.intentDir = new DirIntent(
|
|
29
27
|
{
|
|
30
28
|
API_ENDPOINT: context.TILEDESK_APIURL,
|
|
31
29
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
32
30
|
supportRequest: context.supportRequest,
|
|
33
|
-
token: context.token
|
|
34
|
-
log: context.log
|
|
31
|
+
token: context.token
|
|
35
32
|
}
|
|
36
33
|
);
|
|
37
|
-
this.log = context.log;
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
execute(directive, callback) {
|
|
@@ -58,7 +54,6 @@ class DirIfNotOpenHours {
|
|
|
58
54
|
go(action, callback) {
|
|
59
55
|
const intentName = action.body.intentName;
|
|
60
56
|
if (!intentName) {
|
|
61
|
-
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
62
57
|
callback();
|
|
63
58
|
}
|
|
64
59
|
let intentDirective = {
|
|
@@ -69,13 +64,11 @@ class DirIfNotOpenHours {
|
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
this.tdclient.openNow((err, result) => {
|
|
72
|
-
if (this.log) {console.log("openNow():", result);}
|
|
73
67
|
if (err) {
|
|
74
68
|
console.error("DirIfNotOpenHours Error:", err);
|
|
75
69
|
callback();
|
|
76
70
|
}
|
|
77
71
|
else if (result && !result.isopen) {
|
|
78
|
-
if (this.log) {console.log("executing the action on 'closed'");}
|
|
79
72
|
this.intentDir.execute(intentDirective, () => {
|
|
80
73
|
callback();
|
|
81
74
|
});
|
|
@@ -12,8 +12,7 @@ class DirIfOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
16
|
-
log: context.log
|
|
15
|
+
APIKEY: "___"
|
|
17
16
|
});
|
|
18
17
|
// let context = {
|
|
19
18
|
// projectId: projectId,
|
|
@@ -22,7 +21,6 @@ class DirIfOpenHours {
|
|
|
22
21
|
// APIURL: API_URL,
|
|
23
22
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
24
23
|
// departmentId: depId,
|
|
25
|
-
// log: false
|
|
26
24
|
// }
|
|
27
25
|
this.intentDir = new DirIntent(
|
|
28
26
|
{
|
|
@@ -30,10 +28,8 @@ class DirIfOpenHours {
|
|
|
30
28
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
31
29
|
supportRequest: context.supportRequest,
|
|
32
30
|
token: context.token,
|
|
33
|
-
log: context.log
|
|
34
31
|
}
|
|
35
|
-
)
|
|
36
|
-
this.log = context.log;
|
|
32
|
+
)
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
execute(directive, callback) {
|
|
@@ -56,7 +52,6 @@ class DirIfOpenHours {
|
|
|
56
52
|
go(action, callback) {
|
|
57
53
|
const intentName = action.body.intentName;
|
|
58
54
|
if (!intentName) {
|
|
59
|
-
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
60
55
|
callback();
|
|
61
56
|
}
|
|
62
57
|
let intentDirective = {
|
|
@@ -67,13 +62,11 @@ class DirIfOpenHours {
|
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
this.tdclient.openNow((err, result) => {
|
|
70
|
-
if (this.log) {console.log("openNow():", result);}
|
|
71
65
|
if (err) {
|
|
72
66
|
console.error("DirIfOpenHours Error:", err);
|
|
73
67
|
callback();
|
|
74
68
|
}
|
|
75
69
|
else if (result && result.isopen) {
|
|
76
|
-
if (this.log) {console.log("executing the action on 'open'");}
|
|
77
70
|
this.intentDir.execute(intentDirective, () => {
|
|
78
71
|
callback();
|
|
79
72
|
});
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
const axios = require("axios").default;
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
+
const { Filler } = require('../Filler');
|
|
4
|
+
let https = require("https");
|
|
5
|
+
const { DirIntent } = require("./DirIntent");
|
|
6
|
+
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
7
|
+
const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
8
|
+
const assert = require("assert");
|
|
9
|
+
require('dotenv').config();
|
|
10
|
+
const winston = require('../../utils/winston');
|
|
11
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
12
|
+
const integrationService = require("../../services/IntegrationService");
|
|
13
|
+
const { Logger } = require("../../Logger");
|
|
14
|
+
|
|
15
|
+
class DirAddKbContent {
|
|
16
|
+
|
|
17
|
+
constructor(context) {
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error('context object is mandatory');
|
|
20
|
+
}
|
|
21
|
+
this.context = context;
|
|
22
|
+
this.chatbot = context.chatbot;
|
|
23
|
+
this.tdcache = this.context.tdcache;
|
|
24
|
+
this.requestId = this.context.requestId;
|
|
25
|
+
this.projectId = this.context.projectId;
|
|
26
|
+
this.token = this.context.token;
|
|
27
|
+
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
28
|
+
this.log = context.log;
|
|
29
|
+
|
|
30
|
+
this.intentDir = new DirIntent(context);
|
|
31
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
execute(directive, callback) {
|
|
35
|
+
this.logger.info("Execute AskKnowledgeBase action")
|
|
36
|
+
winston.debug("DirAskGPTV2 directive: ", directive);
|
|
37
|
+
let action;
|
|
38
|
+
if (directive.action) {
|
|
39
|
+
action = directive.action;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
43
|
+
winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
|
|
44
|
+
callback();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.go(action, (stop) => {
|
|
48
|
+
this.logger.info("Acion AskKnowledgeBase completed");
|
|
49
|
+
callback(stop);
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async go(action, callback) {
|
|
54
|
+
winston.debug("[DirAddKbContent] action:", action);
|
|
55
|
+
if (!this.tdcache) {
|
|
56
|
+
winston.error("[DirAddKbContent] Error: tdcache is mandatory");
|
|
57
|
+
callback();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let publicKey = false;
|
|
62
|
+
let type = action.type;
|
|
63
|
+
let name = action.name;
|
|
64
|
+
let content = action.content;
|
|
65
|
+
let engine;
|
|
66
|
+
|
|
67
|
+
// default values
|
|
68
|
+
let namespace = this.context.projectId;
|
|
69
|
+
|
|
70
|
+
if (action.namespace) {
|
|
71
|
+
namespace = action.namespace;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let requestVariables = null;
|
|
75
|
+
requestVariables =
|
|
76
|
+
await TiledeskChatbot.allParametersStatic(
|
|
77
|
+
this.tdcache, this.requestId
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const filler = new Filler();
|
|
81
|
+
const filled_content = filler.fill(content, requestVariables);
|
|
82
|
+
const filled_name = filler.fill(name, requestVariables);
|
|
83
|
+
|
|
84
|
+
const kb_endpoint = process.env.API_ENDPOINT;
|
|
85
|
+
winston.verbose("[DirAddKbContent] KbEndpoint URL: " + kb_endpoint);
|
|
86
|
+
|
|
87
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
88
|
+
if (!key) {
|
|
89
|
+
this.logger.debug("[DirAddKbContent] OpenAI key not found in Integration. Using shared OpenAI key");
|
|
90
|
+
winston.verbose("[DirAddKbContent] - Key not found in Integrations. Searching in kb settings...");
|
|
91
|
+
key = await this.getKeyFromKbSettings();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!key) {
|
|
95
|
+
winston.verbose("[DirAddKbContent] - Retrieve public gptkey")
|
|
96
|
+
key = process.env.GPTKEY;
|
|
97
|
+
publicKey = true;
|
|
98
|
+
} else {
|
|
99
|
+
this.logger.debug("[DirAddKbContent] use your own OpenAI key")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!key) {
|
|
103
|
+
winston.info("[DirAddKbContent] Error: gptkey is mandatory");
|
|
104
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: gptkey is mandatory");
|
|
105
|
+
callback();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (publicKey === true) {
|
|
110
|
+
let keep_going = await this.checkQuoteAvailability();
|
|
111
|
+
if (keep_going === false) {
|
|
112
|
+
this.logger.warn("[DirAddKbContent] Tokens quota exceeded. Skip the action")
|
|
113
|
+
winston.verbose("[DirAddKbContent] - Quota exceeded for tokens. Skip the action")
|
|
114
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: tokens quota exceeded");
|
|
115
|
+
callback(true);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let ns;
|
|
121
|
+
|
|
122
|
+
if (action.namespaceAsName) {
|
|
123
|
+
// Namespace could be an attribute
|
|
124
|
+
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
125
|
+
this.logger.debug("[DirAddKbContent] Searching namespace by name ", filled_namespace);
|
|
126
|
+
ns = await this.getNamespace(filled_namespace, null);
|
|
127
|
+
namespace = ns?.id;
|
|
128
|
+
winston.verbose("[DirAddKbContent] - Retrieved namespace id from name " + namespace);
|
|
129
|
+
} else {
|
|
130
|
+
this.logger.debug("[DirAddKbContent] Searching namespace by id ", namespace);
|
|
131
|
+
ns = await this.getNamespace(null, namespace);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!ns) {
|
|
135
|
+
this.logger.error("[DirAddKbContent] Namespace not found");
|
|
136
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace not found");
|
|
137
|
+
callback();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (ns.engine) {
|
|
142
|
+
engine = ns.engine;
|
|
143
|
+
} else {
|
|
144
|
+
engine = await this.setDefaultEngine()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!namespace) {
|
|
148
|
+
this.logger.error("[DirAddKbContent] Namespace is undefined")
|
|
149
|
+
winston.verbose("[DirAddKbContent] - Error: namespace is undefined")
|
|
150
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace is undefined");
|
|
151
|
+
callback(true);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let json = {
|
|
156
|
+
content: filled_content,
|
|
157
|
+
namespace: namespace,
|
|
158
|
+
type: type,
|
|
159
|
+
name: filled_name,
|
|
160
|
+
source: filled_name
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
winston.debug("[DirAddKbContent] json:", json);
|
|
164
|
+
|
|
165
|
+
const HTTPREQUEST = {
|
|
166
|
+
url: kb_endpoint + "/" + this.projectId + "/kb",
|
|
167
|
+
headers: {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
'Authorization': 'JWT ' + this.context.token
|
|
170
|
+
},
|
|
171
|
+
json: json,
|
|
172
|
+
method: "POST"
|
|
173
|
+
}
|
|
174
|
+
winston.debug("[DirAddKbContent] HttpRequest: ", HTTPREQUEST);
|
|
175
|
+
|
|
176
|
+
httpUtils.request(
|
|
177
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
178
|
+
|
|
179
|
+
if (err) {
|
|
180
|
+
this.logger.error("[DirAddKbContent] error: " + JSON.stringify(err?.response));
|
|
181
|
+
winston.error("[DirAddKbContent] error: ", err?.response);
|
|
182
|
+
if (callback) {
|
|
183
|
+
callback();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (resbody.success === true) {
|
|
188
|
+
winston.debug("[DirAddKbContent] resbody: ", resbody);
|
|
189
|
+
callback();
|
|
190
|
+
return;
|
|
191
|
+
} else {
|
|
192
|
+
callback();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async getKeyFromKbSettings() {
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
|
|
202
|
+
const KB_HTTPREQUEST = {
|
|
203
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'Authorization': 'JWT ' + this.context.token
|
|
207
|
+
},
|
|
208
|
+
method: "GET"
|
|
209
|
+
}
|
|
210
|
+
winston.debug("DirAskGPTV2 KB HttpRequest", KB_HTTPREQUEST);
|
|
211
|
+
|
|
212
|
+
httpUtils.request(
|
|
213
|
+
KB_HTTPREQUEST, async (err, resbody) => {
|
|
214
|
+
if (err) {
|
|
215
|
+
winston.error("DirAskGPTV2 Get kb settings error ", err?.response?.data);
|
|
216
|
+
resolve(null);
|
|
217
|
+
} else {
|
|
218
|
+
if (!resbody.gptkey) {
|
|
219
|
+
resolve(null);
|
|
220
|
+
} else {
|
|
221
|
+
resolve(resbody.gptkey);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
)
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async checkQuoteAvailability() {
|
|
230
|
+
return new Promise((resolve) => {
|
|
231
|
+
|
|
232
|
+
const HTTPREQUEST = {
|
|
233
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
|
|
234
|
+
headers: {
|
|
235
|
+
'Content-Type': 'application/json',
|
|
236
|
+
'Authorization': 'JWT ' + this.context.token
|
|
237
|
+
},
|
|
238
|
+
method: "GET"
|
|
239
|
+
}
|
|
240
|
+
winston.debug("DirAskGPTV2 check quote availability HttpRequest", HTTPREQUEST);
|
|
241
|
+
|
|
242
|
+
httpUtils.request(
|
|
243
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
244
|
+
if (err) {
|
|
245
|
+
winston.error("DirAskGPTV2 Check quote availability err: ", err);
|
|
246
|
+
resolve(true)
|
|
247
|
+
} else {
|
|
248
|
+
if (resbody.isAvailable === true) {
|
|
249
|
+
resolve(true)
|
|
250
|
+
} else {
|
|
251
|
+
resolve(false)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
)
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async updateQuote(tokens_usage) {
|
|
260
|
+
return new Promise((resolve, reject) => {
|
|
261
|
+
|
|
262
|
+
const HTTPREQUEST = {
|
|
263
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
|
|
264
|
+
headers: {
|
|
265
|
+
'Content-Type': 'application/json',
|
|
266
|
+
'Authorization': 'JWT ' + this.context.token
|
|
267
|
+
},
|
|
268
|
+
json: tokens_usage,
|
|
269
|
+
method: "POST"
|
|
270
|
+
}
|
|
271
|
+
winston.debug("DirAskGPTV2 update quote HttpRequest ", HTTPREQUEST);
|
|
272
|
+
|
|
273
|
+
httpUtils.request(
|
|
274
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
275
|
+
if (err) {
|
|
276
|
+
winston.error("DirAskGPTV2 Increment tokens quote err: ", err);
|
|
277
|
+
reject(false)
|
|
278
|
+
} else {
|
|
279
|
+
resolve(true);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async getNamespace(name, id) {
|
|
287
|
+
return new Promise((resolve) => {
|
|
288
|
+
const HTTPREQUEST = {
|
|
289
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kb/namespace/all",
|
|
290
|
+
headers: {
|
|
291
|
+
'Content-Type': 'application/json',
|
|
292
|
+
'Authorization': 'JWT ' + this.context.token
|
|
293
|
+
},
|
|
294
|
+
method: "GET"
|
|
295
|
+
}
|
|
296
|
+
winston.debug("DirAskGPTV2 get all namespaces HttpRequest", HTTPREQUEST);
|
|
297
|
+
httpUtils.request(
|
|
298
|
+
HTTPREQUEST, async (err, namespaces) => {
|
|
299
|
+
if (err) {
|
|
300
|
+
winston.error("DirAskGPTV2 get all namespaces err: ", err);
|
|
301
|
+
resolve(null)
|
|
302
|
+
} else {
|
|
303
|
+
winston.debug("DirAskGPTV2 get all namespaces resbody: ", namespaces);
|
|
304
|
+
if (name) {
|
|
305
|
+
let namespace = namespaces.find(n => n.name === name);
|
|
306
|
+
resolve(namespace);
|
|
307
|
+
} else {
|
|
308
|
+
let namespace = namespaces.find(n => n.id === id);
|
|
309
|
+
resolve(namespace);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async setDefaultEngine() {
|
|
319
|
+
return new Promise((resolve) => {
|
|
320
|
+
let engine = {
|
|
321
|
+
name: "pinecone",
|
|
322
|
+
type: process.env.PINECONE_TYPE,
|
|
323
|
+
apikey: "",
|
|
324
|
+
vector_size: 1536,
|
|
325
|
+
index_name: process.env.PINECONE_INDEX
|
|
326
|
+
}
|
|
327
|
+
resolve(engine);
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
module.exports = { DirAddKbContent }
|
|
@@ -13,7 +13,6 @@ class DirDeflectToHelpCenter {
|
|
|
13
13
|
}
|
|
14
14
|
this.context = context;
|
|
15
15
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
16
|
-
this.log = context.log;
|
|
17
16
|
|
|
18
17
|
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
|
|
19
18
|
}
|
|
@@ -64,8 +63,7 @@ class DirDeflectToHelpCenter {
|
|
|
64
63
|
if (last_user_text && last_user_text.trim() !== '') {
|
|
65
64
|
const helpcenter = new HelpCenterQuery({
|
|
66
65
|
APIKEY: "__",
|
|
67
|
-
projectId: project_id
|
|
68
|
-
log: false
|
|
66
|
+
projectId: project_id
|
|
69
67
|
});
|
|
70
68
|
if (this.helpcenter_api_endpoint) {
|
|
71
69
|
helpcenter.APIURL = this.helpcenter_api_endpoint
|
|
@@ -19,7 +19,7 @@ class DirFlowLog {
|
|
|
19
19
|
this.requestId = context.requestId;
|
|
20
20
|
this.log = context.log;
|
|
21
21
|
|
|
22
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest
|
|
22
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
execute(directive, callback) {
|