Winston Churchill was one of the most motivational of all wartime leaders. His inspirational sayings still ring true in our lives as we try to overcome obstacles in our lives.
Years after this great orator first spoke his words of advice we can plug into them by asking Alexa to read a random word of wisdom. This is very handy when we need some additional motivation.
The app I created has been certified and published. It can be found at https://www.amazon.com/dp/b071xd5v53
Voice User InterfaceThis is a simple app with no menu tree. The user asks for a quote and Alexa provides them with one without fuss.
The first thing I did was head over to https://console.aws.amazon.com where I created a Lambda function:
/* eslint-disable func-names */
/* eslint quote-props: ["error", "consistent"]*/
'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = undefined;
const languageStrings = {
'en': {
translation: {
FACTS: [
'Success consists of going from failure to failure without loss of enthusiasm.',
'If you are going through hell, keep going.',
'You have enemies? Good. That means you have stood up for something, sometime in your life.',
'Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen.',
'Success is not final, failure is not fatal: it is the courage to continue that counts.',
'A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.',
'To improve is to change; to be perfect is to change often.',
'Never give in, never give in, never, never, never, never—in nothing, great or small, large or petty—never give in except to convictions of honor and good sense.',
'History will be kind to me for I intend to write it.',
'We make a living by what we get, but we make a life by what we give.',
],
SKILL_NAME: 'Winston Churchill Quotes',
GET_FACT_MESSAGE: "Here's your Churchill quote: ",
HELP_MESSAGE: 'You can say quote me, or, you can say exit... What can I help you with?',
HELP_REPROMPT: 'What can I help you with?',
STOP_MESSAGE: 'keep calm and carry on!',
},
},
'en-US': {
translation: {
FACTS: [
'Success consists of going from failure to failure without loss of enthusiasm.',
'If you are going through hell, keep going.',
'You have enemies? Good. That means you have stood up for something, sometime in your life.',
'Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen.',
'Success is not final, failure is not fatal: it is the courage to continue that counts.',
'A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.',
'To improve is to change; to be perfect is to change often.',
'Never give in, never give in, never, never, never, never—in nothing, great or small, large or petty—never give in except to convictions of honor and good sense.',
'History will be kind to me for I intend to write it.',
'We make a living by what we get, but we make a life by what we give.',
],
SKILL_NAME: 'American Winston Churchill Quotes',
},
},
'en-GB': {
translation: {
FACTS: [
'Success consists of going from failure to failure without loss of enthusiasm.',
'If you are going through hell, keep going.',
'You have enemies? Good. That means you have stood up for something, sometime in your life.',
'Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen.',
'Success is not final, failure is not fatal: it is the courage to continue that counts.',
'A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.',
'To improve is to change; to be perfect is to change often.',
'Never give in, never give in, never, never, never, never—in nothing, great or small, large or petty—never give in except to convictions of honor and good sense.',
'History will be kind to me for I intend to write it.',
'We make a living by what we get, but we make a life by what we give.',
],
SKILL_NAME: 'British Winston Churchill Quotes',
},
},
};
const handlers = {
'LaunchRequest': function () {
this.emit('GetFact');
},
'GetNewFactIntent': function () {
this.emit('GetFact');
},
'GetFact': function () {
const factArr = this.t('FACTS');
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
// Create speech output
const speechOutput = this.t('GET_FACT_MESSAGE') + randomFact;
this.emit(':tellWithCard', speechOutput, this.t('SKILL_NAME'), randomFact);
},
'AMAZON.HelpIntent': function () {
const speechOutput = this.t('HELP_MESSAGE');
const reprompt = this.t('HELP_MESSAGE');
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
'AMAZON.StopIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
};
exports.handler = function (event, context) {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
It is worth noting that it includes an overall EN locale as well as a US and a GB locale.
Creating the SkillI then headed to https://developer.amazon.com where I worked my way through the Alexa Skill creation wizard. Working through this wizard has been documented in many other projects so I think it might be most helpful if I focus on four of the gotchas that I came across when I was trying to create a skill. Hopefully this will help you avoid what seem to be quite common pitfalls. The five gotchas I came across are:
- Excessive String Length
- Incorrect AWS Location
- Short Skill Name
- Incorrect Example Phrases
- Publish all Locales
You can see each of these in turn below:
Excessive String LengthI originally wanted to create a function which would allow you to request chapters of the Bible to be read. I started with the only chapter of Jude which is as follows:
Jude, the servant of Jesus Christ, and brother of James, to them that are sanctified by God the Father, and preserved in Jesus Christ, and called: Mercy unto you, and peace, and love, be multiplied. Beloved, when I gave all diligence to write unto you of the common salvation, it was needful for me to write unto you, and exhort you that ye should earnestly contend for the faith which was once delivered unto the saints. For there are certain men crept in unawares, who were before of old ordained to this condemnation, ungodly men, turning the grace of our God into lasciviousness, and denying the only Lord God, and our Lord Jesus Christ. I will therefore put you in remembrance, though ye once knew this, how that the Lord, having saved the people out of the land of Egypt, afterward destroyed them that believed not. And the angels which kept not their first estate, but left their own habitation, he hath reserved in everlasting chains under darkness unto the judgment of the great day. Even as Sodom and Gomorrha, and the cities about them in like manner, giving themselves over to fornication, and going after strange flesh, are set forth for an example, suffering the vengeance of eternal fire. Likewise also these filthy dreamers defile the flesh, despise dominion, and speak evil of dignities. Yet Michael the archangel, when contending with the devil he disputed about the body of Moses, durst not bring against him a railing accusation, but said, The Lord rebuke thee. But these speak evil of those things which they know not: but what they know naturally, as brute beasts, in those things they corrupt themselves. Woe unto them! for they have gone in the way of Cain, and ran greedily after the error of Balaam for reward, and perished in the gainsaying of Core. These are spots in your feasts of charity, when they feast with you, feeding themselves without fear: clouds they are without water, carried about of winds; trees whose fruit withereth, without fruit, twice dead, plucked up by the roots; Raging waves of the sea, foaming out their own shame; wandering stars, to whom is reserved the blackness of darkness for ever. And Enoch also, the seventh from Adam, prophesied of these, saying, Behold, the Lord cometh with ten thousands of his saints, To execute judgment upon all, and to convince all that are ungodly among them of all their ungodly deeds which they have ungodly committed, and of all their hard speeches which ungodly sinners have spoken against him. These are murmurers, complainers, walking after their own lusts; and their mouth speaketh great swelling words, having men's persons in admiration because of advantage. But, beloved, remember ye the words which were spoken before of the apostles of our Lord Jesus Christ; How that they told you there should be mockers in the last time, who should walk after their own ungodly lusts. These be they who separate themselves, sensual, having not the Spirit. But ye, beloved, building up yourselves on your most holy faith, praying in the Holy Ghost, Keep yourselves in the love of God, looking for the mercy of our Lord Jesus Christ unto eternal life. And of some have compassion, making a difference: And others save with fear, pulling them out of the fire; hating even the garment spotted by the flesh. Now unto him that is able to keep you from falling, and to present you faultless before the presence of his glory with exceeding joy, To the only wise God our Saviour, be glory and majesty, dominion and power, both now and ever. Amen.
This was way too long to work as a string in the Lambda function so I needed to choose a different project. Hence the Winston Churchill quotes which are generally a lot shorter:
Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen.Incorrect AWS Location
All AWS locations are not the same. I found that the function had to be hosted at either US East (North Virginia) or EU (Ireland) in order to work as an Alexa Skill.
Short Skill NamePay close attention to the rules about what you can call your skill. I originally called mine Winston but that is not permitted because unless it is a brand name it must be at least two words such as Winston Churchill.
Incorrect Example PhrasesI regularly had my certification refused because my example phrases that I entered in the publishing information fell foul of many different rules. The example phrases that did the trick were as follows:
- Alexa, open winston churchill
- Alexa, ask winston churchill to say a quote
- Alexa ask winston churchill to quote me
I got knocked back for the first phrase not being a catchall open request and the phrases not being lower case apart from the word Alexa.
Similarly the invocation name must also be lower case.
Publish All LocalesI initially had my skill certified and published to the Amazon.com skill store and because I had publish "in all countries and regions where Amazon distributes skills" selected and that it includes a GB locale in the Lambda function I assumed it would also appear in the Amazon.co.uk skill store. This was an incorrect assumption. I should not have assumed this as it did not appear in the British store. I had to return to my skill in the Developer Console and add an English (U.K.) tab.
Comments
Please log in or sign up to comment.