-
Notifications
You must be signed in to change notification settings - Fork 2
/
emailDialog.js
74 lines (60 loc) · 2.66 KB
/
emailDialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { ComponentDialog, TextPrompt, WaterfallDialog} = require('botbuilder-dialogs');
const emailId = 'email'
const nodemailer = require('nodemailer');
const jsonfile = require('jsonfile');
const config = require('./config');
const { log } = require('./logger');
//Class extends the CompenetDialog from botbuilder and will request an address and message and then email to an address
class EmailDialog extends ComponentDialog {
constructor(id){
super(id);
this.initialDialogId = emailId;
this.addDialog(new TextPrompt('textPrompt'));
this.addDialog(new WaterfallDialog (emailId, [
//Request an address
async function (step){
step.values.option = {};
return await step.prompt('textPrompt', 'What address would you like to email?')
},
//Request message
async function (step){
step.values.option.address = step.result;
return await step.prompt('textPrompt', `I have the address as ${step.result}. What message would you like to send?`)
},
//Send email and end dialog
async function(step){
step.values.option.text = step.result;
await step.context.sendActivity('Ok sending email');
let transporter = nodemailer.createTransport({
service: 'gmail',
secure: false,
port: 25,
auth: {
user: config.email.address,
pass: config.email.password
},
tls: {
rejectUnauthorized: false
}
});
//We need a dialog that builds this
let HelperOptions = {
from: `BotCaptain <${config.email.address}>`,
to: `${step.values.option.address}`,
subject: 'BotCaptain',
text: `${step.values.option.text}`
};
transporter.sendMail(HelperOptions, (error, info) => {
if (error) {
log.error(`[ERROR] ${error}.`);
return console.log(`[ERROR] ${error}`);
}
console.log("The message was sent!");
console.log(info);
});
return await step.endDialog(step.values.option);
}
]));
}
}
exports.EmailDialog=EmailDialog;