improve dialog ; send email
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
var Alexa = require ('alexa-sdk');
|
||||
const config = require ('../config/config');
|
||||
var databaseHelper = require ('../helpers/database');
|
||||
var emailHelper = require ('../helpers/email');
|
||||
const constants = require ('../config/constants');
|
||||
|
||||
var handlers = {};
|
||||
var destinationEmail;
|
||||
|
||||
module.exports = {
|
||||
run: function (req, res) {
|
||||
@@ -30,6 +32,7 @@ module.exports = {
|
||||
.getSkill (config.SKILL_DB_ID)
|
||||
.then (activeSkill => {
|
||||
handlers = {};
|
||||
destinationEmail = activeSkill.contactEmail;
|
||||
|
||||
//Handler for launch request
|
||||
handlers = {
|
||||
@@ -58,36 +61,42 @@ module.exports = {
|
||||
let intent = this.event.request.intent;
|
||||
|
||||
console.log ('Dialog state : ' + this.event.request.dialogState);
|
||||
console.log ('Intent object :');
|
||||
console.log (intent);
|
||||
//STARTED, IN_PROGRESS
|
||||
|
||||
if (this.event.request.dialogState === 'STARTED') {
|
||||
//Should this be in constants ?
|
||||
if (!intent.slots.Name.value) {
|
||||
//Name not defined yet, ask user for name
|
||||
const slotToElicit = 'Name';
|
||||
const speechOutput = 'What is your name';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else if (!intent.slots.Email.value) {
|
||||
//Name not defined yet, ask user for email
|
||||
if (!intent.slots.Name.value) {
|
||||
//Name not defined yet, ask user for name
|
||||
const slotToElicit = 'Name';
|
||||
const speechOutput = 'What is your name';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else if (!intent.slots.Email.value) {
|
||||
//Name not defined yet, ask user for email
|
||||
const slotToElicit = 'Email';
|
||||
const speechOutput =
|
||||
'Ok ' + intent.slots.Name.value + '. What is your email';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else if (!intent.slots.Message.value) {
|
||||
if (
|
||||
!emailHelper.validateEmailFromAlexaResponse (
|
||||
intent.slots.Email.value
|
||||
)
|
||||
) {
|
||||
//Email is not valid, ask again
|
||||
const slotToElicit = 'Email';
|
||||
const speechOutput = 'What is your email';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else if (!intent.slots.Message.value) {
|
||||
const slotToElicit = 'Message';
|
||||
const speechOutput = 'What is your message';
|
||||
const speechOutput =
|
||||
'Sorry, that was not valid email. What is your email';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
@@ -96,13 +105,37 @@ module.exports = {
|
||||
repromptSpeech
|
||||
);
|
||||
} else {
|
||||
//all slots are filled
|
||||
console.log ('Name : ' + intent.slots.Name.value);
|
||||
console.log ('Email : ' + intent.slots.Email.value);
|
||||
console.log ('Message : ' + intents.slots.Message.value);
|
||||
this.response.speak ('Ok. Someone will contact you ASAP');
|
||||
this.emit (':responseReady');
|
||||
//Email is valid
|
||||
const slotToElicit = 'Message';
|
||||
const speechOutput = 'Great. What is your message';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
}
|
||||
} else {
|
||||
//all slots are filled
|
||||
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=>{
|
||||
this.response.speak (
|
||||
'Ok. Message sent. Someone will contact you ASAP'
|
||||
);
|
||||
}).catch(error=>{
|
||||
this.response.speak (
|
||||
'Sorry, there was a problem with sending message.'
|
||||
);
|
||||
});
|
||||
this.emit (':responseReady');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user