Some times a small piece of advice can change your day. thus Alexa is gona help you make your day with some advice a day. to develop this application first sing in aws developer console.
in the alexa section click the alexa skill button.
now click the add a new skill
fill in the details, name and invocation name.
copy paste the intents provided below. click the add pause/resume intent button or else you can't go to the next step.
{
"intents": [
{
"intent": "GetNewAdviceIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "AMAZON.CancelIntent"
}
]
}
GetNewAdviceIntent an advice
GetNewAdviceIntent what is the advice for the day
GetNewAdviceIntent do you have any advice for me
GetNewAdviceIntent give me an advice
GetNewAdviceIntent tell me a advice
GetNewAdviceIntent give me a piece of advice
GetNewAdviceIntent any famous sayings suggested for me
GetNewAdviceIntent do you want to suggest any advice for me
GetNewAdviceIntent tell me something
GetNewAdviceIntent give me something
GetNewAdviceIntent what's there for me today
GetNewAdviceIntent tell me some information
GetNewAdviceIntent give me some information
copy paste the sample utterances as given above. you can give your own utterances. these are the keys for getting the advice.
download the fact skill template using the link below
https://s3.amazonaws.com/alexatutorials/Fact/tutorial_assets/FactSkillTemplate.zip
now open the new tab and open the aws console. enter the lambda section in the apps and service section. in the configure triggers section click the alexa skills kits by clicking the box.
Under “Configure Function,” enter the name and description for your skill
Select “index.handler” from the Handler dropdown
Select “Create a custom role” to open a new tab in the IAM Management Console, then:
Accept the defaults to create a new IAM Role called “lambda_basic_execution”
Select “Allow” in the lower right corner and you will be returned to your Lambda function
Keep the default Advanced settings. Select “Next” and review
keep rest as default and click create function. now the function is created.
now you got the ARN copy paste the ARN in the previous tab as given below.
open the code section and edit the app_id and other variable names for your requirement.
'use strict';
var Alexa = require('alexa-sdk');
var APP_ID = 'amzn1.ask.skill.dab4a8db-1c4c-4ab5-989f-0d2dbcff17cc'; //OPTIONAL: replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";
var SKILL_NAME = 'Advice for you';
/**
* Array containing space facts.
*/
var ADVICE = [
"What you're supposed to do when you don't like a thing is change it. If you can't change it, change the way you think about it. Don't complain.",
"Try to be a rainbow in someone's cloud.",
"Never miss a good chance to shut up.",
"If a man will begin with certainties, he shall end in doubts; but if he will be content to begin with doubts, he shall end in certainties.",
"Here's some advice. Stay alive.",
"We cannot change the cards we are dealt, just how we play the hand.",
"Never ruin an apology with an excuse.",
"Don't leave a piece of jewelry at his house so you can go back and get it later; he may be with his real girlfriend.",
"Don't ever take a fence down until you know why it was put up.",
"Write with the door closed, rewrite with the door open.",
"Don't take life too seriously. Punch it in the face when it needs a good hit. Laugh at it.",
"Push your boundaries, that's what they're there for.",
"Choose your battles, but don't choose very many.","Adapt what is useful, reject what is useless, and add what is specifically your own."
];
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function () {
this.emit('GetAdvice');
},
'GetNewAdviceIntent': function () {
this.emit('GetAdvice');
},
'GetAdvice': function () {
// Get a random space fact from the space facts list
var adviceIndex = Math.floor(Math.random() * ADVICE.length);
var randomAdvice = ADVICE[adviceIndex];
// Create speech output
var speechOutput = "Here's your fact: " + randomAdvice;
this.emit(':tellWithCard', speechOutput, SKILL_NAME, randomAdvice)
},
'AMAZON.HelpIntent': function () {
var speechOutput = "You can say tell me a space fact, or, you can say exit... What can I help you with?";
var reprompt = "What can I help you with?";
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', 'Goodbye!');
},
'AMAZON.PauseIntent': function () {
this.emit(':tell', 'paused');
},
'AMAZON.ResumeIntent': function () {
this.emit(':tell', 'app is resumed');
},
'AMAZON.StopIntent': function () {
this.emit(':tell', 'Goodbye!');
}
};
now its over. test your code as below in the developer console.
Comments
Please log in or sign up to comment.