Documentation for the Code


Central interface for the assistant app

class flask_assistant.Assistant(app=None, blueprint=None, route=None, project_id=None, dev_token=None, client_token=None)[source]

Central Interface for creating a Dialogflow webhook.

The Assistant object routes requests to action() decorated functions.

The assistant object maps requests received from an Dialogflow agent to Intent-specific view functions. The view_functions can be properly matched depending on required parameters and contexts. These requests originate from Google Actions and are sent to the Assistant object through Dialogflow’s infrastructure.

Keyword Arguments:
app {Flask object} – App instance - created with Flask(__name__) (default: {None}) blueprint {Flask Blueprint} – Flask Blueprint instance to initialize (Default: {None}) route {str} – entry point to which initial Alexa Requests are forwarded (default: {None}) project_id {str} – Google Cloud Project ID, required to manage contexts from flask-assistant dev_token {str} - Dialogflow dev access token used to register and retrieve agent resources client_token {str} - Dialogflow client access token required for querying agent

Local proxy referring to the OAuth token for linked accounts.

action(intent_name, is_fallback=False, mapping={}, convert={}, default={}, with_context=[], events=[], *args, **kw)[source]

Decorates an intent_name’s Action view function.

The wrapped function is called when a request with the given intent_name is recieved along with all required parameters.


Local Proxy refering to context objects contained within current session


LocalProxy refering to the app’s instance of the :class: ContextManager.

Interface for adding and accessing contexts and their parameters

init_blueprint(blueprint, path='templates.yaml')[source]

Initialize a Flask Blueprint, similar to init_app, but without the access to the application config.

Keyword Arguments:
blueprint {Flask Blueprint} – Flask Blueprint instance to initialize
(Default: {None})
path {str} – path to templates yaml file, relative to Blueprint
(Default: {‘templates.yaml’})

Local Proxy refering to the name of the intent contained in the Dialogflow request

prompt_for(next_param, intent_name)[source]

Decorates a function to prompt for an action’s required parameter.

The wrapped function is called if next_param was not recieved with the given intent’s request and is required for the fulfillment of the intent’s action.

next_param {str} – name of the parameter required for action function intent_name {str} – name of the intent the dependent action belongs to

Local Proxy refering to the request JSON recieved from Dialogflow


Invoke the Flask Assistant application from an AWS Lambda function handler. Use this method to service AWS Lambda requests from a custom Assistant Action. This method will invoke your Flask application providing a WSGI-compatible environment that wraps the original Dialogflow event provided to the AWS API Gateway handler. Returns the output generated by a Flask Assistant application, which should be used as the return value to the AWS Lambda handler function ready for API Gateway. From Flask Ask and adjusted for Flask Assistant Example usage:

from flask import Flask from flask_assistant import Assistant, ask

app = Flask(__name__) assist = Assistant(app, route=’/’) logging.getLogger(‘flask_assistant’).setLevel(logging.DEBUG)

def lambda_handler(event, _context):
return assist.run_aws_lambda(event)

@assist.action(‘greetings’) def greet_and_start():

speech = “Hey! Are you male or female?” return ask(speech)


Used for storing and accessing contexts and their parameters

class flask_assistant.manager.ContextManager(assist)[source]


class flask_assistant.response.ask(speech, display_text=None, is_ssml=False)[source]
class flask_assistant.response.tell(speech, display_text=None, is_ssml=False)[source]
class flask_assistant.response.event(event_name, **kwargs)[source]

Triggers an event to invoke it’s respective intent.

When an event is triggered, speech, displayText and services’ data will be ignored.

class flask_assistant.response._Response(speech, display_text=None, is_ssml=False)[source]

Base webhook response to be returned to Dialogflow

build_list(title=None, items=None)[source]

Presents the user with a vertical list of multiple items.

Allows the user to select a single item. Selection generates a user query containing the title of the list item

Note Returns a completely new object, and does not modify the existing response object Therefore, to add items, must be assigned to new variable or call the method directly after initializing list

example usage:

simple = ask(‘I speak this text’) mylist = simple.build_list(‘List Title’) mylist.add_item(‘Item1’, ‘key1’) mylist.add_item(‘Item2’, ‘key2’)

return mylist

title {str} – Title displayed at top of list card
_ListSelector – [_Response object exposing the add_item method]

Presents a chip similar to suggestion, but instead links to a url


Use suggestion chips to hint at responses to continue or pivot the conversation

Rich Messages