What is Flask-Ask?
With the Amazon Echo, you ask "Alexa" to play songs, get the weather, and report scores. Those "skills", as they're called, have an open API for building conversational apps. Flask-Ask is an Alexa Skills Kit for Python that makes programming the Amazon Echo super easy.

Alexa Skills Kit / Slot Conversions with John Wheeler


Slot Conversions Details
  • 5m 40s
  • Appropriate for all
  • 06-21-2016
  • Updated 06-21-2016

Key Concepts: Using Built-ins, Custom Callables, Error Handling

When Flask-Ask maps intent slots to function parameters, it passes them as strings by default. This video shows how to use Flask-Ask's convert parameter to convert Alexa Skills Kit datatypes into Python's. First, we'll use Python's built-in int function, and then we'll build our own callable that shows how to handle slot conversion errors.

About the author

John Wheeler is the creator of Flask-Ask He's been developing for two decades in Java, JavaScript, Python, C# and Ruby. He lives in San Diego with his wife, daughter, and twin boys. Follow him on Twitter.

Subject: Alexa Skills Kit
Author: John Wheeler
intent_schema.json
{
    "intents": [{
        "intent": "AddIntent",
        "slots": [{
            "name": "first",
            "type": "AMAZON.NUMBER"
        }, {
            "name": "second",
            "type": "AMAZON.NUMBER"
        }]
    }, {
        "intent": "LikesCarrotsIntent",
        "slots": [{
            "name": "preference",
            "type": "LIST_OF_PREFERENCES"
        }]
    }]
}

sample_utterances.txt
AddIntent add {first} plus {second}
LikesCarrotsIntent I {preference} like carrots

demo.py
import logging
from datetime import date

from flask import Flask
from flask_ask import Ask, statement, question


app = Flask(__name__)
ask = Ask(app, "/")

log = logging.getLogger()
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)
logging.getLogger("flask_ask").setLevel(logging.DEBUG)


@ask.intent("AddIntent", convert={'first': int, 'second': int})
def add(first, second):
    thesum = first + second
    return statement("{} plus {} is {}".format(first, second, thesum))


def preference2bool(preference):
    if preference == 'do':
        return True
    elif preference == 'do not':
        return False
    else:
        raise ValueError("must be 'do' or 'do not'")


@ask.intent("LikesCarrotsIntent", convert={'preference': preference2bool})
def likes_carrots(preference):
    if preference:
        msg = "You say you like carrots"
    else:
        msg = "Carrots are not your favorite"
    return statement(msg)
Slot Conversions Discussion
Tutorial Playlist
Flask-Ask Quickstart
Project Bootstrap, Alexa Skills Kit, Flask-Ask, ngrok

4m 48s

Request Handling
Launch Requests, Intent Requests, Session Ended Requests

3m 17s

Building Responses
Statements, Questions, Cards, Reprompts

3m 50s

Intent Slots
Slots, Null Values, Default Values

3m 37s

Slot Conversions
Using Built-ins, Custom Callables, Error Handling

5m 40s

Conversion Helpers
Amazon Data Types, Python datetime Package

4m 27s

With more on the way!