added various fields inside the dropdown
This commit is contained in:
@@ -36,41 +36,23 @@ public class StudentMenuHandler {
|
||||
public void sendMainMenu(String phoneNumber) {
|
||||
sessionService.setUserState(phoneNumber, UserState.MAIN_MENU);
|
||||
|
||||
List<Map<String, String>> rows = new ArrayList<>();
|
||||
rows.add(createRow("student_attendance", "Attendance", "Overall % and Subject-wise"));
|
||||
rows.add(createRow("student_timetable", "Timetable", "Today's classes and Weekly"));
|
||||
rows.add(createRow("student_internal_marks", "Internal marks", "CAT 1, CAT 2, Overall"));
|
||||
rows.add(createRow("student_semester_results", "Semester results", "Latest result and CGPA"));
|
||||
rows.add(createRow("student_fee_details", "Fee details & receipt", "Fee paid, Pending, Due date"));
|
||||
rows.add(createRow("student_academic_calendar", "Academic calendar", "Holidays and Important dates"));
|
||||
rows.add(createRow("student_exam_schedule", "Exam schedule", "Upcoming exams and Hall details"));
|
||||
rows.add(createRow("student_circulars", "Circulars & Notices", "Department circulars"));
|
||||
rows.add(createRow("student_raise_grievance", "Raise a grievance \u2B50", "Submit an issue ticket"));
|
||||
rows.add(createRow("student_contact_department", "Contact department", "Faculty mentor, HOD, etc."));
|
||||
String token = sessionService.getImsToken(phoneNumber);
|
||||
String studentName = "Student";
|
||||
if (token != null) {
|
||||
studentName = sessionService.getStudentName(phoneNumber, token);
|
||||
}
|
||||
|
||||
Map<String, Object> interactiveList = WhatsAppMessageBuilder.buildListMessage(
|
||||
"RIT Digital Assistant",
|
||||
"Welcome to the RITz Student Portal! Please select an option from the menu below.",
|
||||
"Welcome " + studentName + "! Please select an option from the menu below.",
|
||||
"Student Menu",
|
||||
rows
|
||||
getStudentMenuRows()
|
||||
);
|
||||
|
||||
messageService.sendInteractiveMessage(phoneNumber, interactiveList);
|
||||
|
||||
// Send a separate Logout button since the list is maxed out at 10 items
|
||||
List<Map<String, String>> logoutBtn = new ArrayList<>();
|
||||
Map<String, String> btn = new HashMap<>();
|
||||
btn.put("id", "student_logout");
|
||||
btn.put("title", "Logout");
|
||||
logoutBtn.add(btn);
|
||||
|
||||
Map<String, Object> logoutMessage = WhatsAppMessageBuilder.buildButtonMessage(
|
||||
"Need to switch accounts?",
|
||||
logoutBtn
|
||||
);
|
||||
messageService.sendInteractiveMessage(phoneNumber, logoutMessage);
|
||||
}
|
||||
|
||||
|
||||
public void handleMenuSelection(String phoneNumber, String selectedOptionId) {
|
||||
String token = sessionService.getImsToken(phoneNumber);
|
||||
if (token == null) {
|
||||
@@ -81,23 +63,67 @@ public class StudentMenuHandler {
|
||||
switch (selectedOptionId) {
|
||||
case "student_attendance":
|
||||
String rawAttendance = imsApiService.getAttendance(token);
|
||||
messageService.sendMessage(phoneNumber, MessageFormatter.formatAttendance(rawAttendance));
|
||||
String rawLeaves = imsApiService.getLeaves(token);
|
||||
sendResponseWithMenu(phoneNumber, MessageFormatter.formatAttendanceAndLeaves(rawAttendance, rawLeaves));
|
||||
break;
|
||||
|
||||
case "student_timetable":
|
||||
String rawTimetable = imsApiService.getTimetable(token);
|
||||
messageService.sendMessage(phoneNumber, MessageFormatter.formatTimetable(rawTimetable));
|
||||
sendResponseWithMenu(phoneNumber, MessageFormatter.formatTimetable(rawTimetable));
|
||||
break;
|
||||
|
||||
case "student_internal_marks":
|
||||
String rawCatMarks = imsApiService.getCatMarks(token);
|
||||
String rawAssignmentMarks = imsApiService.getAssignmentMarks(token);
|
||||
sendResponseWithMenu(phoneNumber, MessageFormatter.formatInternalMarks(rawCatMarks, rawAssignmentMarks));
|
||||
break;
|
||||
|
||||
case "student_semester_results":
|
||||
// Defaulting to semester 1 for now
|
||||
String rawResults = imsApiService.getResults(token, 1);
|
||||
messageService.sendMessage(phoneNumber, MessageFormatter.formatResults(rawResults, 1));
|
||||
sendSemesterSelection(phoneNumber, token);
|
||||
break;
|
||||
|
||||
case "student_fee_details":
|
||||
String rawFees = imsApiService.getFees(token);
|
||||
String rawExamFees = imsApiService.getExamFees(token);
|
||||
String bodyText = MessageFormatter.formatFeesAndExamFees(rawFees, rawExamFees);
|
||||
|
||||
List<Map<String, String>> receiptRows = MessageFormatter.extractReceiptRows(rawExamFees);
|
||||
|
||||
if (!receiptRows.isEmpty()) {
|
||||
// Max 10 items in a list. Limit to 10 if necessary.
|
||||
if (receiptRows.size() > 10) receiptRows = receiptRows.subList(0, 10);
|
||||
|
||||
sessionService.setUserState(phoneNumber, UserState.AWAITING_RECEIPT_SELECTION);
|
||||
|
||||
// Meta API interactive list body limit is 1024 characters
|
||||
if (bodyText.length() > 1024) bodyText = bodyText.substring(0, 1021) + "...";
|
||||
|
||||
Map<String, Object> listMessage = WhatsAppMessageBuilder.buildListMessage(
|
||||
"Receipts", bodyText, "Download Receipt", receiptRows
|
||||
);
|
||||
messageService.sendInteractiveMessage(phoneNumber, listMessage);
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, bodyText);
|
||||
}
|
||||
break;
|
||||
|
||||
case "student_raise_grievance":
|
||||
grievanceHandler.startGrievanceFlow(phoneNumber);
|
||||
break;
|
||||
|
||||
case "student_help_menu":
|
||||
sendHelpMenu(phoneNumber);
|
||||
break;
|
||||
|
||||
case "student_logout":
|
||||
sessionService.logoutUser(phoneNumber);
|
||||
messageService.sendMessage(phoneNumber, "You have been logged out successfully. Type 'Hi' to log in again.");
|
||||
break;
|
||||
|
||||
case "student_contact_department":
|
||||
messageService.sendMessage(phoneNumber, "Contact Department is currently under development. Please check back later!");
|
||||
sendMainMenu(phoneNumber);
|
||||
break;
|
||||
|
||||
default:
|
||||
messageService.sendMessage(phoneNumber, "You selected an option that is currently under development. Please check back later!");
|
||||
@@ -107,6 +133,134 @@ public class StudentMenuHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSemesterSelection(String phoneNumber, String token) {
|
||||
sessionService.setUserState(phoneNumber, UserState.AWAITING_SEMESTER_SELECTION);
|
||||
|
||||
List<Map<String, String>> rows = new ArrayList<>();
|
||||
for (int i = 1; i <= 8; i++) {
|
||||
rows.add(createRow("sem_" + i, "Semester " + i, ""));
|
||||
}
|
||||
|
||||
String rawDashboard = imsApiService.getDashboard(token);
|
||||
String bodyText = MessageFormatter.formatDashboardCgpa(rawDashboard);
|
||||
|
||||
Map<String, Object> interactiveList = WhatsAppMessageBuilder.buildListMessage(
|
||||
"Semester Results",
|
||||
bodyText,
|
||||
"Select Semester",
|
||||
rows
|
||||
);
|
||||
|
||||
messageService.sendInteractiveMessage(phoneNumber, interactiveList);
|
||||
}
|
||||
|
||||
public void handleSemesterSelection(String phoneNumber, String selectedOptionId) {
|
||||
String token = sessionService.getImsToken(phoneNumber);
|
||||
if (token == null) {
|
||||
messageService.sendMessage(phoneNumber, "Your session has expired. Please type 'Reset' to login again.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int semester = Integer.parseInt(selectedOptionId.replace("sem_", ""));
|
||||
byte[] pdfBytes = imsApiService.getResultsPdf(token, semester);
|
||||
|
||||
if (pdfBytes != null) {
|
||||
String fileName = "Semester_" + semester + "_Results.pdf";
|
||||
String mediaId = messageService.uploadMedia(pdfBytes, fileName, "application/pdf");
|
||||
|
||||
if (mediaId != null) {
|
||||
messageService.sendDocumentMessage(phoneNumber, mediaId, "Here are your Semester " + semester + " results!", fileName);
|
||||
// Send menu afterwards
|
||||
sendResponseWithMenu(phoneNumber, "Select an option from the menu below.");
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, "Failed to upload the results document to WhatsApp.");
|
||||
}
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, "Failed to download your results. They may not be published yet.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sendResponseWithMenu(phoneNumber, "Invalid semester selected.");
|
||||
}
|
||||
|
||||
sessionService.resetState(phoneNumber); // Reset state after fetching results
|
||||
}
|
||||
|
||||
public void handleReceiptSelection(String phoneNumber, String selectedOptionId) {
|
||||
String token = sessionService.getImsToken(phoneNumber);
|
||||
if (token == null) {
|
||||
messageService.sendMessage(phoneNumber, "Your session has expired. Please type 'Reset' to login again.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String historyId = selectedOptionId.replace("receipt_", "");
|
||||
byte[] pdfBytes = imsApiService.getExamFeeReceiptPdf(token, historyId);
|
||||
|
||||
if (pdfBytes != null) {
|
||||
String fileName = "Receipt_" + historyId + ".pdf";
|
||||
String mediaId = messageService.uploadMedia(pdfBytes, fileName, "application/pdf");
|
||||
|
||||
if (mediaId != null) {
|
||||
messageService.sendDocumentMessage(phoneNumber, mediaId, "Here is your Exam Fee Receipt!", fileName);
|
||||
sendResponseWithMenu(phoneNumber, "Select an option from the menu below.");
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, "Failed to upload the receipt document to WhatsApp.");
|
||||
}
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, "Failed to download your receipt. It may not be available.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sendResponseWithMenu(phoneNumber, "Invalid receipt selected.");
|
||||
}
|
||||
|
||||
sessionService.resetState(phoneNumber); // Reset state after fetching receipt
|
||||
}
|
||||
|
||||
private void sendResponseWithMenu(String phoneNumber, String bodyText) {
|
||||
// Meta API interactive list body limit is 1024 characters
|
||||
if (bodyText.length() > 1024) {
|
||||
bodyText = bodyText.substring(0, 1021) + "...";
|
||||
}
|
||||
|
||||
Map<String, Object> interactiveList = WhatsAppMessageBuilder.buildListMessage(
|
||||
null,
|
||||
bodyText,
|
||||
"Student Menu",
|
||||
getStudentMenuRows()
|
||||
);
|
||||
messageService.sendInteractiveMessage(phoneNumber, interactiveList);
|
||||
}
|
||||
|
||||
public void sendHelpMenu(String phoneNumber) {
|
||||
List<Map<String, String>> rows = new ArrayList<>();
|
||||
rows.add(createRow("student_contact_department", "Contact department", "Faculty mentor, HOD, etc."));
|
||||
rows.add(createRow("student_logout", "Logout", "Sign out of your account"));
|
||||
|
||||
Map<String, Object> interactiveList = WhatsAppMessageBuilder.buildListMessage(
|
||||
"Help & Settings",
|
||||
"Please select an option below:",
|
||||
"Help Menu",
|
||||
rows
|
||||
);
|
||||
messageService.sendInteractiveMessage(phoneNumber, interactiveList);
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getStudentMenuRows() {
|
||||
List<Map<String, String>> rows = new ArrayList<>();
|
||||
rows.add(createRow("student_attendance", "Attendance", "Overall % and Subject-wise"));
|
||||
rows.add(createRow("student_timetable", "Timetable", "Today's classes and Weekly"));
|
||||
rows.add(createRow("student_internal_marks", "Internal marks", "CAT 1, CAT 2, Overall"));
|
||||
rows.add(createRow("student_semester_results", "Semester results", "Latest result and CGPA"));
|
||||
rows.add(createRow("student_fee_details", "Fee details & receipt", "Fee paid, Pending, Due date"));
|
||||
rows.add(createRow("student_academic_calendar", "Academic calendar", "Holidays and Important dates"));
|
||||
rows.add(createRow("student_exam_schedule", "Exam schedule", "Upcoming exams and Hall details"));
|
||||
rows.add(createRow("student_circulars", "Circulars & Notices", "Department circulars"));
|
||||
rows.add(createRow("student_raise_grievance", "Raise a grievance \u2B50", "Submit an issue ticket"));
|
||||
rows.add(createRow("student_help_menu", "Help & Settings", "Logout, Contact dept, etc."));
|
||||
return rows;
|
||||
}
|
||||
|
||||
private Map<String, String> createRow(String id, String title, String description) {
|
||||
Map<String, String> row = new HashMap<>();
|
||||
row.put("id", id);
|
||||
|
||||
Reference in New Issue
Block a user