@tiledesk/tiledesk-tybot-connector 0.2.82 → 0.2.84
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/models/TiledeskChatbot.js +12 -18
- package/models/TiledeskChatbotConst.js +3 -0
- package/models/TiledeskChatbotUtil.js +9 -9
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +13 -3
- package/tiledeskChatbotPlugs/directives/DirReply.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
# v0.2.84
|
|
9
|
+
- Fixed "guest#" bug
|
|
10
|
+
- Fixed default_context in AskGPTv2
|
|
11
|
+
|
|
12
|
+
# v0.2.83
|
|
13
|
+
- Added support for advanced context in AskGPTv2
|
|
14
|
+
|
|
8
15
|
# v0.2.82
|
|
9
16
|
- Added {context} in 'system_context' in AskGPTv2
|
|
10
17
|
|
|
@@ -44,28 +44,22 @@ class TiledeskChatbot {
|
|
|
44
44
|
|
|
45
45
|
async replyToMessage(message, callback) {
|
|
46
46
|
return new Promise( async (resolve, reject) => {
|
|
47
|
-
// get bot info
|
|
48
|
-
// if (this.log) {
|
|
49
|
-
// console.log("replyToMessage():", JSON.stringify(message));
|
|
50
|
-
// }
|
|
51
47
|
let lead = null;
|
|
52
48
|
if (message.request) {
|
|
53
49
|
this.request = message.request;
|
|
54
|
-
lead = message.request.lead;
|
|
55
|
-
if (lead && lead.fullname) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (lead
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await this.addParameter("userEmail", lead.email);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (this.log) {
|
|
67
|
-
console.log("replyToMessage() > lead found:", JSON.stringify(lead));
|
|
50
|
+
// lead = message.request.lead;
|
|
51
|
+
// if (lead && lead.fullname) {
|
|
52
|
+
// if (this.log) {console.log("lead.fullname => params.userFullname:", lead.fullname)}
|
|
53
|
+
// await this.addParameter("userFullname", lead.fullname);
|
|
54
|
+
// }
|
|
55
|
+
// if (lead && lead.email) {
|
|
56
|
+
// if (this.log) {console.log("lead.email => params.userEmail:", lead.email)}
|
|
57
|
+
// await this.addParameter("userEmail", lead.email);
|
|
58
|
+
// }
|
|
68
59
|
}
|
|
60
|
+
// if (this.log) {
|
|
61
|
+
// console.log("replyToMessage() > lead found:", JSON.stringify(lead));
|
|
62
|
+
// }
|
|
69
63
|
|
|
70
64
|
// reset lockedIntent on direct user invocation ( /intent or action => this only?)
|
|
71
65
|
if (message.sender != "_tdinternal") {
|
|
@@ -23,6 +23,9 @@ class TiledeskChatbotConst {
|
|
|
23
23
|
static REQ_DECODED_JWT_KEY = "decodedCustomJWT";
|
|
24
24
|
static REQ_REQUESTER_IS_AUTHENTICATED_KEY = "strongAuthenticated";
|
|
25
25
|
static USER_INPUT = "_userInput";
|
|
26
|
+
static REQ_LEAD_USERFULLNAME_KEY = "userFullname";
|
|
27
|
+
static REQ_LEAD_EMAIL_KEY = "userEmail";
|
|
28
|
+
|
|
26
29
|
|
|
27
30
|
// static REQ_DEPARTMENT_ID_KEY = "tdDepartmentId";
|
|
28
31
|
// static REQ_PROJECT_ID_KEY = "projectId";
|
|
@@ -594,19 +594,16 @@ class TiledeskChatbotUtil {
|
|
|
594
594
|
// await chatbot.addParameter("lastUserDocumentType", null);
|
|
595
595
|
// }
|
|
596
596
|
if (message && message.request && message.request.lead) {
|
|
597
|
+
console.log("lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)
|
|
597
598
|
if (message.request.lead.email) {
|
|
598
|
-
await chatbot.addParameter(
|
|
599
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
|
|
599
600
|
}
|
|
600
|
-
if (message.request.lead.fullname && !message.request.lead.fullname.startsWith("guest#")) {
|
|
601
|
+
// if (message.request.lead.fullname && !message.request.lead.fullname.startsWith("guest#")) {
|
|
602
|
+
if (message.request.lead.fullname) {
|
|
601
603
|
// worth saving
|
|
604
|
+
console.log("worth saving. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)
|
|
602
605
|
try {
|
|
603
|
-
|
|
604
|
-
// if (current_userFullname && current_userFullname.startsWith("guest#")) { // replace if exists as guest#
|
|
605
|
-
// await chatbot.addParameter("userFullname", message.request.lead.fullname);
|
|
606
|
-
// }
|
|
607
|
-
// else if (!current_userFullname) {
|
|
608
|
-
await chatbot.addParameter("userFullname", message.request.lead.fullname);
|
|
609
|
-
// }
|
|
606
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
|
|
610
607
|
}
|
|
611
608
|
catch(error) {
|
|
612
609
|
console.error("Error on setting userFullname:", error);
|
|
@@ -702,6 +699,7 @@ class TiledeskChatbotUtil {
|
|
|
702
699
|
const value_type = typeof value;
|
|
703
700
|
//if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
|
|
704
701
|
//await chatbot.addParameter(key, String(value));
|
|
702
|
+
console.log("Adding from message.attributes:", key, "->", value);
|
|
705
703
|
await chatbot.addParameter(key, value);
|
|
706
704
|
}
|
|
707
705
|
}
|
|
@@ -777,6 +775,8 @@ class TiledeskChatbotUtil {
|
|
|
777
775
|
// "sub": "guest",
|
|
778
776
|
// "jti": "f053af3d-14ca-411b-9903-78bd74e24218"
|
|
779
777
|
// }
|
|
778
|
+
// let userFullname = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
|
|
779
|
+
// console.log("userFullname:", userFullname);
|
|
780
780
|
}
|
|
781
781
|
|
|
782
782
|
static actionsToDirectives(actions) {
|
package/package.json
CHANGED
|
@@ -62,7 +62,8 @@ class DirAskGPTV2 {
|
|
|
62
62
|
let temperature;
|
|
63
63
|
let max_tokens;
|
|
64
64
|
let top_k;
|
|
65
|
-
|
|
65
|
+
let default_context = "You are an helpful assistant for question-answering tasks.\nUse ONLY the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf none of the retrieved context answer the question, add this word to the end <NOANS>\n\n{context}";
|
|
66
|
+
|
|
66
67
|
let source = null;
|
|
67
68
|
|
|
68
69
|
if (!action.question || action.question === '') {
|
|
@@ -145,6 +146,7 @@ class DirAskGPTV2 {
|
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
|
|
148
150
|
let json = {
|
|
149
151
|
question: filled_question,
|
|
150
152
|
gptkey: key,
|
|
@@ -160,9 +162,17 @@ class DirAskGPTV2 {
|
|
|
160
162
|
if (max_tokens) {
|
|
161
163
|
json.max_tokens = max_tokens;
|
|
162
164
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
|
|
166
|
+
if (!action.advancedPrompt) {
|
|
167
|
+
if (filled_context) {
|
|
168
|
+
json.system_context = filled_context + "\n" + default_context;
|
|
169
|
+
} else {
|
|
170
|
+
json.system_context = default_context;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
json.system_context = filled_context;
|
|
165
174
|
}
|
|
175
|
+
|
|
166
176
|
if (this.log) { console.log("DirAskGPT json:", json); }
|
|
167
177
|
|
|
168
178
|
const HTTPREQUEST = {
|
|
@@ -119,10 +119,11 @@ class DirReply {
|
|
|
119
119
|
// callback(); // cancel reply operation
|
|
120
120
|
// return;
|
|
121
121
|
// }
|
|
122
|
-
|
|
122
|
+
|
|
123
123
|
cleanMessage.senderFullname = this.context.chatbot.bot.name;
|
|
124
124
|
if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
|
|
125
125
|
await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
|
|
126
|
+
// console.log("sending message!", cleanMessage);
|
|
126
127
|
this.context.tdclient.sendSupportMessage(
|
|
127
128
|
this.requestId,
|
|
128
129
|
cleanMessage,
|
|
@@ -130,7 +131,7 @@ class DirReply {
|
|
|
130
131
|
if (err) {
|
|
131
132
|
console.error("Error sending reply:", err);
|
|
132
133
|
}
|
|
133
|
-
if (this.log) {console.log("Reply message sent");}
|
|
134
|
+
if (this.log) {console.log("Reply message sent", cleanMessage);}
|
|
134
135
|
const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
|
|
135
136
|
// console.log("got total delay:", delay)
|
|
136
137
|
if (delay > 0 && delay <= 30000) { // prevent long delays
|