code fix and improvements
This commit is contained in:
14
backend/config/email.js
Normal file
14
backend/config/email.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
var config = {};
|
||||||
|
|
||||||
|
config.PORT = 587;
|
||||||
|
config.SMTP_HOST = 'smtp.mail.com';
|
||||||
|
config.SECURE = false;
|
||||||
|
config.AUTH = {
|
||||||
|
user: 'saburly@mail.com',
|
||||||
|
pass: 'KeepSaburly',
|
||||||
|
};
|
||||||
|
|
||||||
|
config.FROM_EMAIL = 'saburly@mail.com';
|
||||||
|
config.SUBJECT = 'Message from Saburly service';
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
const nodemailer = require ('nodemailer');
|
const nodemailer = require ('nodemailer');
|
||||||
|
const emailConfig = require('../config/email');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
transformEmailFromAlexaResponse: function (email) {
|
transformEmailFromAlexaResponse: function (email) {
|
||||||
@@ -43,23 +44,20 @@ module.exports = {
|
|||||||
name +
|
name +
|
||||||
'<br/><b>Email : </b>' +
|
'<br/><b>Email : </b>' +
|
||||||
fromEmail +
|
fromEmail +
|
||||||
'<br/><b>Your Saburly team</b>';
|
'<br/><br/><b>Your Saburly team</b>';
|
||||||
|
|
||||||
let transporter = nodemailer.createTransport ({
|
let transporter = nodemailer.createTransport ({
|
||||||
host: 'smtp.mail.com',
|
host: emailConfig.SMTP_HOST,
|
||||||
port: 587,
|
port: emailConfig.PORT,
|
||||||
secure: false,
|
secure: emailConfig.SECURE,
|
||||||
auth: {
|
auth: emailConfig.AUTH,
|
||||||
user: 'saburly@mail.com',
|
|
||||||
pass: 'KeepSaburly',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var mailOptions = {
|
var mailOptions = {
|
||||||
from: 'saburly@mail.com',
|
from: emailConfig.FROM_EMAIL,
|
||||||
replyTo: fromEmail,
|
replyTo: fromEmail,
|
||||||
to: toEmail,
|
to: toEmail,
|
||||||
subject: 'Message from Saburly service',
|
subject: emailConfig.SUBJECT,
|
||||||
text: messageBody,
|
text: messageBody,
|
||||||
html: messageBodyHTML,
|
html: messageBodyHTML,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,12 +88,10 @@ module.exports = {
|
|||||||
repromptSpeech
|
repromptSpeech
|
||||||
);
|
);
|
||||||
} else if (!intent.slots.Message.value) {
|
} else if (!intent.slots.Message.value) {
|
||||||
intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse(intent.slots.Email.value);
|
intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse (
|
||||||
if (
|
intent.slots.Email.value
|
||||||
!emailHelper.isEmailValid (
|
);
|
||||||
intent.slots.Email.value
|
if (!emailHelper.isEmailValid (intent.slots.Email.value)) {
|
||||||
)
|
|
||||||
) {
|
|
||||||
//Email is not valid, ask again
|
//Email is not valid, ask again
|
||||||
const slotToElicit = 'Email';
|
const slotToElicit = 'Email';
|
||||||
const speechOutput =
|
const speechOutput =
|
||||||
@@ -103,7 +101,8 @@ module.exports = {
|
|||||||
':elicitSlot',
|
':elicitSlot',
|
||||||
slotToElicit,
|
slotToElicit,
|
||||||
speechOutput,
|
speechOutput,
|
||||||
repromptSpeech
|
repromptSpeech,
|
||||||
|
intent
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//Email is valid
|
//Email is valid
|
||||||
@@ -122,24 +121,27 @@ module.exports = {
|
|||||||
console.log ('Name : ' + intent.slots.Name.value);
|
console.log ('Name : ' + intent.slots.Name.value);
|
||||||
console.log ('Email : ' + intent.slots.Email.value);
|
console.log ('Email : ' + intent.slots.Email.value);
|
||||||
console.log ('Message : ' + intent.slots.Message.value);
|
console.log ('Message : ' + intent.slots.Message.value);
|
||||||
emailHelper.sendEmal (
|
emailHelper
|
||||||
intent.slots.Name.value,
|
.sendEmal (
|
||||||
intent.slots.Email.value,
|
intent.slots.Name.value,
|
||||||
intent.slots.Message.value,
|
intent.slots.Email.value,
|
||||||
destinationEmail
|
intent.slots.Message.value,
|
||||||
).then(info=>{
|
destinationEmail
|
||||||
console.log(info);
|
)
|
||||||
this.response.speak (
|
.then (info => {
|
||||||
'Ok. Message sent. Someone will contact you ASAP'
|
console.log (info);
|
||||||
);
|
this.response.speak (
|
||||||
this.emit (':responseReady');
|
'Ok. Message sent. Someone will contact you ASAP'
|
||||||
}).catch(error=>{
|
);
|
||||||
console.log(error);
|
this.emit (':responseReady');
|
||||||
this.response.speak (
|
})
|
||||||
'Sorry, there was a problem with sending message.'
|
.catch (error => {
|
||||||
);
|
console.log (error);
|
||||||
this.emit (':responseReady');
|
this.response.speak (
|
||||||
});
|
'Sorry, there was a problem with sending message.'
|
||||||
|
);
|
||||||
|
this.emit (':responseReady');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user