我目前正在使用python的对话流程库进行编程,但是当我获得尝试获得的参数列表时,它会返回一个我不知道如何阅读的Struct对象。 / p>
fields {
key: "apellido1"
value {
string_value: "Baena"
}
}
fields {
key: "apellido2"
value {
string_value: "P\303\251rez"
}
}
fields {
key: "nombre"
value {
string_value: "Rub\303\251n"
}
}
对话流程库的文档非常有限,没有示例。
我能猜到的最好的是,Struct来自以下路线
google.protobuf.struct_pb2
非常感谢您的帮助
答案 0 :(得分:0)
Github上有Dialogflow示例,以下是与Python相关的示例:weather sample使用WWO API和translation sample。总体而言,Dialogflow documentation讨论了如何从意图访问参数。以下天气示例的摘录:
import json
from flask import Flask, request, make_response, jsonify
app = Flask(__name__)
log = app.logger
@app.route('/', methods=['POST'])
def webhook():
req = request.get_json(silent=True, force=True)
try:
action = req.get('queryResult').get('action')
except AttributeError:
return 'json error'
if action == 'weather':
res = weather(req)
elif action == 'weather.activity':
res = weather_activity(req)
elif action == 'weather.condition':
res = weather_condition(req)
elif action == 'weather.outfit':
res = weather_outfit(req)
elif action == 'weather.temperature':
res = weather_temperature(req)
else:
log.error('Unexpected action.')
print('Action: ' + action)
print('Response: ' + res)
return make_response(jsonify({'fulfillmentText': res}))
def weather(req):
parameters = req['queryResult']['parameters']
print('Dialogflow Parameters:')
print(json.dumps(parameters, indent=4))
.....