@tiledesk/tiledesk-tybot-connector 0.1.39 → 0.1.40
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/package.json +2 -2
- package/test/send_email_directive_test.js +87 -0
- package/test/single_test.sh +2 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +6 -0
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +90 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
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.40
|
|
9
|
+
- tiledesk-client => 0.9.5
|
|
10
|
+
- added _tdSendEmail directive
|
|
11
|
+
|
|
8
12
|
### 0.1.39 - online
|
|
9
13
|
- ExtApi.sendSupportMessageExt => added support for rejectUnauthorized: false
|
|
10
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@tiledesk/helpcenter-query-client": "^0.1.8",
|
|
15
15
|
"@tiledesk/tiledesk-chatbot-client": "^0.5.30",
|
|
16
16
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.38",
|
|
17
|
-
"@tiledesk/tiledesk-client": "^0.9.
|
|
17
|
+
"@tiledesk/tiledesk-client": "^0.9.5",
|
|
18
18
|
"axios": "^0.27.2",
|
|
19
19
|
"body-parser": "^1.19.0",
|
|
20
20
|
"cors": "^2.8.5",
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
const { ExtUtil } = require('../ExtUtil');
|
|
3
|
+
const { DirectivesChatbotPlug } = require('../tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
4
|
+
const { DirSendEmail } = require('../tiledeskChatbotPlugs/directives/DirSendEmail');
|
|
5
|
+
const supportRequest = require('./support_request.js').request;
|
|
6
|
+
|
|
7
|
+
describe('Directive DirSendEmail', function() {
|
|
8
|
+
|
|
9
|
+
it('test directive DirSendEmail', async () => {
|
|
10
|
+
class MockTdClient {
|
|
11
|
+
async sendEmail(message, callback) {
|
|
12
|
+
if (callback) {
|
|
13
|
+
callback(null, message);
|
|
14
|
+
}
|
|
15
|
+
return message;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
send_email_directive = {
|
|
19
|
+
name: "sendemail",
|
|
20
|
+
parameter: '--to "test@test" --subject "test" --text "test"'
|
|
21
|
+
};
|
|
22
|
+
let dir = new DirSendEmail({
|
|
23
|
+
tdclient: new MockTdClient()
|
|
24
|
+
});
|
|
25
|
+
let requestId = null;
|
|
26
|
+
const message = await dir.execute(send_email_directive, requestId) //, "err").to.be.null;
|
|
27
|
+
// console.error("Was expecting an error for the 'to' missing parameter");
|
|
28
|
+
console.log("message:", message);
|
|
29
|
+
assert(message);
|
|
30
|
+
assert(message.to);
|
|
31
|
+
assert(message.text);
|
|
32
|
+
assert(message.subject);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('test directive DirSendEmail with missing "to"', async () => {
|
|
36
|
+
class MockTdClient {
|
|
37
|
+
async sendEmail(message, callback) {
|
|
38
|
+
if (callback) {
|
|
39
|
+
callback(null, message);
|
|
40
|
+
}
|
|
41
|
+
return message;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
send_email_directive = {
|
|
45
|
+
name: "sendemail",
|
|
46
|
+
parameter: '--subject "test" --text "_test"'
|
|
47
|
+
};
|
|
48
|
+
let dir = new DirSendEmail({
|
|
49
|
+
tdclient: new MockTdClient()
|
|
50
|
+
});
|
|
51
|
+
let requestId = null;
|
|
52
|
+
// try {
|
|
53
|
+
const message = await dir.execute(send_email_directive, requestId) //, "err").to.be.null;
|
|
54
|
+
// console.error("Was expecting an error for the 'to' missing parameter");
|
|
55
|
+
assert(message == null);
|
|
56
|
+
// }
|
|
57
|
+
// catch(err) {
|
|
58
|
+
// //console.log("Error is ok", err);
|
|
59
|
+
// if (!err.message.startsWith("sendEmail missing mandatory parameters")) {
|
|
60
|
+
// assert.ok(false);
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('test directive DirSendEmail in pipeline', async () => {
|
|
66
|
+
const message_text = `\\_tdsendemail --to "test@test" --subject "_sub" --text "_body"`;
|
|
67
|
+
const answer = {
|
|
68
|
+
text: message_text,
|
|
69
|
+
attributes: {
|
|
70
|
+
splits: true,
|
|
71
|
+
directives: true,
|
|
72
|
+
markbot: true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
|
|
76
|
+
const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
|
|
77
|
+
assert(bot_answer == null);
|
|
78
|
+
assert(directivesPlug.directives != null);
|
|
79
|
+
assert(directivesPlug.directives.length == 1);
|
|
80
|
+
assert(directivesPlug.directives[0].name === "sendemail");
|
|
81
|
+
assert(directivesPlug.directives[0].parameter === '--to "test@test" --subject "_sub" --text "_body"');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
package/test/single_test.sh
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
#npx mocha ./test/mock_query_test.js
|
|
3
3
|
#npx mocha ./test/disable_input_text_directive_test.js
|
|
4
4
|
#npx mocha ./test/close_directive_test.js
|
|
5
|
-
npx mocha ./test/conversation1-test.js --exit
|
|
5
|
+
#npx mocha ./test/conversation1-test.js --exit
|
|
6
6
|
#npx mocha ./test/intent_form_test.js --exit
|
|
7
|
+
npx mocha ./test/send_email_directive_test.js --exit
|
|
@@ -15,6 +15,7 @@ const { DirDisableInputText } = require('./directives/DirDisableInputText');
|
|
|
15
15
|
const { DirClose } = require('./directives/DirClose');
|
|
16
16
|
const { DirIfAvailableAgents } = require('./directives/DirIfAvailableAgents');
|
|
17
17
|
const { DirFireTiledeskEvent } = require('./directives/DirFireTiledeskEvent');
|
|
18
|
+
const { DirSendEmail } = require('./directives/DirSendEmail');
|
|
18
19
|
const { Directives } = require('./directives/Directives');
|
|
19
20
|
|
|
20
21
|
class DirectivesChatbotPlug {
|
|
@@ -267,6 +268,11 @@ class DirectivesChatbotPlug {
|
|
|
267
268
|
process(nextDirective());
|
|
268
269
|
});
|
|
269
270
|
}
|
|
271
|
+
else if (directive_name === Directives.SEND_EMAIL) {
|
|
272
|
+
new DirSendEmail({tdclient: tdclient}).execute(directive, requestId, () => {
|
|
273
|
+
process(nextDirective());
|
|
274
|
+
});
|
|
275
|
+
}
|
|
270
276
|
else {
|
|
271
277
|
//console.log("Unhandled Post-message Directive:", directive_name);
|
|
272
278
|
process(nextDirective());
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//const { HelpCenter } = require('./HelpCenter');
|
|
2
|
+
const { HelpCenterQuery } = require('@tiledesk/helpcenter-query-client');
|
|
3
|
+
const { param } = require('express/lib/request');
|
|
4
|
+
const ms = require('minimist-string');
|
|
5
|
+
|
|
6
|
+
class DirSendEmail {
|
|
7
|
+
|
|
8
|
+
constructor(config) {
|
|
9
|
+
if (!config.tdclient) {
|
|
10
|
+
throw new Error('config.tdclient (TiledeskClient) object is mandatory.');
|
|
11
|
+
}
|
|
12
|
+
this.tdclient = config.tdclient;
|
|
13
|
+
this.log = config.log;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async execute(directive, requestId, completion) {
|
|
17
|
+
// return new Promise( (resolve, reject) => {
|
|
18
|
+
let params = null;
|
|
19
|
+
if (directive.parameter) {
|
|
20
|
+
// console.log("processing sendEmail parameters");
|
|
21
|
+
params = this.parseParams(directive.parameter);
|
|
22
|
+
// console.log("parameters found", params);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.log("sendEmail missing parameter error. Skipping");
|
|
26
|
+
const error = new Error("sendEmail missing 'parameter' error. Skipping");
|
|
27
|
+
if (completion) {
|
|
28
|
+
completion(error);
|
|
29
|
+
}
|
|
30
|
+
// reject(error);
|
|
31
|
+
// throw error;
|
|
32
|
+
}
|
|
33
|
+
if (params.subject && params.text && params.to) {
|
|
34
|
+
try {
|
|
35
|
+
const message_echo = await this.tdclient.sendEmail({
|
|
36
|
+
subject: params.subject,
|
|
37
|
+
text: params.text,
|
|
38
|
+
to: params.to
|
|
39
|
+
});
|
|
40
|
+
// console.log("echo", message_echo)
|
|
41
|
+
if (completion) {
|
|
42
|
+
completion(null, message_echo);
|
|
43
|
+
}
|
|
44
|
+
// resolve(message_echo);
|
|
45
|
+
return message_echo;
|
|
46
|
+
}
|
|
47
|
+
catch(err) {
|
|
48
|
+
console.error("sendEmail error:", err);
|
|
49
|
+
if (completion) {
|
|
50
|
+
completion(err);
|
|
51
|
+
}
|
|
52
|
+
// reject(error);
|
|
53
|
+
// throw err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// console.log("sendEmail missing mandatory parameters (to|subject|text):");
|
|
58
|
+
const error = new Error("sendEmail missing mandatory parameters (to|subject|text)");
|
|
59
|
+
if (completion) {
|
|
60
|
+
completion(error);
|
|
61
|
+
}
|
|
62
|
+
// reject(err);
|
|
63
|
+
// throw error;
|
|
64
|
+
}
|
|
65
|
+
// });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
parseParams(directive_parameter) {
|
|
69
|
+
let subject = null;
|
|
70
|
+
let text = null;
|
|
71
|
+
let to = null
|
|
72
|
+
const params = ms(directive_parameter);
|
|
73
|
+
if (params.subject) {
|
|
74
|
+
subject = params.subject
|
|
75
|
+
}
|
|
76
|
+
if (params.text) {
|
|
77
|
+
text = params.text.replace(/\\n/g, "\n");
|
|
78
|
+
}
|
|
79
|
+
if (params.to) {
|
|
80
|
+
to = params.to;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
subject: subject,
|
|
84
|
+
to: to,
|
|
85
|
+
text: text
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = { DirSendEmail };
|