Search code examples
alexa-skills-kitalexa-slot

How to expand custom slot types for Alexa Skill?


I want to ask for a flight number. Flight numbers are composed of a short code like EZY, AFR, DLH or CCA and a 3 to 5 digit flight number. Because I have these limited set of codes combined with a large set of potential numbers, I don't know how to define my slot type.

I thought about splitting it up in a custom slot type CODE and the integrated AMAZON.NUMBERS type. That way I run into problems in my model, because both of them are required to fulfil my intent and I would have to ask twice for the slots.

The option to just type out all the numbers seems like very bad practice. How would I concatenate slot types?

Thank you in advance.


Solution

  • Create a custom FLIGHT_NUMBER slot and give a wide variety of sample values.

    When you create a custom slot type, a key concept to understand is that this is training data for Alexa’s NLP (natural language processing). The values you provide are NOT a strict enum or array that limit what the user can say. This has two implications

    1) words and phrases not in your slot values will be passed to you,

    2) your code needs to perform any validation you require if what’s said is unknown.

    Abbreviations and numbers in Slot values

    When you are dealing with abbreviations like EZY or AFR or DLH and followed by numbers you have to give sample slot values like this. (try to give more variations)

    e. z. y. two four seven nine three four
    a. f. r. one two three four one two 
    d. l. h. two three eight zero eight zero
    

    And always validate your slot values in your backend.

    When testing it in Test Simulator use utterances like

    flight number a. f. r. one two three four one two

    You will get the value of slot as AFR238080. A sample request generated by Alexa would be like:

    "intent": {
                "name": "FlightNumberIntent",
                "confirmationStatus": "NONE",
                "slots": {
                    "flightNumber": {
                        "name": "flightNumber",
                        "value": "AFR238080",
    
    ...