Time table feature initiated

This commit is contained in:
Sidharth Prabhu
2026-08-20 09:54:51 +05:30
parent 32b16f363d
commit f0011b4af1
3 changed files with 118 additions and 1 deletions

View File

@@ -69,7 +69,21 @@ public class StudentMenuHandler {
case "student_timetable":
String rawTimetable = imsApiService.getTimetable(token);
sendResponseWithMenu(phoneNumber, MessageFormatter.formatTimetable(rawTimetable));
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, Object> buttonMessage = WhatsAppMessageBuilder.buildButtonMessage(todaySchedule, buttons);
messageService.sendInteractiveMessage(phoneNumber, buttonMessage);
break;
case "student_internal_marks":
@@ -217,6 +231,23 @@ public class StudentMenuHandler {
sessionService.resetState(phoneNumber); // Reset state after fetching receipt
}
public void handleWeeklyTimetable(String phoneNumber) {
String token = sessionService.getImsToken(phoneNumber);
if (token == null) {
messageService.sendMessage(phoneNumber, "Your session has expired. Please type 'Reset' to login again.");
return;
}
String rawTimetable = imsApiService.getTimetable(token);
String weeklyTimetable = MessageFormatter.formatWeeklyTimetable(rawTimetable);
// 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.");
}
private void sendResponseWithMenu(String phoneNumber, String bodyText) {
// Meta API interactive list body limit is 1024 characters
if (bodyText.length() > 1024) {