Join Education Updates Join Jobs Updates Join WhatsApp Channel

Aadil Mushtaq Rather

Powered by chinar tech solutions


// App.js
import React, { useState, useRef, useEffect } from ‘react’;
import ‘./App.css’;

WhatsApp channel Join Now
Telegram Group Join Now
Instagram Group Join Now

const App = () => {
const [messages, setMessages] = useState([
{
id: 1,
text: “Hello! I’m Mentorly Assistant. How can I help you connect with students, faculty, or alumni today?”,
sender: ‘bot’,
timestamp: new Date().toLocaleTimeString([], { hour: ‘2-digit’, minute: ‘2-digit’ })
}
]);
const [inputValue, setInputValue] = useState(”);
const [isLoading, setIsLoading] = useState(false);
const [isTyping, setIsTyping] = useState(false);
const messagesEndRef = useRef(null);

const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: “smooth” });
};

useEffect(() => {
scrollToBottom();
}, [messages]);

const handleSendMessage = async (e) => {
e.preventDefault();
if (!inputValue.trim()) return;

const userMessage = {
id: messages.length + 1,
text: inputValue,
sender: ‘user’,
timestamp: new Date().toLocaleTimeString([], { hour: ‘2-digit’, minute: ‘2-digit’ })
};

setMessages(prev => […prev, userMessage]);
setInputValue(”);
setIsTyping(true);

// Simulate API call delay
setTimeout(() => {
const botResponse = generateBotResponse(inputValue);
setIsTyping(false);
setMessages(prev => […prev, botResponse]);
}, 1000);
};

const generateBotResponse = (userInput) => {
const input = userInput.toLowerCase();

const responses = {
greetings: [
“Hello! Welcome to Mentorly. How can I assist with your academic or professional connections today?”,
“Hi there! Ready to connect with mentors, peers, or resources?”,
“Greetings! I’m here to help you navigate the Mentorly platform.”
],
connections: [
“I can help you connect with faculty members in your department. Would you like to browse by department or specific expertise?”,
“Looking for alumni in specific industries? I can filter connections based on career field, company, or location.”,
“To connect with students, you can join study groups, post in discussion forums, or attend virtual networking events.”
],
resources: [
“We have study materials, research papers, and project resources. What specific subject or topic are you looking for?”,
“You can access shared resources by joining relevant groups or using the resource search with keywords.”,
“Faculty often share lecture notes and additional materials in their dedicated channels.”
],
mentorship: [
“The mentorship program pairs students with alumni based on career interests. Would you like to explore available mentors?”,
“You can request mentorship by filling out the mentorship form and specifying your goals and preferred mentor background.”,
“Current mentorship programs include: Career Guidance, Research Collaboration, and Academic Support.”
],
events: [
“Upcoming events: Virtual Networking Mixer (Friday), Research Symposium (Next Week), Career Fair (Month-end)”,
“You can RSVP to events through the Events calendar. Would you like me to show you this week’s schedule?”,
“Faculty often host office hours and special topic sessions. Check the Events section for details.”
],
default: [
“I understand you’re asking about: ” + userInput + “. For detailed assistance, you might want to check the relevant section on Mentorly or contact the support team.”,
“That’s an interesting question! While I process natural language, for specific platform features, you might find detailed answers in our Help Center.”,
“I recommend checking the FAQ section or reaching out to our community moderators for more specific guidance on this topic.”
]
};

let responseCategory = ‘default’;

if (input.includes(‘hello’) || input.includes(‘hi’) || input.includes(‘hey’)) {
responseCategory = ‘greetings’;
} else if (input.includes(‘connect’) || input.includes(‘faculty’) || input.includes(‘alumni’) || input.includes(‘student’)) {
responseCategory = ‘connections’;
} else if (input.includes(‘resource’) || input.includes(‘material’) || input.includes(‘study’)) {
responseCategory = ‘resources’;
} else if (input.includes(‘mentor’) || input.includes(‘guidance’) || input.includes(‘advice’)) {
responseCategory = ‘mentorship’;
} else if (input.includes(‘event’) || input.includes(‘meeting’) || input.includes(‘schedule’)) {
responseCategory = ‘events’;
}

const categoryResponses = responses[responseCategory];
const randomResponse = categoryResponses[Math.floor(Math.random() * categoryResponses.length)];

return {
id: messages.length + 2,
text: randomResponse,
sender: ‘bot’,
timestamp: new Date().toLocaleTimeString([], { hour: ‘2-digit’, minute: ‘2-digit’ })
};
};

const handleQuickAction = (action) => {
const quickMessages = {
‘Connect Faculty’: “How do I connect with faculty members in my department?”,
‘Find Alumni’: “I want to find alumni working in tech companies”,
‘Share Resources’: “Where can I share my study materials with classmates?”,
‘Mentorship’: “Tell me about the mentorship programs available”,
‘Events’: “What events are happening this week?”
};

setInputValue(quickMessages[action]);
};

const suggestedQueries = [
‘How to connect with faculty?’,
‘Find alumni in my field’,
‘Share study resources’,
‘Join mentorship program’,
‘Upcoming networking events’
];

return (

M

Mentorly

Student-Faculty-Alumni Connection Platform

Quick Actions





Suggested Queries

    {suggestedQueries.map((query, index) => (

  • setInputValue(query)}>
    {query}
  • ))}

Platform Stats

500+
Active Faculty
10K+
Students
5K+
Alumni

MA

Mentorly Assistant

Online • Ready to help


{messages.map((message) => (

{message.text}
{message.timestamp}

{message.sender === ‘user’ ? ‘👤’ : ‘🤖’}

))}

{isTyping && (



🤖

)}

setInputValue(e.target.value)}
placeholder=”Ask about connections, resources, mentorship, events…”
className=”message-input”
/>
Try: “How to connect with alumni in tech?” or “Share resources with my class”

© 2024 Mentorly. All rights reserved. | Empowering academic connections

);
};

export default App;


WhatsApp channel Join Now
Telegram Group Join Now
Instagram Group Join Now