DEV Community

Cover image for How To Build Alexa skill on Alexa Developer Console
Sahastra Kishore
Sahastra Kishore

Posted on • Edited on • Originally published at Medium

2 2

How To Build Alexa skill on Alexa Developer Console

Hello readers it’s my first blog on DEV so recently I published a skill on Amazon alexa and faced lots of difficulties while making the skill as I was a beginner I didn’t have any resource to make that so, I think that writing a blog on this will definitely help to others developer who are interested to build alexa skill on Amazon Alexa. As to create a skill you have to move on to https://developer.amazon.com/alexa/console/ask after Login you will see “Create Skill” Button like this.

Ya, click on the button and you will be next to this image.

Now write your skill name in skill name section and prefer the language in which your skill will invoke, choose “custom” then choose “provision your own” for hosting your skill’s backend resources now click onto “Create Skill” button to create the skill. After doing so, you will head over to Alexa developer console.

As you can see that in left bar menu there are some functions in interaction model section what does it means? So Intent function is used for function call means whenever you invoke your skill this function will calls in JS file so I added intent name as a GetNewFactIntent. Moving further you can see Interface it means that how your skills interface look like and Endpoint plays a role of communication with AWS. As I am using AWS for backend purpose. So this was the basic ideas about them. Now click on “Intent” and add Intent name there.

so, probably you have added that, now come onto next that is setting up of AWS backend.

yow will see this above image after login or signup of your account. What you have to do now is that just search Lambda in Find services box. Now you may have doubt of what this lambda is? So, AWS Lambda is Amazon’s serverless compute service. You can run your code on it without having to manage servers or even containers. After searching you will head over to this image.

As I made some of my skills from the lambda function so, Click on the “Create Function” button to create lambda function for your skill.

Now on next step you have to choose serverless app repository, as earlier fact skills were present in blueprint of lambda function so after choosing it you will see alexa-skill-kit-nodejs-factskill repository select it. And after that you will next to this image.

Now click on the “Deploy” button.

click on first link in Resources i.e alexaskillskitnodejsfactskill

Now you done with setup of lambda function. So, now click on to the Alexa Skill Kit above add trigger you will see that your skill is not verified with this trigger so delete this and Add trigger by enabling skill id in trigger configuration, Now you are thinking that where i will get my skill id so don't worry, Come onto alexa developer console again and move into Endpoint section you will see like this.

Now, copy skill id and paste it in Trigger configuration and on lambda dashboard you will see ARN id at top of the page copy that and paste it here in Default region box this make that your endpoint is linked with AWS lambda which we are using for backend resource after doing this click “Save Endpoint” button to save your endpoint.

Now click on lambda icon you will see Function code. which look like this

/* eslint-disable func-names */
/* eslint-disable no-console */
const Alexa = require('ask-sdk');
const GetNewFactHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest'
|| (request.type === 'IntentRequest'
&& request.intent.name === 'GetNewFactIntent');
},
handle(handlerInput) {
const factArr = data;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = GET_FACT_MESSAGE + randomFact;
return handlerInput.responseBuilder
.speak(speechOutput)
.withSimpleCard(SKILL_NAME, randomFact)
.getResponse();
},
};
const HelpHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak(HELP_MESSAGE)
.reprompt(HELP_REPROMPT)
.getResponse();
},
};
const ExitHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& (request.intent.name === 'AMAZON.CancelIntent'
|| request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak(STOP_MESSAGE)
.getResponse();
},
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`Error handled: ${error.message}`);
return handlerInput.responseBuilder
.speak('Sorry, an error occurred.')
.reprompt('Sorry, an error occurred.')
.getResponse();
},
};
const SKILL_NAME = 'cricket historical facts';
const GET_FACT_MESSAGE = 'Here\'s your fact: ';
const HELP_MESSAGE = 'You can say tell me a cricket historical facts, or, you can say exit... What can I help you with?';
const HELP_REPROMPT = 'What can I help you with?';
const STOP_MESSAGE = 'Goodbye!';
const data = [
'Cricket had started as a child’s game! This game’s origins can be traced to the 16th century. Cricket was first played in the sheep grazing lands of South East England. A stick and a ball of sheep’s wool were the first play equipment in cricket.',,
'In 1611, two men had played cricket instead of attending church on Sunday morning and were impeached for that!',
'The word cricket came from the Old English word “cryce” meaning crutch, and Middle Dutch work “rick” meaning stick.',
"In 1788, the first official laws of cricket were written, and terms like middle stump and lbw were coined. The Marylebone Cricket Club (MCC) was the first cricket team, and they played on the Lord’s field in England. In 1793, the first recorded game of cricket was played at the Lord’s ground.",,
"International games, or professional cricket matches, played by one country against another country; have been happening since 1844. Cricket was introduced to North America by the English colonies. The British India Company’s invasion over India had brought cricket to India and its neighboring countries.",
"In 1853, the cricket bat was made using a cane handle covered with layers of rubber, and the main bat was made of willow wood. The bat was bent like a hockey stick initially, but was made straight later, to adapt to the way the ball is pitched.",
"In 1909, the International Cricket Association (ICC) was formed, with its members being South Africa, England and Australia. Later India, West Indies and other countries were added. The first World Cup was played in 1975.",
"In 1971, the first limited overs or one day cricket match was played in Melbourne, Australia.",
'A cricket match can end in a draw even after being played for 5 straight days! There is no fixed shape of a cricket ground but the pitch is always 22 yards.',
];
const skillBuilder = Alexa.SkillBuilders.standard();
exports.handler = skillBuilder
.addRequestHandlers(
GetNewFactHandler,
HelpHandler,
ExitHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();
view raw index.js hosted with ❤ by GitHub

Now, edit this code with your skills requirement. And save this JS file after then come on alexa developer console and move on to test section, Now we done everything it's time to test your skill is it working or not.

If you are seeing this image then your skill passed test version Hurrey!!! Now it's time to publish it on production. As after this step its confidential So, that’s all. Hope you like this blog and may be helpful for your development of alexa skill, With this note THANK YOU.
If you have any query regarding this then comment below I’ll be happy to give you answers..

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay