moodleNotifer

utils.py
1 from .subjectdatabase import moodle
2 import os
3 os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "wbot99-yafn-04233a19031b.json"
4
5 import dialogflow_v2 as dialogflow
6 dialogflow_session_client = dialogflow.SessionsClient()
7 PROJECT_ID = "wbot99-yafn"
8 def detect_intent_from_text(text, session_id, language_code='en'):
9 session = dialogflow_session_client.session_path(PROJECT_ID, session_id)
10 text_input = dialogflow.types.TextInput(text=text, language_code=language_code)
11 query_input = dialogflow.types.QueryInput(text=text_input)
12 response = dialogflow_session_client.detect_intent(session=session, query_input=query_input)
13 return response.query_result
14
15 def fetch_reply(query,session_id):
16 response = detect_intent_from_text(query,session_id)
17 d = moodle()
18 courses = d.get_all_courses()
19 if response.intent.display_name == "assignment" :
20 sub = (dict(response.parameters))['assignment']
21 if sub in courses:
22 response = d.assignment_details(sub)
23 if response:
24 return response
25 else:
26 return "No assignment found"
27 else:
28 return "Subject not found !!"
29
30 elif(response.intent.display_name == "quiz"):
31 sub = (dict(response.parameters))['assignment']
32 if sub in courses:
33 response = d.quiz_details(sub)
34 if response:
35 return response
36 else:
37 return "No quiz found"
38 else:
39 return "Subject not found !!"
40 elif(response.intent.display_name == "getcontent"):
41 sub = (dict(response.parameters))['assignment']
42 if sub in courses:
43 response = d.course_contents(sub)
44 if response:
45 return response
46 else:
47 return "No contents found"
48 else:
49 return "Subject not found !!"
50 elif(response.intent.display_name == "announcement"):
51 sub = (dict(response.parameters))['assignment']
52 if sub in courses:
53 response = d.get_announcements(sub)
54 if response:
55 return response
56 else:
57 return "No contents found"
58 else:
59 return "Subject not found !!"
60 else :
61 return "Didn't get it? Try again"
62