-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.py
106 lines (80 loc) · 3.15 KB
/
chatbot.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import sentence_breakdown as sb
import new_features.wrapperfunctions as wf # has the functions calling apis. Change baseURL in backendrequests to connect to correct database
from basanti import *
from sentence_breakdown import *
from listen import *
import speak
from intent_classifier import *
import requests
break_query = sb.break_querry
from data import MESSAGES, SCHEDULES, PEOPLE
import new_features.telegram as telegram
def listen_state(created_by):
sentence = listenEnglish()
# speak.speakEnglish("Do you want to ask any questions")
# print('here1')
# print('here2')
print(sentence)
if not sentence:
return
intent, confidence = predict_sentiment(sentence)
print(intent)
if intent == 'Question':
question_bot(created_by, sentence)
elif intent == 'Action':
action_bot(created_by, sentence)
def action_bot(created_by, sentence):
broken_query = break_querry(sentence)
broken_query["CREATED_BY"] = created_by
action = broken_query["FUNCTION"][1]
if action == "ADD MESSAGE":
necessary_params = [
"WHO",
"WHAT",
]
broken_query = wf.checkNecessaryParams(broken_query, necessary_params)
wf.createMessage(MESSAGES, broken_query)
elif action == "SEND MESSAGE":
necessary_params = [
"WHO",
"WHAT",
]
broken_query = wf.checkNecessaryParams(broken_query, necessary_params)
# reconfirm action
reconfirmAction = (
"I am going to send a message to "
+ " ".join(broken_query["WHO"])
+ " about "
+ broken_query["WHAT"]
)
# speak.speakEnglish(reconfirmAction)
# conditions
telegram.sendTelegramMessage(broken_query["WHO"], broken_query["WHAT"])
elif action == "GET MESSAGE":
message_list = wf.checkCurrentUserMessages(MESSAGES, created_by)
for msg in message_list:
speak.speakEnglish(msg)
elif action == "ADD TO SCHEDULE":
necessary_params = ["WHO", "WHAT", "WHERE", "WHEN"] #add where to prompt if message has to be sent
broken_query = wf.checkNecessaryParams(broken_query, necessary_params)
msg = broken_query["WHAT"]+" "+broken_query["WHEN"].isoformat()+" "+broken_query["WHERE"]
print(msg)
telegram.sendTelegramMessage(broken_query["WHO"], broken_query["WHAT"]+" "+broken_query["WHEN"].isoformat()+" "+broken_query["WHERE"])
broken_query["createdBy"] = created_by
elif action == "GET SCHEDULE":
event_list = wf.checkCurrentUserEvents(SCHEDULES, created_by)
for event in event_list:
speak.speakEnglish(event)
else:
speak.speakEnglish("Sorry could you please repeat your querry")
pass
def question_bot(created_by, question:str):
print("hi")
chatURL = "https://positively-primary-stallion.ngrok-free.app/"
question = {"ques": question}
answer = requests.post(chatURL, params = question)
answer = answer.json()
print(answer["message"])
answer:str = answer["message"]
speak.speakEnglish(answer.replace('\n', " "))
# listen_state('aswin')