@tiledesk/tiledesk-tybot-connector 0.5.0 → 2.0.0
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 +4 -83
- package/ExtUtil.js +0 -1
- package/Logger.js +105 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/{models → engine}/IntentForm.js +30 -44
- package/{models → engine}/IntentsMachineFactory.js +5 -4
- package/{models → engine}/MongodbBotsDataSource.js +31 -55
- package/{models → engine}/MongodbIntentsMachine.js +6 -5
- package/{models → engine}/TiledeskChatbot.js +82 -259
- package/{models → engine}/TiledeskChatbotConst.js +9 -0
- package/{models → engine}/TiledeskIntentsMachine.js +5 -15
- package/{models → engine/mock}/MockBotsDataSource.js +3 -19
- package/{models → engine/mock}/MockTdCache.js +0 -9
- package/index.js +103 -380
- package/logs/app.log +12723 -277
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +5 -2
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
- 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 +49 -135
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
- package/tiledeskChatbotPlugs/Filler.js +0 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
- package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
- package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
- package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
- package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +164 -234
- package/utils/winston.js +42 -0
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const { param } = require('express/lib/request');
|
|
2
2
|
const ms = require('minimist-string');
|
|
3
|
-
const { TiledeskChatbot } = require('../../
|
|
3
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
4
4
|
const { Filler } = require('../Filler');
|
|
5
|
+
const winston = require('../../utils/winston');
|
|
5
6
|
|
|
6
7
|
class DirDeleteVariable {
|
|
7
8
|
|
|
@@ -14,6 +15,7 @@ class DirDeleteVariable {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
async execute(directive, callback) {
|
|
18
|
+
winston.verbose("Execute DeleteVariable directive");
|
|
17
19
|
let action;
|
|
18
20
|
if (directive.action) {
|
|
19
21
|
action = directive.action
|
|
@@ -29,11 +31,11 @@ class DirDeleteVariable {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
async go(action, callback) {
|
|
32
|
-
|
|
34
|
+
winston.debug("(DirDeleteVariable) Action: ", action);
|
|
35
|
+
|
|
33
36
|
let variableName = action.variableName;
|
|
34
|
-
// console.log("DirDeleteVariable:", directive);
|
|
35
37
|
if (!variableName) {
|
|
36
|
-
|
|
38
|
+
winston.error("(DirDeleteVariable) deleting variable. Missing 'variableName' error. Skipping");
|
|
37
39
|
if (callback) {
|
|
38
40
|
callback();
|
|
39
41
|
}
|
|
@@ -46,11 +48,9 @@ class DirDeleteVariable {
|
|
|
46
48
|
await TiledeskChatbot.allParametersStatic(
|
|
47
49
|
this.context.tdcache, this.context.requestId
|
|
48
50
|
);
|
|
49
|
-
|
|
51
|
+
|
|
50
52
|
const filler = new Filler();
|
|
51
|
-
// console.log("delete variable name:", variableName);
|
|
52
53
|
variableName = filler.fill(variableName, variables);
|
|
53
|
-
// console.log("delete variable name (after filling):", variableName);
|
|
54
54
|
await TiledeskChatbot.deleteParameterStatic(
|
|
55
55
|
this.context.tdcache, this.context.requestId, variableName
|
|
56
56
|
);
|
|
@@ -60,7 +60,7 @@ class DirDeleteVariable {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
catch(err) {
|
|
63
|
-
|
|
63
|
+
winston.error("(DirDeleteVariable) error: ", err);
|
|
64
64
|
if (completion) {
|
|
65
65
|
completion();
|
|
66
66
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
2
|
+
const winston = require('../../utils/winston');
|
|
2
3
|
|
|
3
4
|
class DirDepartment {
|
|
4
5
|
|
|
@@ -21,7 +22,7 @@ class DirDepartment {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
execute(directive, callback) {
|
|
24
|
-
|
|
25
|
+
winston.verbose("Execute Department directive");
|
|
25
26
|
let action;
|
|
26
27
|
if (directive.action) {
|
|
27
28
|
action = directive.action;
|
|
@@ -61,15 +62,15 @@ class DirDepartment {
|
|
|
61
62
|
// }
|
|
62
63
|
|
|
63
64
|
go(action, callback) {
|
|
64
|
-
|
|
65
|
+
winston.debug("(DirDepartment) Action: ", action);
|
|
65
66
|
const depName = action.depName;
|
|
66
67
|
this.moveToDepartment(this.requestId, depName, (deps) => {
|
|
67
68
|
if (!deps) {
|
|
68
|
-
|
|
69
|
+
winston.warn("(DirDepartment) Dep not found");
|
|
69
70
|
callback();
|
|
70
71
|
return
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
winston.debug("(DirDepartment) Switched to dept: " + depName + " action: " + JSON.stringify(action));
|
|
73
74
|
if (action.triggerBot) {
|
|
74
75
|
let dep = null;
|
|
75
76
|
let i;
|
|
@@ -81,7 +82,7 @@ class DirDepartment {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
if (dep && dep.hasBot === true && dep.id_bot) {
|
|
84
|
-
|
|
85
|
+
winston.debug("(DirDepartment) Sending hidden /start message to bot in dept");
|
|
85
86
|
const message = {
|
|
86
87
|
type: "text",
|
|
87
88
|
text: "/start",
|
|
@@ -93,15 +94,15 @@ class DirDepartment {
|
|
|
93
94
|
this.requestId,
|
|
94
95
|
message, (err) => {
|
|
95
96
|
if (err) {
|
|
96
|
-
|
|
97
|
+
winston.error("(DirDepartment) Error sending hidden message: " + err.message)
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
+
winston.debug("(DirDepartment) Hidden message sent.");
|
|
99
100
|
callback();
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
|
-
|
|
105
|
+
winston.debug("(DirDepartment) No action.triggerBot");
|
|
105
106
|
callback();
|
|
106
107
|
}
|
|
107
108
|
});
|
|
@@ -109,9 +110,9 @@ class DirDepartment {
|
|
|
109
110
|
|
|
110
111
|
moveToDepartment(requestId, depName, callback) {
|
|
111
112
|
this.tdClient.getAllDepartments((err, deps) => {
|
|
112
|
-
|
|
113
|
+
winston.debug("(DirDepartment) deps: ", deps);
|
|
113
114
|
if (err) {
|
|
114
|
-
|
|
115
|
+
winston.error("(DirDepartment) getAllDepartments() error: ", err);
|
|
115
116
|
callback();
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
@@ -127,11 +128,11 @@ class DirDepartment {
|
|
|
127
128
|
if (dep) {
|
|
128
129
|
this.tdClient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
|
|
129
130
|
if (err) {
|
|
130
|
-
|
|
131
|
+
winston.error("(DirDepartment) updatedRequestDepartment error: ", err);
|
|
131
132
|
callback();
|
|
132
133
|
}
|
|
133
134
|
else {
|
|
134
|
-
|
|
135
|
+
winston.debug("(DirDepartment) response: ", res);
|
|
135
136
|
callback(deps);
|
|
136
137
|
}
|
|
137
138
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const ms = require('minimist-string');
|
|
2
|
+
const winston = require('../../utils/winston');
|
|
2
3
|
|
|
3
4
|
// DEPRECATED
|
|
4
5
|
class DirDisableInputText {
|
|
@@ -7,7 +8,7 @@ class DirDisableInputText {
|
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
execute(directive, pipeline, callback) {
|
|
10
|
-
|
|
11
|
+
winston.verbose("Execute DisableInputText directive");
|
|
11
12
|
let message = pipeline.message
|
|
12
13
|
if (!message.attributes) {
|
|
13
14
|
message.attributes = {}
|
|
@@ -15,10 +16,8 @@ class DirDisableInputText {
|
|
|
15
16
|
message.attributes.disableInputMessage = true;
|
|
16
17
|
if (directive.parameter) {
|
|
17
18
|
const options = this.parseParams(directive.parameter);
|
|
18
|
-
// console.log("Options", options)
|
|
19
19
|
directive.options = options;
|
|
20
20
|
if (options.label) {
|
|
21
|
-
// console.log("options.label", options.label)
|
|
22
21
|
message.attributes.inputMessagePlaceholder = options.label;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
@@ -28,13 +27,10 @@ class DirDisableInputText {
|
|
|
28
27
|
parseParams(directive_parameter) {
|
|
29
28
|
let label = null;
|
|
30
29
|
const params = ms(directive_parameter);
|
|
31
|
-
// console.log("params:", params);
|
|
32
30
|
if (params.l) {
|
|
33
|
-
// console.log("_param l", params.l);
|
|
34
31
|
label = params.l;
|
|
35
32
|
}
|
|
36
33
|
if (params.label) {
|
|
37
|
-
// console.log("_param label", params.label);
|
|
38
34
|
label = params.label;
|
|
39
35
|
}
|
|
40
36
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
2
|
const ms = require('minimist-string');
|
|
3
|
+
const winston = require('../../utils/winston');
|
|
3
4
|
|
|
4
5
|
class DirFireTiledeskEvent {
|
|
5
6
|
|
|
@@ -22,6 +23,7 @@ class DirFireTiledeskEvent {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
execute(directive, callback) {
|
|
26
|
+
winston.verbose("Execute FireTiledeskEvent directive");
|
|
25
27
|
if (directive.parameter) {
|
|
26
28
|
const params = this.parseParams(directive.parameter);
|
|
27
29
|
const event_name = params.name;
|
|
@@ -31,15 +33,13 @@ class DirFireTiledeskEvent {
|
|
|
31
33
|
}
|
|
32
34
|
this.tdClient.fireEvent(event, function(err, result) {
|
|
33
35
|
if (err) {
|
|
34
|
-
|
|
36
|
+
winston.error("(FireTiledeskEvent) An error occurred invoking an event: ", err);
|
|
35
37
|
}
|
|
36
38
|
callback();
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
else {
|
|
40
|
-
|
|
41
|
-
console.log("DirFireTiledeskEvent: no parameter");
|
|
42
|
-
}
|
|
42
|
+
winston.verbose("(DirFireTiledeskEvent) no parameter");
|
|
43
43
|
callback();
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const { Filler } = require('../Filler');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
3
|
const { DirIntent } = require('./DirIntent');
|
|
4
|
-
const { IntentForm } = require('../../
|
|
4
|
+
const { IntentForm } = require('../../engine/IntentForm.js');
|
|
5
5
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
6
|
+
const winston = require('../../utils/winston');
|
|
6
7
|
|
|
7
8
|
class DirForm {
|
|
8
9
|
constructor(context) {
|
|
@@ -28,17 +29,17 @@ class DirForm {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
execute(directive, callback) {
|
|
32
|
+
winston.verbose("Execute Form directive");
|
|
31
33
|
let action;
|
|
32
34
|
if (directive.action) {
|
|
33
35
|
action = directive.action;
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
|
-
|
|
38
|
+
winston.warn("DirForm Incorrect directive: ", directive);
|
|
37
39
|
callback();
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
42
|
this.go(action, (stop) => {
|
|
41
|
-
if (this.log) {console.log("(DirForm, stop?", stop); }
|
|
42
43
|
callback(stop);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -72,18 +73,15 @@ class DirForm {
|
|
|
72
73
|
const trueIntent = action.trueIntent; // edit-end (success)
|
|
73
74
|
const falseIntent = action.falseIntent; // cancel
|
|
74
75
|
let form = action.form;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
76
|
+
winston.debug("(DirForm) IntentForm.isValidForm(intent_form) " + IntentForm.isValidForm(form));
|
|
77
|
+
|
|
78
78
|
let clientUpdateUserFullname = null;
|
|
79
79
|
if (IntentForm.isValidForm(form)) {
|
|
80
80
|
await this.chatbot.lockAction(this.requestId, action.action_id);
|
|
81
81
|
const user_reply = message.text;
|
|
82
82
|
let form_reply = await this.execIntentForm(user_reply, form);
|
|
83
|
-
// console.log("got form reply", form_reply)
|
|
84
83
|
if (!form_reply.canceled && form_reply.message) {
|
|
85
|
-
|
|
86
|
-
if (this.log) {console.log("Sending form reply...", form_reply.message)}
|
|
84
|
+
winston.debug("(DirForm) Sending form reply...", form_reply.message)
|
|
87
85
|
// reply with this message (ex. please enter your fullname)
|
|
88
86
|
if (!form_reply.message.attributes) {
|
|
89
87
|
form_reply.message.attributes = {}
|
|
@@ -98,18 +96,17 @@ class DirForm {
|
|
|
98
96
|
form_reply.message,
|
|
99
97
|
(err) => {
|
|
100
98
|
if (err) {
|
|
101
|
-
|
|
99
|
+
winston.error("(DirForm) Error sending form reply: " + err.message);
|
|
102
100
|
}
|
|
103
|
-
|
|
101
|
+
winston.debug("(DirForm) Form reply message sent.");
|
|
104
102
|
callback(true);
|
|
105
103
|
});
|
|
106
104
|
}
|
|
107
105
|
else if (form_reply.end) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
106
|
+
winston.debug("(DirForm) FORM end.", );
|
|
107
|
+
winston.debug("(DirForm) unlocking intent for request: " + this.requestId);
|
|
108
|
+
winston.debug("(DirForm) populate data on lead: ", lead);
|
|
109
|
+
|
|
113
110
|
this.chatbot.unlockAction(this.requestId);
|
|
114
111
|
|
|
115
112
|
if (callback) {
|
|
@@ -121,16 +118,13 @@ class DirForm {
|
|
|
121
118
|
// if (lead) {
|
|
122
119
|
// this.populatePrechatFormAndLead(lead._id, this.requestId);
|
|
123
120
|
// }
|
|
124
|
-
// else {
|
|
125
|
-
// if (this.log) {console.log("No lead. Skipping populatePrechatFormAndLead()");}
|
|
126
|
-
// }
|
|
127
121
|
// const all_parameters = await this.chatbot.allParameters();
|
|
128
122
|
// if (all_parameters && all_parameters["userFullname"]) {
|
|
129
123
|
// clientUpdateUserFullname = all_parameters["userFullname"];
|
|
130
124
|
// }
|
|
131
125
|
}
|
|
132
126
|
else if (form_reply.canceled) {
|
|
133
|
-
|
|
127
|
+
winston.debug("(DirForm) unlocking intent due to canceling, for request " + this.requestId);
|
|
134
128
|
this.unlockAction(this.requestId);
|
|
135
129
|
|
|
136
130
|
// TODO: INVOKE DIR_INTENT FOR CANCEL.
|
|
@@ -140,7 +134,6 @@ class DirForm {
|
|
|
140
134
|
});
|
|
141
135
|
}
|
|
142
136
|
|
|
143
|
-
// if (this.log) {console.log("sending form 'cancel' reply...", form_reply.message)}
|
|
144
137
|
// TODO: REMOVE CANCEL REPLY
|
|
145
138
|
// reply with this message (ex. please enter your fullname)
|
|
146
139
|
// if (!form_reply.message.attributes) {
|
|
@@ -174,7 +167,7 @@ class DirForm {
|
|
|
174
167
|
});
|
|
175
168
|
}
|
|
176
169
|
else {
|
|
177
|
-
|
|
170
|
+
winston.debug("(DirForm) No trueIntentDirective specified");
|
|
178
171
|
callback();
|
|
179
172
|
}
|
|
180
173
|
}
|
|
@@ -185,7 +178,7 @@ class DirForm {
|
|
|
185
178
|
});
|
|
186
179
|
}
|
|
187
180
|
else {
|
|
188
|
-
|
|
181
|
+
winston.debug("(DirForm) No falseIntentDirective specified");
|
|
189
182
|
callback();
|
|
190
183
|
}
|
|
191
184
|
}
|