Dialogflow event trigger

Dialogflow를 사용하다가 특정 문장 입력 없이 reponse를 받는 방법이 없을까 고민하던 중 event trigger 기능이 있는 것을 알았다. Intent를 정의할 때 Event name을 지정할 수 있는데 이를 사용해서 response를 받는 것이 가능하다.

SESSION_ID = 'current-user-id'

session_client = dialogflow.SessionsClient()
session = session_client.session_path([GOOGLE 키 위치], SESSION_ID)

dialog_input = dialogflow.types.EventInput(name="Welcome", language_code=DIALOGFLOW_LANGUAGE_CODE)
query_input = dialogflow.types.QueryInput(event=dialog_input)

try:
    response = session_client.detect_intent(session=session, query_input=query_input)
except InvalidArgument:
    raise

res_text = response.query_result.fulfillment_text
print(res_text)

코드로 보면 대략 위와 같다. EventInput() function을 호출할 때 Event name을 지정하여 호출하는 방식으로 Event Trigger가 가능하다.

참고

Leave a Reply