Skip to content

vivekdse/flask-ask

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http://flask-ask.readthedocs.io/en/latest/_images/logo-full.png


Bird Follow @_johnwheeler for updates

Program the Amazon Echo with Python

Flask-Ask is a Flask extension that makes building Alexa skills for the Amazon Echo easier and much more fun.

Get started with the Flask-Ask quickstart on Amazon's Developer Blog.

👊 Level Up with our Alexa Skills Kit Video Tutorial

Chat on Slack Use channel #Alexa

☤ The Basics

A Flask-Ask application looks like this:

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

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

@ask.intent('HelloIntent')
def hello(firstname):
    text = render_template('hello', firstname=firstname)
    return statement(text).simple_card('Hello', text)

if __name__ == '__main__':
    app.run()

In the code above:

  1. The Ask object is created by passing in the Flask application and a route to forward Alexa requests to.
  2. The intent decorator maps HelloIntent to a view function hello.
  3. The intent's firstname slot is implicitly mapped to hello's firstname parameter.
  4. Jinja templates are supported. Internally, templates are loaded from a YAML file (discussed further below).
  5. Lastly, a builder constructs a spoken response and displays a contextual card in the Alexa smartphone/tablet app.

Since Alexa responses are usually short phrases, it's convenient to put them in the same file. Flask-Ask has a Jinja template loader that loads multiple templates from a single YAML file. For example, here's a template that supports the minimal voice interface above.Templates are stored in a file called templates.yaml located in the application root:

hello: Hello, {{ firstname }}

For more information about how the Alexa Skills Kit works, see Understanding Custom Skills in the Alexa Skills Kit documentation.

Additionally, more code and template examples are in the samples directory.

☤ Documentation

These resources will get you up and running quickly:

Fantastic 3-part tutorial series by Harrison Kinsley

☤ Features

Flask-Ask handles the boilerplate, so you can focus on writing clean code. Flask-Ask:

  • Has decorators to map Alexa requests and intent slots to view functions
  • Helps construct ask and tell responses, reprompts and cards
  • Makes session management easy
  • Allows for the separation of code and speech through Jinja templates
  • Verifies Alexa request signatures

☤ Installation

To install Flask-Ask:

pip install flask-ask

☤ Deployment

You can deploy using any WSGI compliant framework (uWSGI, Gunicorn). If you haven't deployed a Flask app to production, checkout flask-live-starter.

To deploy on AWS Lambda, use Zappa.

Note: When deploying to AWS Lambda with Zappa, make sure you point the Alexa skill to the HTTPS API gateway that Zappa creates.

☤ Thank You

Thanks for checking this library out! I hope you find it useful.

Of course, there's always room for improvement. Feel free to open an issue so we can make Flask-Ask better.

Special thanks to @kennethreitz for his sense of style, and of course, @mitsuhiko for Flask

About

Alexa Skills Kit for Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%