V1 인증
기존의 인증 방식으로 Dialogflow Agent를 생성하면 설정 > General에 Access Key라고 표시가 되어 있는 곳이 있다.
Access Key를 request 할 때 Header에 포함하여 요청을 하면 인증이 끝난다.
V2 인증
{
"type": "",
"project_id": "",
"private_key_id": "",
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",..
}
Module Install
환경 설정
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="auth.json"
if __name__ == "__main__": # 이 코드가 있는 파일
# app.debug = True
app.run()
작성( python 이라.. 들여쓰기 표현이 .. 엉성합니다... )
import os
import dialogflow from google.api_core.exceptions
import InvalidArgument
DIALOGFLOW_PROJECT_ID = '[PROJECT_ID]'
DIALOGFLOW_LANGUAGE_CODE = '[LANGUAGE]
SESSION_ID = 'me'
text_to_be_analyzed = "Howdy" # 요청 문장
session_client = dialogflow.SessionsClient()
session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)
text_input = dialogflow.types.TextInput(text=text_to_be_analyzed, 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
nprint("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)
참고 : https://medium.com/swlh/working-with-dialogflow-using-python-client-cb2196d579a4