forked from japhari/whatsap_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
21 lines (16 loc) · 784 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import dialogflow_v2 as dialogflow
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "jokes-ejssqt-36270e8f377f.json"
dialogflow_session_client = dialogflow.SessionsClient()
PROJECT_ID = "jokes-ejssqt"
def detect_intent_from_text(text, session_id, language_code='en'):
session = dialogflow_session_client.session_path(PROJECT_ID, session_id)
text_input = dialogflow.types.TextInput(
text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = dialogflow_session_client.detect_intent(
session=session, query_input=query_input)
return response.query_result
def fetch_reply(query, session_id):
response = detect_intent_from_text(query, session_id)
return response.fulfillment_text