Как определить контекст сообщения, отправленного из Dialogflow в серверную часть Python?
Я использую следующие detect_intent
функция:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'private_key.json'
DIALOGFLOW_PROJECT_ID = 'kuku-lulu'
DIALOGFLOW_LANGUAGE_CODE = 'en'
SESSION_ID = 'me'
def detect_intent(text):
session_client = dialogflow.SessionsClient()
session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)
text_input = dialogflow.types.TextInput(text = text, language_code = DIALOGFLOW_LANGUAGE_CODE)
query_input = dialogflow.types.QueryInput(text = text_input)
try:
response = session_client.detect_intent(session = session, query_input = query_input)
except InvalidArgument:
raise
# print("Query text:", response.query_result.query_text)
# print("Detected intent:", response.query_result.intent.display_name)
# print("Detected intent confidence:", response.query_result.intent_detection_confidence)
# print("Fulfillment text:", response.query_result.fulfillment_text)
return {'sc': session_client, 'intent_name': response.query_result.intent.display_name}
Как я могу также определить контекст из Dialogflow?
1 ответ
Решение
В response.query_result.output_context
field должно быть массивом текущих активных контекстов, каждый из которых является объектом Context.
Вы можете прочитать эту информацию и отправить ее обратно в качестве входных контекстов для следующего запроса.