Spaces:
Sleeping
Sleeping
File size: 32,908 Bytes
0b355ec 7851df6 0b355ec | 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | const { validationResult } = require('express-validator');
const { v4: uuidv4 } = require('uuid');
const mongoose = require('mongoose');
const Conversation = require('../models/Conversation');
const User = require('../models/User');
const aiService = require('../services/aiService');
const ugaService = require('../services/ugaService');
const agenticService = require('../services/agenticService');
const knowledgeBaseService = require('../services/knowledgeBaseService');
const logger = require('../utils/logger');
class ChatController {
async sendMessage(req, res) {
try {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({
success: false,
errors: errors.array()
});
}
const { message, sessionId, category } = req.body;
// Get user ID - require authenticated user
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
error: 'Authentication required'
});
}
const userId = req.user.id || req.user._id;
// Find or create conversation
let conversation;
if (sessionId) {
conversation = await Conversation.findOne({
sessionId,
userId,
isActive: true
});
}
if (!conversation) {
conversation = new Conversation({
userId,
sessionId: sessionId || uuidv4(),
category: category || 'general'
});
await conversation.save();
}
// Add user message
await conversation.addMessage('user', message);
// Prepare user context for AI
let user = await User.findById(userId);
// Handle missing user data
if (!user) {
return res.status(404).json({
success: false,
error: 'User not found'
});
}
const userContext = {
userId: userId,
role: user.role,
college: user.college,
major: user.major,
classification: user.classification
};
// First, check if this is an agentic request (requires actions)
const agenticResult = await agenticService.processAgenticRequest(
message,
user,
conversation.messages.map(msg => ({ role: msg.role, content: msg.content }))
);
let aiResponse;
if (agenticResult.requiresAction) {
// This is an agentic request - actions were planned and executed
aiResponse = {
content: agenticResult.response,
metadata: {
agentic: true,
actionsExecuted: agenticResult.executionResults.map(r => r.action),
executionResults: agenticResult.executionResults,
responseTime: agenticResult.executionResults.reduce((total, r) => total + (r.executionTime || 0), 0),
tokens: 0
}
};
} else {
// Check if this is a knowledge base query
const knowledgeResults = await knowledgeBaseService.queryKnowledgeBase(message);
if (knowledgeResults.length > 0) {
// Enhanced AI response with knowledge base context
const knowledgeContext = knowledgeResults.map(r =>
`${r.section}: ${r.content}`
).join('\n');
const enhancedMessages = [
{
role: 'system',
content: `Here is relevant UGA/Athens information to help answer the user's question:\n\n${knowledgeContext}`
},
...conversation.messages.map(msg => ({
role: msg.role,
content: msg.content
}))
];
aiResponse = await aiService.generateResponse(enhancedMessages, userContext);
aiResponse.metadata.knowledgeBaseUsed = true;
aiResponse.metadata.knowledgeResults = knowledgeResults.length;
} else {
// Check if this is a UGA system-specific query
// TEMPORARY: Disable UGA specific queries for testing
const ugaResponse = null;
if (ugaResponse) {
aiResponse = {
content: ugaResponse,
metadata: {
ugaSystemUsed: this.detectUgaSystem(message),
responseTime: 100,
tokens: 0
}
};
} else {
// Standard AI response
const messages = conversation.messages.map(msg => ({
role: msg.role,
content: msg.content
}));
aiResponse = await aiService.generateResponse(messages, userContext);
}
}
}
// Add AI response to conversation
await conversation.addMessage('assistant', aiResponse.content, aiResponse.metadata);
// Update user statistics
await user.incrementChatStats(conversation.category);
// Update conversation statistics
await conversation.updateStats(
aiResponse.metadata.tokens || 0,
aiResponse.metadata.responseTime || 0
);
logger.info('Chat message processed', {
userId,
sessionId: conversation.sessionId,
messageLength: message.length,
responseTime: aiResponse.metadata.responseTime
});
res.json({
success: true,
data: {
response: aiResponse.content,
sessionId: conversation.sessionId,
conversationId: conversation._id,
metadata: {
intent: aiResponse.metadata.intent,
ugaSystemUsed: aiResponse.metadata.ugaSystemUsed,
confidence: aiResponse.metadata.confidence
}
}
});
} catch (error) {
logger.error('Chat message error:', error);
res.status(500).json({
success: false,
error: 'Failed to process message'
});
}
}
async getConversations(req, res) {
try {
// Get user ID - require authenticated user
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
error: 'Authentication required'
});
}
const userId = req.user.id || req.user._id;
const { page = 1, limit = 20, category } = req.query;
const query = {
userId,
isActive: true
};
if (category && category !== 'all') {
query.category = category;
}
const conversations = await Conversation.find(query)
.sort({ lastActivity: -1 })
.limit(limit * 1)
.skip((page - 1) * limit)
.select('sessionId title category lastActivity stats.messageCount');
const total = await Conversation.countDocuments(query);
// Transform conversations to match frontend expectations
const transformedConversations = conversations.map(conv => ({
id: conv._id.toString(),
sessionId: conv.sessionId,
title: conv.title,
category: conv.category,
lastActivity: conv.lastActivity,
stats: conv.stats
}));
res.json({
success: true,
data: {
conversations: transformedConversations,
pagination: {
page: parseInt(page),
limit: parseInt(limit),
total,
pages: Math.ceil(total / limit)
}
}
});
} catch (error) {
logger.error('Get conversations error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch conversations'
});
}
}
async getConversation(req, res) {
try {
const { conversationId } = req.params;
// Get user ID - require authenticated user
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
error: 'Authentication required'
});
}
const userId = req.user.id || req.user._id;
// Validate conversation ID
if (!conversationId || conversationId === 'undefined' || conversationId === 'null') {
return res.status(400).json({
success: false,
error: 'Invalid conversation ID'
});
}
const conversation = await Conversation.findOne({
_id: conversationId,
userId,
isActive: true
});
if (!conversation) {
return res.status(404).json({
success: false,
error: 'Conversation not found'
});
}
// Transform conversation to match frontend expectations
const transformedConversation = {
id: conversation._id.toString(),
sessionId: conversation.sessionId,
title: conversation.title,
category: conversation.category,
messages: conversation.messages.map(msg => ({
id: msg._id.toString(),
role: msg.role,
content: msg.content,
timestamp: msg.timestamp,
metadata: msg.metadata
})),
ugaContext: conversation.ugaContext,
isActive: conversation.isActive,
lastActivity: conversation.lastActivity,
stats: conversation.stats,
retentionDate: conversation.retentionDate,
createdAt: conversation.createdAt,
updatedAt: conversation.updatedAt
};
res.json({
success: true,
data: transformedConversation
});
} catch (error) {
logger.error('Get conversation error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch conversation'
});
}
}
async deleteConversation(req, res) {
try {
const { conversationId } = req.params;
// Get user ID - require authenticated user
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
error: 'Authentication required'
});
}
const userId = req.user.id || req.user._id;
const conversation = await Conversation.findOneAndUpdate(
{ _id: conversationId, userId },
{ isActive: false },
{ new: true }
);
if (!conversation) {
return res.status(404).json({
success: false,
error: 'Conversation not found'
});
}
logger.info('Conversation deleted', { userId, conversationId });
res.json({
success: true,
message: 'Conversation deleted successfully'
});
} catch (error) {
logger.error('Delete conversation error:', error);
res.status(500).json({
success: false,
error: 'Failed to delete conversation'
});
}
}
async rateConversation(req, res) {
try {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({
success: false,
errors: errors.array()
});
}
const { conversationId } = req.params;
const { rating, feedback } = req.body;
// Get user ID - require authenticated user
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
error: 'Authentication required'
});
}
const userId = req.user.id || req.user._id;
const conversation = await Conversation.findOne({
_id: conversationId,
userId,
isActive: true
});
if (!conversation) {
return res.status(404).json({
success: false,
error: 'Conversation not found'
});
}
await conversation.setSatisfaction(rating, feedback);
logger.info('Conversation rated', { userId, conversationId, rating });
res.json({
success: true,
message: 'Rating submitted successfully'
});
} catch (error) {
logger.error('Rate conversation error:', error);
res.status(500).json({
success: false,
error: 'Failed to submit rating'
});
}
}
// Student-specific endpoints
async getStudentCourses(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const courses = await ugaService.getElcCourses(user.id, req.token);
if (!courses.success) {
return res.status(503).json({
success: false,
error: courses.error,
fallback: courses.fallback
});
}
res.json({
success: true,
data: courses.data
});
} catch (error) {
logger.error('Get student courses error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch courses'
});
}
}
async getStudentGrades(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
const { semester } = req.query;
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const grades = await ugaService.getAthenaGrades(user.id, semester, req.token);
if (!grades.success) {
return res.status(503).json({
success: false,
error: grades.error
});
}
res.json({
success: true,
data: grades.data
});
} catch (error) {
logger.error('Get student grades error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch grades'
});
}
}
async getStudentAssignments(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
const { courseId } = req.query;
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const assignments = await ugaService.getElcAssignments(user.id, courseId, req.token);
if (!assignments.success) {
return res.status(503).json({
success: false,
error: assignments.error
});
}
res.json({
success: true,
data: assignments.data
});
} catch (error) {
logger.error('Get student assignments error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch assignments'
});
}
}
async getStudentSchedule(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const studentInfo = await ugaService.getAthenaStudentInfo(user.id, req.token);
if (!studentInfo.success) {
return res.status(503).json({
success: false,
error: studentInfo.error,
fallback: studentInfo.fallback
});
}
res.json({
success: true,
data: studentInfo.data.schedule || []
});
} catch (error) {
logger.error('Get student schedule error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch schedule'
});
}
}
async getAnalytics(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'admin' };
if (user.role !== 'admin') {
return res.status(403).json({
success: false,
error: 'Access restricted to administrators'
});
}
const { startDate, endDate } = req.query;
const start = startDate ? new Date(startDate) : new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
const end = endDate ? new Date(endDate) : new Date();
const analytics = await Conversation.getAnalytics(start, end);
res.json({
success: true,
data: analytics
});
} catch (error) {
logger.error('Get analytics error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch analytics'
});
}
}
// Enhanced Student Services
async getRegistrationInfo(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const registrationInfo = await ugaService.getRegistrationInfo(user.id, req.token);
if (!registrationInfo.success) {
return res.status(503).json({
success: false,
error: registrationInfo.error
});
}
res.json({
success: true,
data: registrationInfo.data
});
} catch (error) {
logger.error('Get registration info error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch registration information'
});
}
}
async getFinancialAidInfo(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const financialAid = await ugaService.getFinancialAidInfo(user.id, req.token);
if (!financialAid.success) {
return res.status(503).json({
success: false,
error: financialAid.error
});
}
res.json({
success: true,
data: financialAid.data
});
} catch (error) {
logger.error('Get financial aid info error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch financial aid information'
});
}
}
async getHousingInfo(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const housing = await ugaService.getHousingInfo(user.id, req.token);
if (!housing.success) {
return res.status(503).json({
success: false,
error: housing.error
});
}
res.json({
success: true,
data: housing.data
});
} catch (error) {
logger.error('Get housing info error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch housing information'
});
}
}
async getMealPlanInfo(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const mealPlans = await ugaService.getMealPlanInfo(user.id, req.token);
if (!mealPlans.success) {
return res.status(503).json({
success: false,
error: mealPlans.error
});
}
res.json({
success: true,
data: mealPlans.data
});
} catch (error) {
logger.error('Get meal plan info error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch meal plan information'
});
}
}
async getBillingInfo(req, res) {
try {
// TEMPORARY: Use mock user when auth is disabled
const user = req.user || { id: '507f1f77bcf86cd799439011', role: 'student' };
if (user.role !== 'student') {
return res.status(403).json({
success: false,
error: 'Access restricted to students'
});
}
const billing = await ugaService.getBillingInfo(user.id, req.token);
if (!billing.success) {
return res.status(503).json({
success: false,
error: billing.error
});
}
res.json({
success: true,
data: billing.data
});
} catch (error) {
logger.error('Get billing info error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch billing information'
});
}
}
async getAcademicCalendar(req, res) {
try {
const { year } = req.query;
const currentYear = new Date().getFullYear();
const targetYear = year || currentYear;
const calendar = await ugaService.getAcademicCalendar(targetYear);
if (!calendar.success) {
return res.status(503).json({
success: false,
error: calendar.error
});
}
res.json({
success: true,
data: calendar.data
});
} catch (error) {
logger.error('Get academic calendar error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch academic calendar'
});
}
}
async getQuickResponses(req, res) {
try {
const quickResponses = [
{
category: 'eLC',
questions: [
{ q: 'How do I access eLC?', a: 'Visit elc.uga.edu and log in with your MyID credentials.' },
{ q: 'Why can\'t I see my courses in eLC?', a: 'Make sure you\'re enrolled and the instructor has published the course.' },
{ q: 'How do I submit an assignment in eLC?', a: 'Go to your course, find the assignment, and click "Submit Assignment".' }
]
},
{
category: 'Registration',
questions: [
{ q: 'When does registration open?', a: 'Registration dates vary by classification. Check Athena for your specific time.' },
{ q: 'How do I add/drop classes?', a: 'Use Athena during the add/drop period for your semester.' },
{ q: 'What if a class is full?', a: 'You can join the waitlist if available, or look for alternative sections.' }
]
},
{
category: 'Financial Aid',
questions: [
{ q: 'When is the FAFSA deadline?', a: 'The priority deadline is March 1. Use UGA school code 001598.' },
{ q: 'How do I apply for scholarships?', a: 'Visit scholarships.uga.edu to apply for UGA scholarships by January 1.' },
{ q: 'What is the HOPE Scholarship?', a: 'Merit-based scholarship for Georgia residents with 3.0+ GPA.' }
]
},
{
category: 'Housing & Dining',
questions: [
{ q: 'How do I apply for housing?', a: 'Submit your housing application online with a $300 deposit by May 1.' },
{ q: 'What meal plans are available?', a: 'Four plans: Bulldog (unlimited), Dawg (200 meals), Pup (150 meals), Commuter (50 meals).' },
{ q: 'Where can I eat on campus?', a: 'The Niche, ECV Dining Commons, Village Summit Food Court, and Bulldog Cafe.' }
]
},
{
category: 'Technical Support',
questions: [
{ q: 'I forgot my MyID password', a: 'Visit myid.uga.edu to reset your password or call EITS at 706-542-3106.' },
{ q: 'How do I set up ArchPass?', a: 'Download Duo Mobile and follow the setup instructions when prompted.' },
{ q: 'WiFi not working', a: 'Forget and reconnect to UGA-WiFi network, or contact EITS for help.' }
]
}
];
res.json({
success: true,
data: quickResponses
});
} catch (error) {
logger.error('Get quick responses error:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch quick responses'
});
}
}
// Helper methods
async handleUgaSpecificQuery(message, user) {
const lowerMessage = message.toLowerCase();
// Handle system status queries
if (lowerMessage.includes('system status') || lowerMessage.includes('is elc down')) {
const status = await ugaService.getSystemStatus();
return this.formatSystemStatus(status);
}
// Handle IT support queries
if (lowerMessage.includes('it support') || lowerMessage.includes('help desk')) {
const support = await ugaService.getITSupport();
return this.formatITSupport(support.data);
}
// Handle registration queries
if (lowerMessage.includes('registration') || lowerMessage.includes('register for classes') || lowerMessage.includes('how to enroll')) {
const registration = await ugaService.getRegistrationInfo(user.id, null);
return this.formatRegistrationInfo(registration.data);
}
// Handle financial aid queries
if (lowerMessage.includes('financial aid') || lowerMessage.includes('fafsa') || lowerMessage.includes('scholarship') || lowerMessage.includes('hope')) {
const financialAid = await ugaService.getFinancialAidInfo(user.id, null);
return this.formatFinancialAidInfo(financialAid.data);
}
// Handle housing queries
if (lowerMessage.includes('housing') || lowerMessage.includes('dorm') || lowerMessage.includes('residence hall')) {
const housing = await ugaService.getHousingInfo(user.id, null);
return this.formatHousingInfo(housing.data);
}
// Handle meal plan queries
if (lowerMessage.includes('meal plan') || lowerMessage.includes('dining') || lowerMessage.includes('bulldog bucks')) {
const mealPlans = await ugaService.getMealPlanInfo(user.id, null);
return this.formatMealPlanInfo(mealPlans.data);
}
// Handle billing queries
if (lowerMessage.includes('tuition') || lowerMessage.includes('billing') || lowerMessage.includes('payment')) {
const billing = await ugaService.getBillingInfo(user.id, null);
return this.formatBillingInfo(billing.data);
}
// Handle campus services
if (lowerMessage.includes('library') || lowerMessage.includes('gym') || lowerMessage.includes('recreation')) {
const services = await ugaService.getCampusServices();
return this.formatCampusServices(services.data, lowerMessage);
}
return null;
}
detectUgaSystem(message) {
const lowerMessage = message.toLowerCase();
if (lowerMessage.includes('elc') || lowerMessage.includes('elearning')) {
return 'eLC';
} else if (lowerMessage.includes('athena')) {
return 'Athena';
} else if (lowerMessage.includes('myid') || lowerMessage.includes('archpass')) {
return 'MyID';
}
return null;
}
formatSystemStatus(status) {
let response = 'UGA System Status:\n\n';
for (const [system, systemStatus] of Object.entries(status)) {
const statusIndicator = systemStatus === 'operational' ? '[ONLINE]' : '[OFFLINE]';
response += `${statusIndicator} ${system.toUpperCase()}: ${systemStatus}\n`;
}
response += '\nIf you\'re experiencing issues, contact EITS at 706-542-3106.';
return response;
}
formatITSupport(support) {
return `**EITS Help Desk**
π Phone: ${support.eits.phone}
π§ Email: ${support.eits.email}
π Hours: ${support.eits.hours}
π Location: ${support.eits.location}
**Common Solutions:**
${Object.entries(support.commonIssues).map(([issue, solution]) =>
`β’ **${issue}:** ${solution}`
).join('\n')}`;
}
formatRegistrationInfo(registration) {
return `**UGA Course Registration**
**Registration Window:**
β’ Opens: ${registration.registrationWindow.opens}
β’ Priority: ${registration.registrationWindow.priority}
β’ System: ${registration.registrationWindow.location}
**Registration Process:**
${registration.process.steps.map((step, index) => `${index + 1}. ${step}`).join('\n')}
**Important Tips:**
${registration.tips.map(tip => `β’ ${tip}`).join('\n')}
**Key Dates:**
β’ Advising: ${registration.importantDates.advising}
β’ Registration: ${registration.importantDates.registration}
β’ Add/Drop: ${registration.importantDates.addDrop}
β’ Withdrawal Deadline: ${registration.importantDates.withdrawalDeadline}`;
}
formatFinancialAidInfo(aid) {
return `**UGA Financial Aid Information**
**Financial Aid Office:**
π ${aid.office.location}
π ${aid.office.phone}
π§ ${aid.office.email}
π ${aid.office.hours}
**Applications:**
β’ **FAFSA:** Due ${aid.applications.fafsa.deadline} (UGA code: ${aid.applications.fafsa.schoolCode})
β’ **UGA Scholarships:** Due ${aid.applications.ugaScholarships.deadline}
**Available Aid Types:**
${aid.aidTypes.map(type =>
`β’ **${type.type}:** ${type.description}${type.requirements ? `\n Requirements: ${type.requirements}` : ''}`
).join('\n')}
**Important Deadlines:**
β’ FAFSA Priority: ${aid.deadlines.fafsa}
β’ Verification: ${aid.deadlines.verification}
β’ Response: ${aid.deadlines.acceptanceResponse}`;
}
formatHousingInfo(housing) {
return `**UGA Housing Information**
**Housing Office:**
π ${housing.office.phone}
π§ ${housing.office.email}
π ${housing.office.website}
**Application Process:**
β’ Deadline: ${housing.application.deadline}
β’ Deposit: ${housing.application.deposit}
β’ Portal: ${housing.application.portal}
**Process Steps:**
${housing.application.process.map((step, index) => `${index + 1}. ${step}`).join('\n')}
**Residence Halls:**
${housing.dormitories.map(dorm =>
`β’ **${dorm.name}** (${dorm.type})\n Occupancy: ${dorm.occupancy}\n Amenities: ${dorm.amenities.join(', ')}`
).join('\n\n')}
**Annual Costs:**
β’ Traditional: ${housing.costs.traditional}
β’ Suite-style: ${housing.costs.suite}
β’ Apartment-style: ${housing.costs.apartment}`;
}
formatMealPlanInfo(mealPlans) {
return `**UGA Meal Plans**
**Dining Services:**
π ${mealPlans.office.phone}
π§ ${mealPlans.office.email}
π ${mealPlans.office.website}
**Available Plans:**
${mealPlans.plans.map(plan =>
`β’ **${plan.name}** - ${plan.cost}\n ${plan.meals} + ${plan.flex}\n Best for: ${plan.bestFor}`
).join('\n\n')}
**Dining Locations:**
${mealPlans.locations.map(location =>
`β’ **${location.name}** (${location.type})\n Location: ${location.location}\n Hours: ${location.hours}`
).join('\n\n')}
**Bulldog Bucks:**
${mealPlans.bullDogBucks.description}
β’ Use at: ${mealPlans.bullDogBucks.locations}
β’ Rollover: ${mealPlans.bullDogBucks.rollover}
β’ Refundable: ${mealPlans.bullDogBucks.refundable}`;
}
formatBillingInfo(billing) {
return `**UGA Student Accounts & Billing**
**Student Accounts Office:**
π ${billing.office.location}
π ${billing.office.phone}
π§ ${billing.office.email}
π ${billing.office.hours}
**Payment Methods:**
${billing.paymentMethods.map(method => `β’ ${method}`).join('\n')}
**Payment Plans:**
β’ **Semester Plan:** ${billing.paymentPlans.semesterPlan.description} (${billing.paymentPlans.semesterPlan.discount})
β’ **Monthly Plan:** ${billing.paymentPlans.monthlyPlan.description} (${billing.paymentPlans.monthlyPlan.fee})
**2024-25 Tuition & Fees:**
β’ **In-State Undergraduate:** ${billing.tuitionFees.inState.undergraduate}
β’ **Out-of-State Undergraduate:** ${billing.tuitionFees.outOfState.undergraduate}
β’ **Additional Fees:** ${billing.tuitionFees.additionalFees}
**Important Dates:**
β’ Fall Bill Available: ${billing.importantDates.fall2024.billAvailable}
β’ Fall Payment Due: ${billing.importantDates.fall2024.paymentDue}`;
}
formatCampusServices(services, query) {
if (query.includes('dining')) {
return `**UGA Dining Locations:**
${services.dining.locations.map(location =>
`β’ **${location.name}** - ${location.location}\n Hours: ${location.hours}`
).join('\n\n')}`;
}
if (query.includes('library')) {
return `**UGA Libraries:**
${services.libraries.map(lib =>
`β’ **${lib.name}**\n Hours: ${lib.hours}\n Services: ${lib.services.join(', ')}`
).join('\n\n')}`;
}
if (query.includes('gym') || query.includes('fitness')) {
return `**${services.recreation.ramsey.name}**
Hours: ${services.recreation.ramsey.hours}
Facilities:
${services.recreation.ramsey.facilities.map(facility => `β’ ${facility}`).join('\n')}`;
}
return null;
}
}
module.exports = new ChatController(); |