如何在 Dialogflow 的 Detect Intent Text API 中发送 accessToken
How to send accessToken in Detect Intent Text API in Dialogflow
我正在 Python 中使用检测意图 API 开发我的聊天机器人后端,一旦识别出意图,它就会转到我的网络钩子并获取适当的数据。
这是我从文本中获取数据的 detectIntent 代码
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 正在此路径中寻找访问令牌
req.get("originalDetectIntentRequest").get("payload").get("user").get("accessToken")
"payload" 属性下的所有内容都依赖于平台。例如,助手平台将用户信息放在此处,这是您的 webhook 当前正在尝试处理的内容。
如果您想将访问令牌放在同一个地方,您可以将 query_params
命名参数连同您要查询的文本以及其他任何内容一起传递给对 detect_intent()
的调用这可能是相关的。 (Reference) That parameter can be a dict and, if so, has to have the same field names as a QueryParameters 对象。
我正在 Python 中使用检测意图 API 开发我的聊天机器人后端,一旦识别出意图,它就会转到我的网络钩子并获取适当的数据。
这是我从文本中获取数据的 detectIntent 代码
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 正在此路径中寻找访问令牌
req.get("originalDetectIntentRequest").get("payload").get("user").get("accessToken")
"payload" 属性下的所有内容都依赖于平台。例如,助手平台将用户信息放在此处,这是您的 webhook 当前正在尝试处理的内容。
如果您想将访问令牌放在同一个地方,您可以将 query_params
命名参数连同您要查询的文本以及其他任何内容一起传递给对 detect_intent()
的调用这可能是相关的。 (Reference) That parameter can be a dict and, if so, has to have the same field names as a QueryParameters 对象。