Welcome to Flask-Assistant!¶
A flask extension serving as an Dialogflow SDK to provide an easy way to create virtual assistants which may be integrated with platforms such as Google Actions (Google Home).
Flask-Assistant allows you to focus on building the core business logic of conversational user interfaces while utilizing Dialogflow’s Natural Language Processing to interact with users.
Features¶
- Maping of user-triggered Intents to action view functions
- Context support for crafting dialogue dependent on the user’s requests
- Define prompts for missing parameters when they are not present in the users request or past active contexs
- A convenient syntax resembling Flask’s decoratored routing
- Internal Dialogflow schema generation and registration
A Minimal Assistant¶
from flask import Flask
from flask_assistant import Assistant, tell
# to see the full request and response objects
# set logging level to DEBUG
import logging
logging.getLogger('flask_assistant').setLevel(logging.DEBUG)
app = Flask(__name__)
assist = Assistant(app, project_id='GOOGLE_CLOUD_PROJECT_ID')
@assist.action('Demo')
def hello_world():
speech = 'Microphone check 1, 2 what is this?'
return tell(speech)
if __name__ == '__main__':
app.run(debug=True)
As you can see, structure of an Assistant app resembles the structure of a regular Flask app.
Explanation¶
- Initialized an
Assistant
object with a Flask app and the route to your webhook URL. - Used the
action
decorator to map the greetings intent to the proper action function. - The action decorator accepts the name of an intent as a parameter
- The decorated function serves as the action view function, called when an Dialogflow request sent on behalf of the send-message intent is received
- Used the
- The action function returns an
ask
response containing text/speech which prompts the user for the next intent.
Check out the Quick Start to see how to quickly build an assistant