@tiledesk/tiledesk-tybot-connector 2.0.36-rc12 → 2.0.37
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 +3 -0
- package/engine/TiledeskChatbot.js +21 -67
- package/engine/TiledeskChatbotConst.js +0 -2
- package/index.js +0 -26
- package/logs/app.log +13651 -12759
- package/logs/app1.log +13327 -13395
- package/logs/app2.log +7679 -10185
- package/logs/app8.log +4066 -0
- package/logs/app9.log +5452 -0
- package/package.json +4 -3
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +1 -22
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirOfflineHours.js +4 -3
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +12 -11
- package/tiledeskChatbotPlugs/directives/DirAssign.js +7 -5
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +0 -26
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -35
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +0 -34
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +0 -22
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -24
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -30
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +0 -29
- package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +1 -25
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -32
- package/tiledeskChatbotPlugs/directives/DirWait.js +0 -8
- package/utils/TiledeskChatbotUtil.js +163 -139
- package/logs/app3.log +0 -161
- package/logs/app4.log +0 -46163
package/CHANGELOG.md
CHANGED
|
@@ -43,60 +43,48 @@ class TiledeskChatbot {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async replyToMessage(message, callback) {
|
|
46
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage start --> at : ${new Date().getTime()} for message.sender: ${message.sender} with text: ${message.text}`)
|
|
47
46
|
return new Promise( async (resolve, reject) => {
|
|
48
47
|
let lead = null;
|
|
49
48
|
if (message.request) {
|
|
50
49
|
this.request = message.request;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
let start00 = new Date();
|
|
52
|
+
// reset lockedIntent on direct user invocation ( /intent or action => this only?)
|
|
55
53
|
if (message.sender != "_tdinternal") {
|
|
56
54
|
try {
|
|
57
|
-
winston.verbose("(TiledeskChatbot)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
winston.debug("(TiledeskChatbot) Message has action: " + message.attributes.action);
|
|
64
|
-
ops.push(this.unlockIntent(this.requestId), this.unlockAction(this.requestId));
|
|
65
|
-
winston.debug("(TiledeskChatbot) Reset locked intent. Intent was explicitly invoked with an action: " + message.attributes.action);
|
|
55
|
+
winston.verbose("(TiledeskChatbot) Checking locked intent reset on action invocation")
|
|
56
|
+
if (message.attributes && message.attributes.action) {
|
|
57
|
+
winston.debug("(TiledeskChatbot) Message has action: " + message.attributes.action)
|
|
58
|
+
await this.unlockIntent(this.requestId);
|
|
59
|
+
await this.unlockAction(this.requestId);
|
|
60
|
+
winston.debug("(TiledeskChatbot) Reset locked intent. Intent was explicitly invoked with an action: " + message.attributes.action)
|
|
66
61
|
}
|
|
62
|
+
} catch(error) {
|
|
63
|
+
winston.error("(TiledeskChatbot) Error resetting locked intent: ", error)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
// any external invocation restarts the steps counter
|
|
68
|
+
try {
|
|
69
|
+
if (message.sender != "_tdinternal") {
|
|
70
70
|
winston.verbose("(TiledeskChatbot) Resetting current step by request message: " + message.text);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
TiledeskChatbot.resetStarted(this.tdcache, this.requestId)
|
|
74
|
-
);
|
|
71
|
+
await TiledeskChatbot.resetStep(this.tdcache, this.requestId);
|
|
72
|
+
await TiledeskChatbot.resetStarted(this.tdcache, this.requestId);
|
|
75
73
|
|
|
76
|
-
await Promise.all(ops);
|
|
77
|
-
|
|
78
|
-
// --- Debug final state ---
|
|
79
74
|
if (this.tdcache) {
|
|
80
|
-
|
|
75
|
+
let currentStep =
|
|
76
|
+
await TiledeskChatbot.currentStep(this.tdcache, this.requestId);
|
|
81
77
|
winston.verbose("(TiledeskChatbot) After reset currentStep:" + currentStep);
|
|
82
78
|
}
|
|
83
|
-
|
|
84
|
-
} catch (error) {
|
|
85
|
-
winston.error("(TiledeskChatbot) Error resetting locked intent: ", error)
|
|
79
|
+
|
|
86
80
|
}
|
|
81
|
+
} catch(error) {
|
|
82
|
+
winston.error("(TiledeskChatbot) Error resetting locked intent: ", error);
|
|
87
83
|
}
|
|
88
|
-
let end00 = new Date()
|
|
89
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 00--> after reset lockedIntent at : ${end00.getTime()}, diff: ${end00-start00}[ms]`)
|
|
90
|
-
|
|
91
|
-
|
|
92
84
|
|
|
93
85
|
// Checking locked intent (for non-internal intents)
|
|
94
86
|
// internal intents always "skip" the locked intent
|
|
95
|
-
let start0 = new Date()
|
|
96
87
|
const locked_intent = await this.currentLockedIntent(this.requestId);
|
|
97
|
-
let end0 = new Date()
|
|
98
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 0--> after currentLockedIntent at : ${end0.getTime()}, diff: ${end0-start0}[ms]`)
|
|
99
|
-
|
|
100
88
|
winston.verbose("(TiledeskChatbot) Got locked intent: -" + locked_intent + "-");
|
|
101
89
|
if (locked_intent) {
|
|
102
90
|
// const tdclient = new TiledeskClient({
|
|
@@ -107,18 +95,11 @@ class TiledeskChatbot {
|
|
|
107
95
|
// });
|
|
108
96
|
// it only gets the locked_intent
|
|
109
97
|
// const faq = await this.botsDataSource.getByIntentDisplayName(this.botId, locked_intent);
|
|
110
|
-
let start0 = new Date()
|
|
111
98
|
const faq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, locked_intent, this.tdcache);
|
|
112
|
-
let end0 = new Date()
|
|
113
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 1-> after botsDataSource.getByIntentDisplayNameCache at : ${end0.getTime()}, diff: ${end0-start0}[ms]`)
|
|
114
99
|
winston.debug("(TiledeskChatbot) Locked intent. Got faqs: ", faq);
|
|
115
100
|
let reply;
|
|
116
101
|
if (faq) {
|
|
117
|
-
let start1 = new Date()
|
|
118
102
|
reply = await this.execIntent(faq, message, lead);//, bot);
|
|
119
|
-
let end1 = new Date()
|
|
120
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 1--> after execIntent at : ${end1.getTime()}, diff: ${end1-start1}[ms]`)
|
|
121
|
-
|
|
122
103
|
}
|
|
123
104
|
else {
|
|
124
105
|
reply = {
|
|
@@ -167,10 +148,7 @@ class TiledeskChatbot {
|
|
|
167
148
|
}
|
|
168
149
|
else {
|
|
169
150
|
winston.verbose("(TiledeskChatbot) Processing intent:", explicit_intent_name)
|
|
170
|
-
let start2 = new Date()
|
|
171
151
|
let faq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, intent.name, this.tdcache);
|
|
172
|
-
let end2 = new Date()
|
|
173
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 2--> after botsDataSource.getByIntentDisplayNameCache at : ${end2.getTime()}, diff: ${end2-start2}[ms]`)
|
|
174
152
|
if (faq) {
|
|
175
153
|
winston.verbose("(TiledeskChatbot) Got a reply (faq) by Intent name:", faq)
|
|
176
154
|
try {
|
|
@@ -180,11 +158,7 @@ class TiledeskChatbot {
|
|
|
180
158
|
this.addParameter(key, value);
|
|
181
159
|
}
|
|
182
160
|
}
|
|
183
|
-
let start2 = new Date();
|
|
184
161
|
reply = await this.execIntent(faq, message, lead);
|
|
185
|
-
let end2 = new Date()
|
|
186
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 2--> after execIntent at : ${end2.getTime()}, diff: ${end2-start2}[ms]`)
|
|
187
|
-
|
|
188
162
|
resolve(reply);
|
|
189
163
|
return;
|
|
190
164
|
}
|
|
@@ -215,11 +189,7 @@ class TiledeskChatbot {
|
|
|
215
189
|
let reply;
|
|
216
190
|
const faq = faqs[0];
|
|
217
191
|
try {
|
|
218
|
-
let start3 = new Date();
|
|
219
192
|
reply = await this.execIntent(faq, message, lead);//, bot);
|
|
220
|
-
let end3 = new Date()
|
|
221
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 3--> after execIntent at : ${end3.getTime()}, diff: ${end3-start3}[ms]`)
|
|
222
|
-
|
|
223
193
|
}
|
|
224
194
|
catch(error) {
|
|
225
195
|
winston.error("(TiledeskChatbot) An error occured during exact match execIntent(): ", error);
|
|
@@ -247,18 +217,10 @@ class TiledeskChatbot {
|
|
|
247
217
|
}
|
|
248
218
|
winston.debug("(TiledeskChatbot) NLP intents found: ", intents);
|
|
249
219
|
if (intents && intents.length > 0) {
|
|
250
|
-
let start2 = new Date();
|
|
251
220
|
let faq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, intents[0].intent_display_name, this.tdcache);
|
|
252
|
-
let end2 = new Date()
|
|
253
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 4--> after botsDataSource.getByIntentDisplayNameCache in if at : ${end2.getTime()}, diff: ${end2-start2}[ms]`)
|
|
254
|
-
|
|
255
221
|
let reply;
|
|
256
222
|
try {
|
|
257
|
-
let start3 = new Date();
|
|
258
223
|
reply = await this.execIntent(faq, message, lead);//, bot);
|
|
259
|
-
let end3 = new Date()
|
|
260
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 4--> after execIntent in if at : ${end3.getTime()}, diff: ${end3-start3}[ms]`)
|
|
261
|
-
|
|
262
224
|
}
|
|
263
225
|
catch(error) {
|
|
264
226
|
winston.error("(TiledeskChatbot) An error occurred during NLP decoding: ", error);
|
|
@@ -269,11 +231,7 @@ class TiledeskChatbot {
|
|
|
269
231
|
return;
|
|
270
232
|
}
|
|
271
233
|
else {
|
|
272
|
-
let start4 = new Date();
|
|
273
234
|
let fallbackIntent = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, "defaultFallback", this.tdcache);
|
|
274
|
-
let end4 = new Date()
|
|
275
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 5--> after execIntent in else at : ${end4.getTime()}, diff: ${end4-start4}[ms]`)
|
|
276
|
-
|
|
277
235
|
if (!fallbackIntent) {
|
|
278
236
|
resolve(null);
|
|
279
237
|
return;
|
|
@@ -281,11 +239,7 @@ class TiledeskChatbot {
|
|
|
281
239
|
else {
|
|
282
240
|
let reply;
|
|
283
241
|
try {
|
|
284
|
-
let start5 = new Date()
|
|
285
242
|
reply = await this.execIntent(fallbackIntent, message, lead);//, bot);
|
|
286
|
-
let end5 = new Date()
|
|
287
|
-
console.log(`(GAB) TiledeskChatbot replyToMessage 5--> after execIntent at : ${end5.getTime()}, diff: ${end5-start5}[ms]`)
|
|
288
|
-
|
|
289
243
|
}
|
|
290
244
|
catch(error) {
|
|
291
245
|
winston.error("(TiledeskChatbot) An error occurred during defaultFallback: ", error);
|
|
@@ -40,8 +40,6 @@ class TiledeskChatbotConst {
|
|
|
40
40
|
static REQ_LAST_USER_IMAGE_HEIGHT = 'lastUserImageHeight';
|
|
41
41
|
static REQ_LAST_USER_IMAGE_TYPE = 'lastUserImageType';
|
|
42
42
|
static REQ_LAST_USER_DOCUMENT_URL = 'lastUserDocumentURL';
|
|
43
|
-
static REQ_LAST_USER_DOCUMENT_AS_ATTACHMENT_URL = 'lastUserDocumentAsAttachmentURL';
|
|
44
|
-
static REQ_LAST_USER_DOCUMENT_AS_INLINE_URL = 'lastUserDocumentAsInlineURL';
|
|
45
43
|
static REQ_LAST_USER_DOCUMENT_NAME = 'lastUserDocumentName';
|
|
46
44
|
static REQ_LAST_USER_DOCUMENT_TYPE = 'lastUserDocumentType';
|
|
47
45
|
static REQ_EMAIL_ATTACHMENTS_LINK = 'link';
|
package/index.js
CHANGED
|
@@ -43,7 +43,6 @@ let staticBots;
|
|
|
43
43
|
|
|
44
44
|
router.post('/ext/:botid', async (req, res) => {
|
|
45
45
|
const botId = req.params.botid;
|
|
46
|
-
console.log(`(GAB) /ext/${botId} 0--> called at : ${new Date().getTime()}`)
|
|
47
46
|
winston.verbose("(tybotRoute) POST /ext/:botid called: " + botId)
|
|
48
47
|
if(!botId || botId === "null" || botId === "undefined"){
|
|
49
48
|
return res.status(400).send({"success": false, error: "Required parameters botid not found. Value is 'null' or 'undefined'"})
|
|
@@ -91,7 +90,6 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
91
90
|
{EX: 604800} // 7 days
|
|
92
91
|
);
|
|
93
92
|
|
|
94
|
-
let start0 = new Date()
|
|
95
93
|
let botsDS;
|
|
96
94
|
if (!staticBots) {
|
|
97
95
|
botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId});
|
|
@@ -100,20 +98,13 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
100
98
|
else {
|
|
101
99
|
botsDS = new MockBotsDataSource(staticBots);
|
|
102
100
|
}
|
|
103
|
-
let end0 = new Date()
|
|
104
|
-
console.log(`(GAB) /ext/${botId} 1--> after get MongodbBotsDataSource at : ${end0.getTime()}, diff: ${end0-start0}[ms]`)
|
|
105
|
-
|
|
106
101
|
|
|
107
102
|
// get the bot metadata
|
|
108
|
-
let start1 = new Date()
|
|
109
103
|
let bot = await botsDS.getBotByIdCache(botId, tdcache).catch((err)=> {
|
|
110
104
|
Promise.reject(err);
|
|
111
105
|
return;
|
|
112
106
|
});
|
|
113
|
-
let end1 = new Date()
|
|
114
|
-
console.log(`(GAB) /ext/${botId} 2--> after get botsDS.getBotByIdCache at : ${end1.getTime()}, diff: ${end1-start1}[ms]`)
|
|
115
107
|
|
|
116
|
-
let start2 = new Date()
|
|
117
108
|
let intentsMachine;
|
|
118
109
|
let backupMachine;
|
|
119
110
|
if (!staticBots) {
|
|
@@ -124,8 +115,6 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
124
115
|
else {
|
|
125
116
|
intentsMachine = {}
|
|
126
117
|
}
|
|
127
|
-
let end2 = new Date()
|
|
128
|
-
console.log(`(GAB) /ext/${botId} 3--> after get IntentsMachineFactory.getMachine at : ${end2.getTime()}, diff: ${end2-start2}[ms]`)
|
|
129
118
|
|
|
130
119
|
const chatbot = new TiledeskChatbot({
|
|
131
120
|
botsDataSource: botsDS,
|
|
@@ -144,23 +133,14 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
144
133
|
});
|
|
145
134
|
winston.verbose("(tybotRoute) Message text: " + message.text)
|
|
146
135
|
|
|
147
|
-
let start3 = new Date()
|
|
148
136
|
await TiledeskChatbotUtil.updateRequestAttributes(chatbot, token, message, projectId, requestId);
|
|
149
|
-
let end3 = new Date()
|
|
150
|
-
console.log(`(GAB) /ext/${botId} 4--> after get TiledeskChatbotUtil.updateRequestAttributes at : ${end3.getTime()}, diff: ${end3-start3}[ms]`)
|
|
151
137
|
if (requestId.startsWith("support-group-")) {
|
|
152
138
|
await TiledeskChatbotUtil.updateConversationTranscript(chatbot, message);
|
|
153
139
|
}
|
|
154
|
-
let end4 = new Date()
|
|
155
|
-
console.log(`(GAB) /ext/${botId} 5--> after get TiledeskChatbotUtil.updateConversationTranscript at : ${end4.getTime()}, diff: ${end4-end3}[ms]`)
|
|
156
|
-
|
|
157
140
|
|
|
158
141
|
let reply = null;
|
|
159
142
|
try {
|
|
160
|
-
let start5 = new Date()
|
|
161
143
|
reply = await chatbot.replyToMessage(message);
|
|
162
|
-
let end5 = new Date()
|
|
163
|
-
console.log(`(GAB) /ext/${botId} 6--> after chatbot.replyToMessage at : ${end5.getTime()}, diff: ${end5-start5}[ms]`)
|
|
164
144
|
}
|
|
165
145
|
catch(err) {
|
|
166
146
|
winston.error("(tybotRoute) An error occurred replying to message: ", err);
|
|
@@ -171,16 +151,11 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
171
151
|
return;
|
|
172
152
|
}
|
|
173
153
|
|
|
174
|
-
|
|
175
154
|
if (reply.actions && reply.actions.length > 0) { // structured actions (coming from chatbot designer)
|
|
176
155
|
try {
|
|
177
|
-
let start6 = new Date()
|
|
178
156
|
winston.debug("(tybotRoute) Reply actions: ", reply.actions)
|
|
179
157
|
let directives = TiledeskChatbotUtil.actionsToDirectives(reply.actions);
|
|
180
158
|
winston.debug("(tybotRoute) the directives:", directives)
|
|
181
|
-
let end6 = new Date()
|
|
182
|
-
console.log(`(GAB) /ext/${botId} 7--> after TiledeskChatbotUtil.actionsToDirectives at : ${end6.getTime()}, diff: ${end6-start6}[ms]`)
|
|
183
|
-
|
|
184
159
|
let directivesPlug = new DirectivesChatbotPlug(
|
|
185
160
|
{
|
|
186
161
|
message: message,
|
|
@@ -195,7 +170,6 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
195
170
|
cache: tdcache
|
|
196
171
|
}
|
|
197
172
|
);
|
|
198
|
-
console.log(`(GAB) /ext/${botId} 8--> directivesPlug.processDirectives at : ${end6.getTime()}`)
|
|
199
173
|
directivesPlug.processDirectives( () => {
|
|
200
174
|
winston.verbose("(tybotRoute) Actions - Directives executed.");
|
|
201
175
|
});
|