Alexa Skills - get custom slot names using Flask-Ask


Amazon encourages developers to use Flask-Ask - the handy Python library for working with Alexa. Sadly, the project has been abandoned. They no longer take pull requests, you can't raise bugs against it, and the documentation is incomplete.

So this is how I solved an annoying problem - how to get the name of a custom slot.

Here's the code, with a fuller explanation afterwards.

Python 3 Python 3from flask import Flask, render_template, request
from flask_ask import Ask, statement, question, session
app = Flask(__name__)
ask = Ask(app, '/')

@ask.intent("YourIntentName")
def your_intent_name():
    content = request.get_json()
    name = content['request']['intent']['slots']['YOUR_SLOT_NAME']['resolutions']['resolutionsPerAuthority'][0]['values'][0]['value']['name']

Yeuch! What's going on?

Alexa lets us define custom slot names - these can be associated with any spoken text. For example, I might want the slot name "car" to be sent whether the user says "car" or "automobile" or "vehicle" or any other synonym.

In my case, I want to send my API the ID Code of a hospital.

Alexa Skills Page.

If the user says "John Radcliff" or "Oxford" or "John Radcliff Hospital" - then my API should receive the ID RTH08. It can then use that ID in a separate API call.

Here's the JSON that Alexa sends our API (I've truncated it for ease of reading).

JSON JSON{
    "request": {
        "type": "IntentRequest",
        "requestId": "amzn1.echo-api.request.1234",
        "timestamp": "2019-06-17T06:54:52Z",
        "locale": "en-GB",
        "intent": {
            "name": "CarPark",
            "confirmationStatus": "NONE",
            "slots": {
                "hospital": {
                    "name": "hospital",
                    "value": "John radcliff",
                    "resolutions": {
                        "resolutionsPerAuthority": [
                            {
                                "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.1234.hospitals",
                                "status": {
                                    "code": "ER_SUCCESS_MATCH"
                                },
                                "values": [
                                    {
                                        "value": {
                                            "name": "RTH08",
                                            "id": "abc123"
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                }
            }
        }
    }
}

A bit verbose, but easy enough to parse.

I've moaned before about Alexa skill development - but it is getting worse. As you can see from the above screenshot, the development website's contrast isn't great - which makes building a skill physically painful.

Add to that the outdated tutorials, the weird terminology, the multiple sites to use, broken links, and abandoned libraries... It's hard to feel enthusiastic about building more skills.

Amazon have gone down the classic route of paying developers to build for their platform. But I don't think that's enough.

 Publish your very first, new Alexa skill during the promotion period and earn an Amazon Smart Plug. Publish three new Alexa skills during the promotion period, where one of them is used by at least 150 unique users within the first 30 days after being approved by Amazon for publication, and earn a €50 (GBP for UK) Amazon Online Store voucher. Add the Alexa Presentation Language to one of your skills (newly published or updated) during the promotion period and reach at least 150 unique users per month for one month, and you will earn an Amazon Echo Show. (Only for Developers residing in Germany, Austria, United Kingdom, Ireland): Add in-skill purchasing to your skill (newly published or updated) during the promotion period and reach at least 150 unique users per month and over €10/£10 in revenue per month for one month, and you will earn a voucher for the AWS Certified Alexa Skill Builder exam fee.

The Alexa team need to work on the developer experience. A GUI like NODE-RED could be used to help build skills in one place. Why is it so complicated to deploy and test skills? Where are the official libraries which "just work"?

I honestly believe that one of the things holding back voice assistants from their full potential is the poor developer experience.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

One thought on “Alexa Skills - get custom slot names using Flask-Ask”

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">