@tiledesk/tiledesk-tybot-connector 0.2.85 → 0.2.86
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 +4 -0
- package/models/MockBotsDataSource.js +1 -1
- package/models/TiledeskChatbotUtil.js +6 -5
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +28 -27
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +74 -15
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +3 -2
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
|
+
# v0.2.86
|
|
9
|
+
- Added to ifOnlineAgents Action: ignoreProjectWideOperatingHours = action.ignoreOperatingHours;
|
|
10
|
+
- Updated ifOnlineAgents with get available agents with 'raw' option
|
|
11
|
+
|
|
8
12
|
# v0.2.85
|
|
9
13
|
- Improved "If operating hours" action with time slots
|
|
10
14
|
- Other fix (?)
|
|
@@ -78,7 +78,7 @@ class MockBotsDataSource {
|
|
|
78
78
|
async getByIntentDisplayNameCache(botId, key, tdcache) {
|
|
79
79
|
let faq = null;
|
|
80
80
|
if (tdcache) {
|
|
81
|
-
// console.log("mock
|
|
81
|
+
// console.log("mock cache. anyway in mock getting faq from datasource...");
|
|
82
82
|
faq = await this.getByIntentDisplayName(botId, key);
|
|
83
83
|
// console.log("faq found in datasource.:", JSON.stringify(faq));
|
|
84
84
|
}
|
|
@@ -598,8 +598,8 @@ class TiledeskChatbotUtil {
|
|
|
598
598
|
if (message.request.lead.email) {
|
|
599
599
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
|
|
600
600
|
}
|
|
601
|
-
|
|
602
|
-
if (message.request.lead.fullname) {
|
|
601
|
+
if (message.request.lead.fullname && !message.request.lead.fullname.startsWith("guest#")) {
|
|
602
|
+
// if (message.request.lead.fullname) {
|
|
603
603
|
// worth saving
|
|
604
604
|
console.log("worth saving. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)
|
|
605
605
|
try {
|
|
@@ -608,9 +608,10 @@ class TiledeskChatbotUtil {
|
|
|
608
608
|
catch(error) {
|
|
609
609
|
console.error("Error on setting userFullname:", error);
|
|
610
610
|
}
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
|
|
611
|
+
// }
|
|
612
|
+
// else {
|
|
613
|
+
// // console.log("!lead.fullname");
|
|
614
|
+
// }
|
|
614
615
|
}
|
|
615
616
|
// console.log("Getting userPhone:", JSON.stringify(message.request));
|
|
616
617
|
if (message.request.lead.phone) {
|
package/package.json
CHANGED
|
@@ -63,33 +63,34 @@ class DirContactUpdate {
|
|
|
63
63
|
// send hidden info to update widget lead fullname only if it is a conversation!
|
|
64
64
|
if (this.log) {console.log("(DirContactUpdate) requestId:", this.requestId); }
|
|
65
65
|
if (this.log) {console.log("(DirContactUpdate) updateProperties:", updateProperties); }
|
|
66
|
-
if (this.log) {console.log("(DirContactUpdate) updateProperties['
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
66
|
+
if (this.log) {console.log("(DirContactUpdate) updateProperties['fullname']:", updateProperties['fullname']); }
|
|
67
|
+
callback();
|
|
68
|
+
// if (this.requestId.startsWith("support-group") && updateProperties['userFullname']) {
|
|
69
|
+
// if (this.log) {console.log("(DirContactUpdate) send hidden info to update widget lead fullname"); }
|
|
70
|
+
// const userFullname = updateProperties['fullname'];
|
|
71
|
+
// const updateLeadDataOnWidgetMessage = {
|
|
72
|
+
// type: "text",
|
|
73
|
+
// text: "Updated lead fullname on widget with: " + userFullname,
|
|
74
|
+
// attributes: {
|
|
75
|
+
// // subtype: "info",
|
|
76
|
+
// updateUserFullname: userFullname
|
|
77
|
+
// }
|
|
78
|
+
// };
|
|
79
|
+
// if (this.log) {console.log("(DirContactUpdate) sending updateLeadDataOnWidgetMessage:", updateLeadDataOnWidgetMessage); }
|
|
80
|
+
// this.context.tdclient.sendSupportMessage(
|
|
81
|
+
// this.requestId,
|
|
82
|
+
// updateLeadDataOnWidgetMessage,
|
|
83
|
+
// (err) => {
|
|
84
|
+
// if (err) {
|
|
85
|
+
// console.error("(DirContactUpdate) Error sending reply:", err);
|
|
86
|
+
// }
|
|
87
|
+
// if (this.log) {console.log("(DirContactUpdate) hidden message sent:", updateLeadDataOnWidgetMessage);}
|
|
88
|
+
// callback();
|
|
89
|
+
// });
|
|
90
|
+
// }
|
|
91
|
+
// else {
|
|
92
|
+
// callback();
|
|
93
|
+
// }
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
}
|
|
@@ -52,8 +52,24 @@ class DirIfOnlineAgentsV2 {
|
|
|
52
52
|
let stopOnConditionMet = true; //action.stopOnConditionMet;
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const ignoreProjectWideOperatingHours = action.ignoreOperatingHours;
|
|
56
|
+
let isOpen = false;
|
|
57
|
+
if (ignoreProjectWideOperatingHours === true) {
|
|
58
|
+
// always go on to only check agents availability
|
|
59
|
+
isOpen = true;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const result = await this.openNow();
|
|
63
|
+
if (result && result.isopen) {
|
|
64
|
+
isOpen = true;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
isOpen = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// if (result && result.isopen) {
|
|
72
|
+
if (isOpen === true) { // always true if ignoreProjectWideOperatingHours = true
|
|
57
73
|
const selectedOption = action.selectedOption;
|
|
58
74
|
|
|
59
75
|
let agents;
|
|
@@ -102,11 +118,10 @@ class DirIfOnlineAgentsV2 {
|
|
|
102
118
|
}
|
|
103
119
|
else { // if (checkAll) => go project-wide
|
|
104
120
|
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all"); }
|
|
105
|
-
agents = await this.getProjectAvailableAgents();
|
|
121
|
+
agents = await this.getProjectAvailableAgents(true);
|
|
106
122
|
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
107
123
|
}
|
|
108
124
|
|
|
109
|
-
console.log("anyway qui...");
|
|
110
125
|
if (agents && agents.length > 0) {
|
|
111
126
|
if (trueIntent) {
|
|
112
127
|
let intentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
@@ -134,6 +149,18 @@ class DirIfOnlineAgentsV2 {
|
|
|
134
149
|
this.chatbot.addParameter("flowError", "(If online Agents) No path for 'no available agents' defined.");
|
|
135
150
|
callback();
|
|
136
151
|
}
|
|
152
|
+
} else {
|
|
153
|
+
if (falseIntent) {
|
|
154
|
+
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
155
|
+
if (this.log) {console.log("!agents (!openHours) => falseIntent");}
|
|
156
|
+
console.log("!agents (!openHours) => falseIntent BECAUSE CLOSED"); //PROD
|
|
157
|
+
this.intentDir.execute(intentDirective, () => {
|
|
158
|
+
callback();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
callback();
|
|
163
|
+
}
|
|
137
164
|
}
|
|
138
165
|
}
|
|
139
166
|
catch(err) {
|
|
@@ -157,19 +184,51 @@ class DirIfOnlineAgentsV2 {
|
|
|
157
184
|
});
|
|
158
185
|
}
|
|
159
186
|
|
|
160
|
-
async getProjectAvailableAgents() {
|
|
187
|
+
async getProjectAvailableAgents(raw, callback) {
|
|
161
188
|
return new Promise( (resolve, reject) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
189
|
+
const URL = `${this.context.TILEDESK_APIURL}/projects/${this.context.projectId}/users/availables?raw=${raw}`
|
|
190
|
+
const HTTPREQUEST = {
|
|
191
|
+
url: URL,
|
|
192
|
+
headers: {
|
|
193
|
+
'Content-Type' : 'application/json',
|
|
194
|
+
'Authorization': this.fixToken(this.context.token)
|
|
195
|
+
},
|
|
196
|
+
// json: true,
|
|
197
|
+
method: 'GET',
|
|
198
|
+
};
|
|
199
|
+
this.#myrequest(
|
|
200
|
+
HTTPREQUEST,
|
|
201
|
+
function(err, resbody) {
|
|
202
|
+
if (err) {
|
|
203
|
+
if (callback) {
|
|
204
|
+
callback(err);
|
|
205
|
+
}
|
|
206
|
+
reject(err);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
if (callback) {
|
|
210
|
+
callback(null, resbody);
|
|
211
|
+
}
|
|
212
|
+
resolve(resbody);
|
|
213
|
+
}
|
|
214
|
+
}, this.log);
|
|
215
|
+
});
|
|
216
|
+
|
|
171
217
|
}
|
|
172
218
|
|
|
219
|
+
// async getProjectAvailableAgents() {
|
|
220
|
+
// return new Promise( (resolve, reject) => {
|
|
221
|
+
// this.tdclient.getProjectAvailableAgents((err, agents) => {
|
|
222
|
+
// if (err) {
|
|
223
|
+
// reject(err);
|
|
224
|
+
// }
|
|
225
|
+
// else {
|
|
226
|
+
// resolve(agents);
|
|
227
|
+
// }
|
|
228
|
+
// });
|
|
229
|
+
// })
|
|
230
|
+
// }
|
|
231
|
+
|
|
173
232
|
async getDepartmentAvailableAgents(depId) {
|
|
174
233
|
return new Promise( (resolve, reject) => {
|
|
175
234
|
this.tdclient.getDepartment(depId, async (error, dep) => {
|
|
@@ -237,7 +296,7 @@ class DirIfOnlineAgentsV2 {
|
|
|
237
296
|
}
|
|
238
297
|
else {
|
|
239
298
|
// no group => assigned to all teammates
|
|
240
|
-
const agents = await this.getProjectAvailableAgents();
|
|
299
|
+
const agents = await this.getProjectAvailableAgents(true);
|
|
241
300
|
resolve(agents);
|
|
242
301
|
}
|
|
243
302
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
2
|
let axios = require('axios');
|
|
3
3
|
const { DirIntent } = require('./DirIntent');
|
|
4
|
+
let https = require("https");
|
|
4
5
|
const ms = require('minimist-string');
|
|
5
6
|
|
|
6
7
|
class DirIfOpenHours {
|
|
@@ -91,8 +92,8 @@ class DirIfOpenHours {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
let slot_id = null;
|
|
94
|
-
if (action.
|
|
95
|
-
slot_id = action.
|
|
95
|
+
if (action.slotId) {
|
|
96
|
+
slot_id = action.slotId;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|