Terence Eden’s Blog<p><strong>Alexa Skills - get custom slot names using Flask-Ask</strong></p><p><a href="https://shkspr.mobi/blog/2019/06/alexa-skills-get-custom-slot-names-using-flask-ask/" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">shkspr.mobi/blog/2019/06/alexa</span><span class="invisible">-skills-get-custom-slot-names-using-flask-ask/</span></a></p><p></p><p>Amazon encourages developers to use <a href="https://github.com/johnwheeler/flask-ask" rel="nofollow noopener" target="_blank">Flask-Ask</a> - the handy Python library for working with Alexa. Sadly, <a href="https://twitter.com/_johnwheeler/status/1131728459028238337" rel="nofollow noopener" target="_blank">the project has been abandoned</a>. They no longer take pull requests, you can't raise bugs against it, and the documentation is incomplete.</p><p>So this is how I solved an annoying problem - how to get the name of a custom slot.</p><p>Here's the code, with a fuller explanation afterwards.</p><pre><code>from flask import Flask, render_template, requestfrom flask_ask import Ask, statement, question, sessionapp = 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']</code></pre><p>Yeuch! What's going on?</p><p>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.</p><p>In my case, I want to send my API the ID Code of a hospital.</p><p></p><p>If the user says "John Radcliff" or "Oxford" or "John Radcliff Hospital" - then my API should receive the ID <code>RTH08</code>. It can then use that ID in a separate API call.</p><p>Here's the JSON that Alexa sends our API (I've truncated it for ease of reading).</p><pre><code>{ "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" } } ] } ] }, } } } }}</code></pre><p>A bit verbose, but easy enough to parse.</p><p>I've <a href="https://shkspr.mobi/blog/2017/05/amazon-alexa-and-solar-panels/" rel="nofollow noopener" target="_blank">moaned before about Alexa skill development</a> - 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.</p><p>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.</p><p>Amazon have gone down the classic route of <a href="https://web.archive.org/web/20190922125800/https://developer.amazon.com/de/en-gb/alexa-skills-kit/alexa-developer-skill-promotion" rel="nofollow noopener" target="_blank">paying developers to build for their platform</a>. But I don't think that's enough.</p><p><a href="https://developer.amazon.com/de/en-gb/alexa-skills-kit/alexa-developer-skill-promotion" rel="nofollow noopener" target="_blank"></a></p><p>The Alexa team need to work on the developer experience. A GUI like NODE-RED could be used to help build skills <em>in one place</em>. Why is it so complicated to deploy and test skills? Where are the official libraries which "just work"?</p><p>I honestly believe that one of the things holding back voice assistants from their full potential is the poor developer experience.</p><p></p><p><a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://shkspr.mobi/blog/tag/alexa/" target="_blank">#alexa</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://shkspr.mobi/blog/tag/developer/" target="_blank">#developer</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://shkspr.mobi/blog/tag/hackday/" target="_blank">#hackday</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://shkspr.mobi/blog/tag/nhshd/" target="_blank">#nhshd</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://shkspr.mobi/blog/tag/python/" target="_blank">#python</a></p>