0

I use flask-assistant on python 3 with dilaogflow as a webhook. I looked at the official documentation and I don't find how to get the user message ("queryText" on dialogflow json request). I tried this with no success:

# -*- coding: utf-8 -*-
from flask import Flask
from flask_assistant import Assistant, ask, tell, context_manager, event

project_id='myproject_id'
app = Flask(__name__)
assist = Assistant(app, route='/', project_id = project_id)

@assist.action('Default Fallback Intent')
def manage_fallback(queryText):
    print('*'*40,queryText)
    speech='Running'
    return tell(speech)

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

The print of queryText always return None, but when I inspect on the ngrok web interface (http://127.0.0.1:4040) , I can see the request.

And I want to know how canI get the user message from flask-assistant?

mee
  • 688
  • 8
  • 18

1 Answers1

0

I also asked about this question on github and get the answer, so I will share for the others:

You can get the query text from the flask-assistant request object.

from flask_assistant import request
...
...
@assist.action('Default Fallback Intent')
def manage_fallback():
    user_query = request['queryResult']['queryText']
    speech = "You said " + user_query
    return tell(speech)

The reason the value of queryText expected by your manage_fallback function is None is because the parameter name must match the entity type expected by the intent.

Parameters are used to receive parsed entities for an intent, not the full user query.

mee
  • 688
  • 8
  • 18