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, client_id=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 client_id {Str} – Actions on Google client ID used for account linking 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

add_media(url, name, description=None, icon_url=None, icon_alt=None)[source]

Adds a Media Card Response

Media responses let your Actions play audio content with a playback duration longer than the 240-second limit of SSML.

Can be included with ask and tell responses. If added to an ask response, suggestion chips

url {str} – Required. Url where the media is stored name {str} – Name of media card.
description {str} – A description of the item (default: {None}) icon_url {str} – Url of icon image icon_alt {str} – Accessibility text for icon image

example usage:

resp = ask(“Check out this tune”) resp = resp.add_media(url, “Jazzy Tune”) return resp_with_media.suggest(“Next Song”, “Done”)
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 items {items} – List of list items
_ListSelector – [_Response object exposing the add_item method]
card(text, title, img_url=None, img_alt=None, subtitle=None, link=None, link_title=None, buttons=None, btn_icon=None, btn_icon_color=None)[source]

Presents the user with a card response

Cards may contain a title, body text, subtitle, an optional image, and a external link in the form of a button

The only information required for a card are the text and title.

example usage:

resp = ask(“Here’s an example of a card”) resp.card(

text=’The text to display’, title=’Card Title’, img_url=’’ link=’’, link_title=”Google it”


return resp

text {str} – The boody text of the card title {str} – The card title shown in header
Keyword Arguments:
img_url {str} – URL of the image to represent the item (default: {None}) img_alt {str} – Accessibility text for the image subtitle {str} – The subtitle displaye dbelow the title link {str} – The https external URL to link to link_title {str} – The text of the link button btn_icon {str} – Icon from Material Icon library (DF_MESSENGER only) (default: chevron_right) btn_icon_color {str} – Icon color hexcode (DF_MESSENGER only) (default: #FF9800)

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