@tiledesk/tiledesk-tybot-connector 0.1.94 → 0.1.95
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
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
### 0.1.95
|
|
9
|
+
- added "chatbot" instance to DirectivesChatbotPlug instance created in index.js
|
|
10
|
+
- Fix: missing key API_ENDPOINT in production
|
|
11
|
+
|
|
8
12
|
### 0.1.94
|
|
9
13
|
- Fix: last_user_message on _tdInternal sender
|
|
10
14
|
- Fix: missing filled question on GptTask Action
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const { Filler } = require('../Filler');
|
|
2
|
+
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
|
+
const { DirIntent } = require('./DirIntent');
|
|
4
|
+
const { DirLockIntent } = require('../tiledeskChatbotPlugs/directives/DirLockIntent');
|
|
5
|
+
const { DirUnlockIntent } = require('../tiledeskChatbotPlugs/directives/DirUnlockIntent');
|
|
6
|
+
|
|
7
|
+
class DirForm {
|
|
8
|
+
constructor(context) {
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('context object is mandatory.');
|
|
11
|
+
}
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.tdclient = context.tdclient;
|
|
14
|
+
this.tdcache = context.tdcache;
|
|
15
|
+
this.requestId = context.requestId;
|
|
16
|
+
this.intentDir = new DirIntent(context);
|
|
17
|
+
this.log = context.log;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
execute(directive, callback) {
|
|
21
|
+
let action;
|
|
22
|
+
if (directive.action) {
|
|
23
|
+
action = directive.action;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
console.error("Incorrect directive:", JSON.stringify(directive));
|
|
27
|
+
callback();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.go(action, (stop) => {
|
|
31
|
+
if (this.log) {console.log("(webrequestv2, stop?", stop); }
|
|
32
|
+
callback(stop);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async go(action, callback) {
|
|
37
|
+
let intent_name = answerObj.intent_display_name
|
|
38
|
+
// THE FORM
|
|
39
|
+
// if (intent_name === "test_form_intent") {
|
|
40
|
+
// answerObj.form = {
|
|
41
|
+
// "cancelCommands": ['reset', 'cancel'],
|
|
42
|
+
// "cancelReply": "Ok canceled!",
|
|
43
|
+
// "fields": [
|
|
44
|
+
// {
|
|
45
|
+
// "name": "userFullname",
|
|
46
|
+
// "type": "text",
|
|
47
|
+
// "label": "What is your name?\n* Andrea\n* Marco\n* Mirco\n* Luca Leo"
|
|
48
|
+
// },{
|
|
49
|
+
// "name": "companyName",
|
|
50
|
+
// "type": "text",
|
|
51
|
+
// "label": "Thank you ${userFullname}! What is your Company name?\n* Tiledesk\n* Frontiere21"
|
|
52
|
+
// },
|
|
53
|
+
// {
|
|
54
|
+
// "name": "userEmail",
|
|
55
|
+
// "type": "text",
|
|
56
|
+
// "regex": "/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/",
|
|
57
|
+
// "label": "Hi ${userFullname} from ${companyName}\n\nJust one last question\n\nYour email 🙂\n* andrea@libero.it\n* andrea@tiledesk.com",
|
|
58
|
+
// "errorLabel": "${userFullname} this email address is invalid\n\nCan you insert a correct email address?"
|
|
59
|
+
// }
|
|
60
|
+
// ]
|
|
61
|
+
// };
|
|
62
|
+
// }
|
|
63
|
+
let intent_form = answerObj.form;
|
|
64
|
+
if (this.log) {
|
|
65
|
+
console.log("IntentForm.isValidForm(intent_form)", IntentForm.isValidForm(intent_form));
|
|
66
|
+
}
|
|
67
|
+
let clientUpdateUserFullname = null;
|
|
68
|
+
if (IntentForm.isValidForm(intent_form)) {
|
|
69
|
+
await this.lockIntent(this.requestId, intent_name);
|
|
70
|
+
const user_reply = message.text;
|
|
71
|
+
let form_reply = await this.execIntentForm(user_reply, intent_form);
|
|
72
|
+
// console.log("got form reply", form_reply)
|
|
73
|
+
if (!form_reply.canceled && form_reply.message) {
|
|
74
|
+
// console.log("Form replying for next field...");
|
|
75
|
+
if (this.log) {console.log("Sending form reply...", form_reply.message)}
|
|
76
|
+
// reply with this message (ex. please enter your fullname)
|
|
77
|
+
if (!form_reply.message.attributes) {
|
|
78
|
+
form_reply.message.attributes = {}
|
|
79
|
+
}
|
|
80
|
+
form_reply.message.attributes.fillParams = true;
|
|
81
|
+
form_reply.message.attributes.splits = true;
|
|
82
|
+
form_reply.message.attributes.markbot = true;
|
|
83
|
+
return form_reply.message;
|
|
84
|
+
}
|
|
85
|
+
else if (form_reply.end) {
|
|
86
|
+
if (this.log) {
|
|
87
|
+
console.log("FORM end.", );
|
|
88
|
+
console.log("unlocking intent for request:", this.requestId);
|
|
89
|
+
console.log("populate data on lead:", JSON.stringify(lead));
|
|
90
|
+
}
|
|
91
|
+
this.unlockIntent(this.requestId);
|
|
92
|
+
if (lead) {
|
|
93
|
+
this.populatePrechatFormAndLead(lead._id, this.requestId);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (this.log) {console.log("No lead. Skipping populatePrechatFormAndLead()");}
|
|
97
|
+
}
|
|
98
|
+
const all_parameters = await this.allParameters();
|
|
99
|
+
// if (this.log) {console.log("We have all_parameters:", all_parameters)};
|
|
100
|
+
if (all_parameters && all_parameters["userFullname"]) {
|
|
101
|
+
clientUpdateUserFullname = all_parameters["userFullname"];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (form_reply.canceled) {
|
|
105
|
+
console.log("Form canceled.");
|
|
106
|
+
if (this.log) {console.log("unlocking intent due to canceling, for request", this.requestId);}
|
|
107
|
+
this.unlockIntent(this.requestId);
|
|
108
|
+
if (this.log) {console.log("sending form 'cancel' reply...", form_reply.message)}
|
|
109
|
+
// reply with this message (ex. please enter your fullname)
|
|
110
|
+
if (!form_reply.message.attributes) {
|
|
111
|
+
form_reply.message.attributes = {}
|
|
112
|
+
}
|
|
113
|
+
form_reply.message.attributes.fillParams = true;
|
|
114
|
+
form_reply.message.attributes.splits = true;
|
|
115
|
+
form_reply.message.attributes.directives = true;
|
|
116
|
+
// // used by the Clients to get some info about the intent that generated this reply
|
|
117
|
+
// form_reply.message.attributes.intent_display_name = faq.intent_display_name;
|
|
118
|
+
// form_reply.message.attributes.intent_id = faq.intent_id;
|
|
119
|
+
return form_reply.message
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// FORM END
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async lockIntent(requestId, intent_name) {
|
|
126
|
+
// await this.tdcache.set("tilebot:requests:" + requestId + ":locked", intent_name);
|
|
127
|
+
await DirLockIntent.lockIntent(this.tdcache, requestId, intent_name);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { DirForm };
|
|
@@ -52,6 +52,14 @@ class DirGptTask {
|
|
|
52
52
|
this.tdcache, this.requestId
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
+
if (this.log) {
|
|
56
|
+
console.log("*** GPT PARTITA ***")
|
|
57
|
+
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
58
|
+
for (const [key, value] of Object.entries(all_parameters)) {
|
|
59
|
+
if (this.log) { console.log("(askgpt) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
// not necessary ?
|
|
56
64
|
const filler = new Filler();
|
|
57
65
|
const filled_question = filler.fill(action.question, requestVariables);
|
|
@@ -64,7 +72,8 @@ class DirGptTask {
|
|
|
64
72
|
console.log("temperature: ", temperature);
|
|
65
73
|
}
|
|
66
74
|
|
|
67
|
-
const
|
|
75
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
76
|
+
const kb_url = server_base_url + "/" + this.context.projectId + "/kbsettings";
|
|
68
77
|
if (this.log) { console.log("ApiEndpoint URL: ", kb_url); }
|
|
69
78
|
const KB_HTTPREQUEST = {
|
|
70
79
|
url: kb_url,
|