After I finished building Gaffney Facts, I was eager to create another skill. I wanted to build a more complicated skill, but I wasn’t ready to start from scratch. As part of the A Cloud Guru Alexa course I built a trivia skill, so I thought that might be a good second skill.

Building the Lambda Function

I decided to build a trivia skill focused on South Carolina, my home state. I created a Word document with around 30 questions about my home state. These questions focused on several topics like the history of the state and random facts like the state bird or beverage. Once I finished my Word document, I saved it and started building my skill.

I visited the Lambda section of the AWS console to begin working on my new skill. I clicked “Create function”, and clicked “Browse Serverless app repository”. On the first page of the app repository there is a function called alexa-skills-kit-nodejs-triviaskill. This Lambda function is written in node.js and is a template for building trivia skills. I clicked on the triviaskill function and on the next screen I clicked “deploy”.

The alexa-skills-kit-nodejs-triviaskill is already set-up for a trivia game called “Reindeer Trivia”. Just like the facts skill, the code is very easy to read. The Lambda function uses two different scripts to run, index.js and questions.js. Index.js is easy to customize. The script is written in three different languages, American English, UK English, and German. I did not want a German version of my skill, so I started by deleting the German code. In the index.js document there are German responses to common game situations on lines 271 through 296. I deleted those lines. Next, I went over to the questions.js document. The section of code called QUESTIONS_DE_DE contains the German question bank. I deleted the questions from line 506 to line 751. This eliminated the German questions from the function.

Customizing the code is simple. Index.js is the backbone of the skill, and it mostly stays the same. Index.js keeps score, gives help to users, and pulls trivia questions from questions.js. I did have to change the GAME_NAME within index.js. I found every instance of GAME_NAME in the code and changed it from Reindeer Trivia to South Carolina Trivia. Now, I was ready to start editing questions.js.

Questions.js contains a pool of questions for your skill to pull from. I scanned through the code until I understood exactly how the questions worked. One important thing to notice is that the questions are repeated twice. Once in American English and once in Great Britain English. If I wanted to support other languages, I’d have to repeat the questions in those languages as well.

    {
      'What Makes Santa\'s Reindeer Fly?': [
        'Magical Reindeer Dust',
        'Fusion',
        'Amanita muscaria',
        'Elves',
      ],
    },

Above is an example of a question from the trivia skill. To customize the questions, you simply replace the question and the answers. The correct answer is always the first one. If you already have the questions ready, then you can build a trivia skill in just a few minutes.

I spent a considerable amount of time researching questions for my trivia skill. I started with my basic knowledge of the state, but to make my game more challenging I did some research. I looked up the state bird, drink, vegetable, and other official representations of the state. I feel that people that play my game will walk away with some knowledge of the state.

I plugged my questions into the EN_GB section of the questions.js script. Then, I very carefully copied and pasted the code into the EN_US section. I pasted the code and double checked to make sure the brackets and parentheses matched up. I used Visual Studio Code to help make sure the node.js has proper syntax. Visual Studio Code connects the beginning and end of each set of brackets. I also added Bracket Pair Colorizer to Visual Studio Code. This tool gives each pair of brackets a color, so you can easily match the brackets, ensuring that your syntax was perfect. Once I was confident that my syntax was correct, I copied and pasted the code back into questions.js in the Lambda console.

Building the Alexa Front End

At this point I switched to the Alexa Developer Console. I clicked “Create Skill” and named the skill “South Carolina Trivia”. I chose “Quiz Game Skill” as my template. This template comes with an AnswerIntent and a QuizIntent. The AnswerIntent uses 5 different slot types, but all the slot types are related to a fifty states quiz. I deleted all 5 slots types and created a new slot with the type AMAZON.NUMBER. Additionally, there was a QuizIntent, which allows the user to start a new quiz. In addition to these built-in intents, I added a DontKnowIntent. This intent allowed users to move on to the next question if they don’t know the answer.

After I finished building the intents, I clicked on endpoint on the left side menu. I flipped back over to the AWS Lambda Console and copied the ARN from my Lambda function and pasted the ARN into the Default Region field. Next, I copied the Skill ID and clicked back to the Lambda function. I added Alexa Skills Kit as a trigger for the Lambda function, then I added the Skill ID to the Skill ID verification slot. Now the lambda function is connected to the skill.

Publishing the Skill

To finish building the skill I saved the Lambda function and then went back to the Alexa developer console and clicked Save Model and then Build Model. Once the Build was complete, I went into the testing area of the console. I double checked to make sure the skill worked as intended. I was especially looking to make sure the skill delivered random questions and that the answers worked properly. Once I was confident that everything worked properly I was ready to publish the skill.

I’d already published my “Gaffney Facts” skill, so I was very familiar with the Distribution step. I gave the skill a name, a description, a small photo, and a large photo. I then proceeded to the Certification step. I ran the Validation test and the Functional test, and the skill easily passed both tests. I then submitted the skill and waited. Amazon got back to me a couple days later, letting me know that my skill was published and available to the public.

Building a second Alexa skill was a wonderful learning experience. I learned how to quickly edit Amazon’s provided code to create something new and unique. Additionally, I became more familiar with the whole process. I felt that I was now comfortable enough to start making my own skills from scratch. I highly recommend that anyone looking to get into Alexa skill development start by customizing the basic skills. You can create something new and exciting in a few hours and get a great grip on how the Alexa platform works. Voice Assistants are a super exciting part of the Cloud world, so dive in and build your first skill today.