diff --git a/backend/config/email.js b/backend/config/email.js
new file mode 100644
index 0000000..89e0ddc
--- /dev/null
+++ b/backend/config/email.js
@@ -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;
diff --git a/backend/helpers/email.js b/backend/helpers/email.js
index cf1bfb3..c70eadc 100644
--- a/backend/helpers/email.js
+++ b/backend/helpers/email.js
@@ -1,4 +1,5 @@
const nodemailer = require ('nodemailer');
+const emailConfig = require('../config/email');
module.exports = {
transformEmailFromAlexaResponse: function (email) {
@@ -43,23 +44,20 @@ module.exports = {
name +
'
Email : ' +
fromEmail +
- '
Your Saburly team';
+ '
Your Saburly team';
let transporter = nodemailer.createTransport ({
- host: 'smtp.mail.com',
- port: 587,
- secure: false,
- auth: {
- user: 'saburly@mail.com',
- pass: 'KeepSaburly',
- },
+ host: emailConfig.SMTP_HOST,
+ port: emailConfig.PORT,
+ secure: emailConfig.SECURE,
+ auth: emailConfig.AUTH,
});
var mailOptions = {
- from: 'saburly@mail.com',
+ from: emailConfig.FROM_EMAIL,
replyTo: fromEmail,
to: toEmail,
- subject: 'Message from Saburly service',
+ subject: emailConfig.SUBJECT,
text: messageBody,
html: messageBodyHTML,
};
diff --git a/backend/models/alexa.js b/backend/models/alexa.js
index 92f0fac..da282f3 100644
--- a/backend/models/alexa.js
+++ b/backend/models/alexa.js
@@ -88,12 +88,10 @@ module.exports = {
repromptSpeech
);
} else if (!intent.slots.Message.value) {
- intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse(intent.slots.Email.value);
- if (
- !emailHelper.isEmailValid (
- intent.slots.Email.value
- )
- ) {
+ intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse (
+ intent.slots.Email.value
+ );
+ if (!emailHelper.isEmailValid (intent.slots.Email.value)) {
//Email is not valid, ask again
const slotToElicit = 'Email';
const speechOutput =
@@ -103,7 +101,8 @@ module.exports = {
':elicitSlot',
slotToElicit,
speechOutput,
- repromptSpeech
+ repromptSpeech,
+ intent
);
} else {
//Email is valid
@@ -122,24 +121,27 @@ module.exports = {
console.log ('Name : ' + intent.slots.Name.value);
console.log ('Email : ' + intent.slots.Email.value);
console.log ('Message : ' + intent.slots.Message.value);
- emailHelper.sendEmal (
- intent.slots.Name.value,
- intent.slots.Email.value,
- intent.slots.Message.value,
- destinationEmail
- ).then(info=>{
- console.log(info);
- this.response.speak (
- 'Ok. Message sent. Someone will contact you ASAP'
- );
- this.emit (':responseReady');
- }).catch(error=>{
- console.log(error);
- this.response.speak (
- 'Sorry, there was a problem with sending message.'
- );
- this.emit (':responseReady');
- });
+ emailHelper
+ .sendEmal (
+ intent.slots.Name.value,
+ intent.slots.Email.value,
+ intent.slots.Message.value,
+ destinationEmail
+ )
+ .then (info => {
+ console.log (info);
+ this.response.speak (
+ 'Ok. Message sent. Someone will contact you ASAP'
+ );
+ this.emit (':responseReady');
+ })
+ .catch (error => {
+ console.log (error);
+ this.response.speak (
+ 'Sorry, there was a problem with sending message.'
+ );
+ this.emit (':responseReady');
+ });
}
};