Number Trivia Skill

Walkthrough Level: Beginner

Did you know that the human head has an average of 125,000 strands of hair?

Luckily, you can learn this and other fun facts from the kind people at Numbers API, who have collected a comprehensive list of number facts on just about any number!

Numbers Gif

In this tutorial, we create an Alexa skill, so you can learn number facts from your Alexa device. We'll go through the full script for creating a Number Trivia skill, similar to the ones referenced in our Alexa documentation, but showing off how to use our Catch-All Mode instead of defining your own Interaction Model.

Because we are using Catch-All Mode in this example, the script will look different from the Number Trivia examples in the Writing Guide, where individual intents have been defined in the Intent Schema.

This walkthrough assumes you will have read the Writing Guide first. If you have not, read that and come back here!

Follow Along!

Alexa, ask "Number Trivia"

If you recall from the Writing Guide, there are three types of incoming user requests. The first is a LaunchRequest when a user opens a skill by calling the invocation name, but does not provide an intent. For this type of request, you should write a welcome message or a short description of what to expect from the skill.

+ launchrequest
- Number Trivia tells you fun number trivia! Just tell me a number to get a number fact. 

Ask "Number Trivia" for a fact about the number 42

By default, we do not close the session -- this means that the Alexa device will continue listening for more incoming input (and will stay lit with a blue circle). This means that the user is not required to say "Alexa ask Number Trivia" anymore while the session is open. They can simply respond to the skill as if a conversation was occurring.

In the last request, we prompted the user for a number, which will hit the special # trigger, which parses out only the number in an incoming phrase.

This # is used as a query parameter for our Numbers API and we return the full text for Alexa to recite back to the user. After this fun tidbit of trivia, Alexa asks the user for more numbers, which would repeat this process once again.

+ [*] # [*] {weight=10}
$ GET<star>
- ${{__text}}. Is there another number you would like fun trivia about? ^alexaReprompt(Is there a number you would like fun trivia about?)

We've also included a special "^alexaReprompt()" shortcode in this response. If the user does not provide "another number [they] would like fun trivia about", Alexa reminds them to provide a follow-up number.

Ask "Number Trivia" for a random fact

This trigger-response pair makes a similar API call as the one in the previous section, except it is triggered by incoming user phrases that have the word "random" as opposed to the. With Catch-All Mode, Alexa can make use of existing Dexter trigger matching rules. In this case, we make use of the optional wildcard match.

+ [*] random [*]
- ${{__text}}. Say "random" again if you would like more random number facts! ^alexaReprompt(If you would like more random number facts, say "random" or say a number you would like a random fact about!)

Required Triggers

Before we can successfully submit our Alexa app for approval, there are a few requirements that every Alexa skill must have:

+ *
- Tell me a number to get a number fact. ^alexaReprompt(Is there a number you would like fun trivia about?)
- I need a number from you if you want a number fact! ^alexaReprompt(Is there a number you would like fun trivia about?)
+ [*] help [*]
- Number Trivia is an Alexa skill that tells you fun number trivia on any number! Which number would you like fun trivia about? ^alexaReprompt(Is there a number you would like fun trivia about?)
+ [*] (stop|cancel|nope|no|nah) [*]
- No more number trivia? Until next time! ^alexaEndSession(true)

First off, any good bot ought to have a wildcard trigger. This trigger is matched whenever a user says something that does not match the "#" or "random" triggers above.

We recommend including some follow-on text that prompts the user on how to veer back on track. In this scenario, we describe what the skill does and what the user should say to lead to the desired action.


Alexa skills must handle the incoming phrase for "help". Ideally, you'd want to tell the user what the skill does and add additional detail as needed to flesh out what the skill does.


Alexa skills must also understand "stop" and "cancel". The user ideally wants to stop using your Alexa skill, so this trigger is commonly paired with an "^alexaEndSession(true)" shortcode.

When Your User Goes Silent

When your user goes silent after a certain period of time, the Alexa skill will close by itself and return back a "SessionEndedRequest". You can also handle this type of request with a special trigger. The skill will respond with this message before shutting off (and the blue ring turns off).

+ sessionendedrequest
- Goodbye! ^alexaEndSession(true)

If the user wants to re-enter the skill after a SessionEndedRequest, they must then say your skill's invocation name again: "Alexa, open Number Trivia".

Let's Get Talking

The Alexa platform is up and ready in the "Platforms" page of your bot. To use the "CatchAll Mode?", make sure to toggle the mode on and copy the provided configuration into the text fields of the "Interaction Model" page of your Alexa app console. If not, define your own Interaction Model, as you see fit.

Consider how you might use bot brain variables or topics to create richer narratives for your Alexa skill. Assuming you use the same Alexa device, your skill can remember state just like any other bot for our platform. Whatever you do decide to build, let us know! We'd love to see how Alexa works for you.

More Resources