我正在使用 Python 中的检测意图 API 开发我的聊天机器人后端,一旦识别出意图,它就会转到我的 webhook 并获取适当的数据。
这是我的 detectorIntent 代码,用于从文本中获取数据
def detect_intent_texts(project_id, session_id, text, language_code='en-US'):
session_client = dialogflow.SessionsClient().from_service_account_file(
'my_service_account_json.json')
session = session_client.session_path(project_id, session_id)
print('Session path: {}\n'.format(session))
text_input = dialogflow.types.TextInput(text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(session=session, query_input=query_input)
data = MessageToDict(response.query_result)
print (json.dumps(data, indent=4))
response = parse_response(data)
return response
How can I sent access_token with it so that my webhook can identify which user is accessing the bot
P.S. 我的 webhook 正在此路径中寻找访问 token
req.get("originalDetectIntentRequest").get("payload").get("user").get("accessToken")
最佳答案
“有效负载”属性下的所有内容均取决于平台。例如,Assistant 平台将用户信息放在此处,这就是您的 webhook 当前正在尝试处理的内容。
如果您想将访问 token 放在同一位置,您可以将 query_params
命名参数与您要调用的文本一起传递给 detect_intent()
调用重新查询,以及任何其他可能相关的内容。 ( Reference ) 该参数可以是一个字典,如果是这样,则必须具有与 QueryParameters 相同的字段名称。对象。
关于dialogflow-es - 如何在 Dialogflow 中的检测意图文本 API 中发送 accessToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53045720/