-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdialogflow_bot.py
More file actions
26 lines (20 loc) · 851 Bytes
/
dialogflow_bot.py
File metadata and controls
26 lines (20 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import dialogflow
from dotenv import load_dotenv
load_dotenv()
project_id="mychatbot-307913"
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]=os.getenv('DIAGFLOW_PATH')
def send_message(message=None):
if message:
response = detect_intent_texts(project_id, "unique", message, 'en')
return response
def detect_intent_texts(project_id, session_id, text, language_code):
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
if text:
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)
return response.query_result.fulfillment_text