grievances redressal system

This commit is contained in:
RIT Services
2026-08-21 06:42:25 +00:00
parent d3be597489
commit 71ddfe0f7b
3 changed files with 92 additions and 77 deletions

View File

@@ -30,19 +30,14 @@ public class GrievanceHandler {
}
public void startGrievanceFlow(String phoneNumber) {
sessionService.setUserState(phoneNumber, UserState.AWAITING_GRIEVANCE_CATEGORY);
sessionService.resetState(phoneNumber);
List<Map<String, String>> buttons = new ArrayList<>();
buttons.add(createButton("grievance_academic", "Academic"));
buttons.add(createButton("grievance_hostel", "Hostel"));
buttons.add(createButton("grievance_other", "Other"));
String message = "📢 *RIT Grievance Portal Notice*\n\n" +
"Please note that grievances and complaints must be officially registered and tracked using our dedicated mobile application, *Complixr*.\n\n" +
"Kindly download the app from the Google Play Store to submit your ticket:\n" +
"🔗 https://play.google.com/store/apps/details?id=com.ritchennai.complixr&pcampaignid=web_share";
Map<String, Object> buttonMessage = WhatsAppMessageBuilder.buildButtonMessage(
"Please select the category for your grievance:",
buttons
);
messageService.sendInteractiveMessage(phoneNumber, buttonMessage);
messageService.sendMessage(phoneNumber, message);
studentMenuHandler.sendStudentMenuDirectly(phoneNumber);
}

View File

@@ -68,30 +68,7 @@ public class StudentMenuHandler {
break;
case "student_timetable":
String rawTimetable = imsApiService.getTimetable(token);
String todaySchedule = MessageFormatter.formatTimetable(rawTimetable);
// Truncate to stay safely within WhatsApp 1024 character limit for button bodies
if (todaySchedule.length() > 1020) {
todaySchedule = todaySchedule.substring(0, 1017) + "...";
}
List<Map<String, String>> buttons = new ArrayList<>();
Map<String, String> weeklyBtn = new HashMap<>();
weeklyBtn.put("id", "student_weekly_timetable");
weeklyBtn.put("title", "Weekly Timetable");
buttons.add(weeklyBtn);
Map<String, String> menuBtn = new HashMap<>();
menuBtn.put("id", "student_show_menu");
menuBtn.put("title", "Student Menu");
buttons.add(menuBtn);
System.out.println("FINAL TODAY TIMETABLE MESSAGE:\n" + todaySchedule);
Map<String, Object> buttonMessage = WhatsAppMessageBuilder.buildButtonMessage(todaySchedule, buttons);
messageService.sendInteractiveMessage(phoneNumber, buttonMessage);
sendStudentMenuDirectly(phoneNumber);
sendTimetableMenu(phoneNumber, token);
break;
case "student_internal_marks":
@@ -113,35 +90,14 @@ public class StudentMenuHandler {
case "student_assignment_marks":
handleAssignmentMarks(phoneNumber);
break;
case "student_semester_results":
sendSemesterSelection(phoneNumber, token);
break;
case "student_fee_details": {
String rawFees = imsApiService.getFees(token);
String bodyText = MessageFormatter.formatAcademicFeesOnly(rawFees);
List<Map<String, String>> feeButtons = new ArrayList<>();
Map<String, String> examBtn = new HashMap<>();
examBtn.put("id", "student_exam_fees");
examBtn.put("title", "Exam Fees");
feeButtons.add(examBtn);
Map<String, String> historyBtn = new HashMap<>();
historyBtn.put("id", "student_payment_history");
historyBtn.put("title", "Payment History");
feeButtons.add(historyBtn);
if (bodyText.length() > 1020) {
bodyText = bodyText.substring(0, 1017) + "...";
}
Map<String, Object> feeButtonMessage = WhatsAppMessageBuilder.buildButtonMessage(bodyText, feeButtons);
messageService.sendInteractiveMessage(phoneNumber, feeButtonMessage);
sendStudentMenuDirectly(phoneNumber);
case "student_fee_details":
sendFeeDetailsMenu(phoneNumber, token);
break;
}
case "student_raise_grievance":
grievanceHandler.startGrievanceFlow(phoneNumber);
@@ -208,16 +164,18 @@ public class StudentMenuHandler {
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.");
sendSemesterSelection(phoneNumber, token);
} else {
sendResponseWithMenu(phoneNumber, "Failed to upload the results document to WhatsApp.");
messageService.sendMessage(phoneNumber, "Failed to upload the results document to WhatsApp.");
sendSemesterSelection(phoneNumber, token);
}
} else {
sendResponseWithMenu(phoneNumber, "Failed to download your results. They may not be published yet.");
messageService.sendMessage(phoneNumber, "Failed to download your results. They may not be published yet.");
sendSemesterSelection(phoneNumber, token);
}
} catch (Exception e) {
sendResponseWithMenu(phoneNumber, "Invalid semester selected.");
messageService.sendMessage(phoneNumber, "Invalid semester selected.");
sendSemesterSelection(phoneNumber, token);
}
sessionService.resetState(phoneNumber); // Reset state after fetching results
@@ -256,15 +214,18 @@ public class StudentMenuHandler {
String mediaId = messageService.uploadMedia(pdfBytes, fileName, "application/pdf");
if (mediaId != null) {
messageService.sendDocumentMessage(phoneNumber, mediaId, docMessage, fileName);
sendResponseWithMenu(phoneNumber, "Select an option from the menu below.");
sendPaymentHistoryMenu(phoneNumber, token);
} else {
sendResponseWithMenu(phoneNumber, "Failed to upload the receipt document to WhatsApp.");
messageService.sendMessage(phoneNumber, "Failed to upload the receipt document to WhatsApp.");
sendPaymentHistoryMenu(phoneNumber, token);
}
} else {
sendResponseWithMenu(phoneNumber, "Failed to download your receipt. It may not be available.");
messageService.sendMessage(phoneNumber, "Failed to download your receipt. It may not be available.");
sendPaymentHistoryMenu(phoneNumber, token);
}
} catch (Exception e) {
sendResponseWithMenu(phoneNumber, "Invalid receipt selected.");
messageService.sendMessage(phoneNumber, "Invalid receipt selected.");
sendPaymentHistoryMenu(phoneNumber, token);
}
sessionService.resetState(phoneNumber); // Reset state after fetching receipt
@@ -283,8 +244,8 @@ public class StudentMenuHandler {
// Send weekly timetable as standard message (up to 4096 characters limit)
messageService.sendMessage(phoneNumber, weeklyTimetable);
// Follow up with Student Menu list message
sendResponseWithMenu(phoneNumber, "Select an option from the menu below.");
// Follow up with Timetable sub-menu again
sendTimetableMenu(phoneNumber, token);
}
public void handleExamFees(String phoneNumber) {
@@ -296,7 +257,8 @@ public class StudentMenuHandler {
String rawExamFees = imsApiService.getExamFees(token);
String formattedExamFees = MessageFormatter.formatExamFees(rawExamFees);
sendResponseWithMenu(phoneNumber, formattedExamFees);
messageService.sendMessage(phoneNumber, formattedExamFees);
sendFeeDetailsMenu(phoneNumber, token);
}
public void handlePaymentHistory(String phoneNumber) {
@@ -305,7 +267,61 @@ public class StudentMenuHandler {
messageService.sendMessage(phoneNumber, "Your session has expired. Please type 'Reset' to login again.");
return;
}
sendPaymentHistoryMenu(phoneNumber, token);
}
public void sendTimetableMenu(String phoneNumber, String token) {
String rawTimetable = imsApiService.getTimetable(token);
String todaySchedule = MessageFormatter.formatTimetable(rawTimetable);
// Truncate to stay safely within WhatsApp 1024 character limit for button bodies
if (todaySchedule.length() > 1020) {
todaySchedule = todaySchedule.substring(0, 1017) + "...";
}
List<Map<String, String>> buttons = new ArrayList<>();
Map<String, String> weeklyBtn = new HashMap<>();
weeklyBtn.put("id", "student_weekly_timetable");
weeklyBtn.put("title", "Weekly Timetable");
buttons.add(weeklyBtn);
Map<String, String> menuBtn = new HashMap<>();
menuBtn.put("id", "student_show_menu");
menuBtn.put("title", "Student Menu");
buttons.add(menuBtn);
System.out.println("FINAL TODAY TIMETABLE MESSAGE:\n" + todaySchedule);
Map<String, Object> buttonMessage = WhatsAppMessageBuilder.buildButtonMessage(todaySchedule, buttons);
messageService.sendInteractiveMessage(phoneNumber, buttonMessage);
sendStudentMenuDirectly(phoneNumber);
}
public void sendFeeDetailsMenu(String phoneNumber, String token) {
String rawFees = imsApiService.getFees(token);
String bodyText = MessageFormatter.formatAcademicFeesOnly(rawFees);
List<Map<String, String>> feeButtons = new ArrayList<>();
Map<String, String> examBtn = new HashMap<>();
examBtn.put("id", "student_exam_fees");
examBtn.put("title", "Exam Fees");
feeButtons.add(examBtn);
Map<String, String> historyBtn = new HashMap<>();
historyBtn.put("id", "student_payment_history");
historyBtn.put("title", "Payment History");
feeButtons.add(historyBtn);
if (bodyText.length() > 1020) {
bodyText = bodyText.substring(0, 1017) + "...";
}
Map<String, Object> feeButtonMessage = WhatsAppMessageBuilder.buildButtonMessage(bodyText, feeButtons);
messageService.sendInteractiveMessage(phoneNumber, feeButtonMessage);
sendStudentMenuDirectly(phoneNumber);
}
public void sendPaymentHistoryMenu(String phoneNumber, String token) {
String rawExamFees = imsApiService.getExamFees(token);
String rawFeesHistory = imsApiService.getAcademicFeesHistory(token);
@@ -408,7 +424,8 @@ public class StudentMenuHandler {
}
String rawCatMarks = imsApiService.getCatMarks(token);
String formatted = com.rit.whatsapp.util.MessageFormatter.formatCat1Marks(rawCatMarks);
sendResponseWithMenu(phoneNumber, formatted);
messageService.sendMessage(phoneNumber, formatted);
sendInternalMarksMenu(phoneNumber);
}
public void handleCat2Marks(String phoneNumber) {
@@ -419,7 +436,8 @@ public class StudentMenuHandler {
}
String rawCatMarks = imsApiService.getCatMarks(token);
String formatted = com.rit.whatsapp.util.MessageFormatter.formatCat2Marks(rawCatMarks);
sendResponseWithMenu(phoneNumber, formatted);
messageService.sendMessage(phoneNumber, formatted);
sendInternalMarksMenu(phoneNumber);
}
public void handleCat3Marks(String phoneNumber) {
@@ -430,7 +448,8 @@ public class StudentMenuHandler {
}
String rawCatMarks = imsApiService.getCatMarks(token);
String formatted = com.rit.whatsapp.util.MessageFormatter.formatCat3Marks(rawCatMarks);
sendResponseWithMenu(phoneNumber, formatted);
messageService.sendMessage(phoneNumber, formatted);
sendInternalMarksMenu(phoneNumber);
}
public void handleAssignmentMarks(String phoneNumber) {
@@ -441,7 +460,8 @@ public class StudentMenuHandler {
}
String rawAssignmentMarks = imsApiService.getAssignmentMarks(token);
String formatted = com.rit.whatsapp.util.MessageFormatter.formatAssignmentMarks(rawAssignmentMarks);
sendResponseWithMenu(phoneNumber, formatted);
messageService.sendMessage(phoneNumber, formatted);
sendInternalMarksMenu(phoneNumber);
}
private List<Map<String, String>> getStudentMenuRows() {