-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogflow_bot.py
30 lines (25 loc) · 1.08 KB
/
dialogflow_bot.py
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
27
28
29
30
import os
import dialogflow
import send_email
from dotenv import load_dotenv
load_dotenv()
def send_message(message=None):
if message:
project_id = os.getenv('DIALOGFLOW_PROJECT_ID')
response = detect_intent_texts(project_id, "unique", message, 'en')
if response == "Brb":
EMAIL_ADDRESS = os.getenv('SENDER_EMAIL')
EMAIL_PASSWORD = os.getenv('SENDER_PASSWORD')
EMAIL_RECIEVER = os.getenv('RECIEVER_EMAIL')
send_email.send_email(EMAIL_ADDRESS, EMAIL_PASSWORD, EMAIL_RECIEVER)
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