135 lines
6.9 KiB
JavaScript
135 lines
6.9 KiB
JavaScript
class PortfolioChatEngine {
|
|
constructor(data) {
|
|
this.data = data || { settings: null, projects: [], certs: [], articles: [] };
|
|
}
|
|
|
|
match(message) {
|
|
const text = message.toLowerCase();
|
|
|
|
const intents = [
|
|
{
|
|
name: 'greeting',
|
|
keywords: ['hi', 'hello', 'hey', 'what\'s up', 'howdy', 'greetings'],
|
|
response: () => "Hi there! I'm Cris's virtual assistant. I can tell you about his **skills**, **projects**, **certifications**, or how to **contact** him. What would you like to know?"
|
|
},
|
|
{
|
|
name: 'about',
|
|
keywords: ['who are you', 'about', 'introduce', 'background', 'cris charles', 'who is cris'],
|
|
response: () => {
|
|
if (this.data.settings) {
|
|
return `${this.data.settings.about_text_1}\n\n${this.data.settings.about_text_2}`;
|
|
}
|
|
return "Cris is a senior IT student majoring in Software Development based in Laguna, Philippines. He's passionate about building scalable apps and beautiful UIs.";
|
|
}
|
|
},
|
|
{
|
|
name: 'skills',
|
|
keywords: ['skills', 'technologies', 'stack', 'languages', 'php', 'react', 'javascript', 'css', 'html', 'python', 'java'],
|
|
response: () => {
|
|
return "Cris works with a variety of modern technologies. His core stack includes **PHP, JavaScript, Python, Java, C++** and frameworks like **React, NextJS, Node.js, and Express**. He's also experienced with **MySQL, MongoDB, Tailwind CSS, and Git**.";
|
|
}
|
|
},
|
|
{
|
|
name: 'projects',
|
|
keywords: ['projects', 'built', 'work', 'portfolio', 'apps', 'websites', 'what have you done'],
|
|
response: () => {
|
|
if (this.data.projects && this.data.projects.length > 0) {
|
|
let res = `Cris has built ${this.data.projects.length} main projects. Here are some of them:\n\n`;
|
|
this.data.projects.slice(0, 3).forEach(p => {
|
|
res += `- **${p.title}**: ${p.des} (Built with ${p.techstack})\n`;
|
|
});
|
|
res += `\nYou can check out the full list in the **Projects** section!`;
|
|
return res;
|
|
}
|
|
return "Cris has built several full-stack web applications, including e-commerce platforms, chat apps, and student management systems. You can view them all in the Projects section above!";
|
|
}
|
|
},
|
|
{
|
|
name: 'certifications',
|
|
keywords: ['certifications', 'certificates', 'courses', 'credentials', 'cert'],
|
|
response: () => {
|
|
if (this.data.certs && this.data.certs.length > 0) {
|
|
let res = `Cris holds ${this.data.certs.length} certifications. A few recent ones:\n\n`;
|
|
this.data.certs.slice(0, 3).forEach(c => {
|
|
res += `- **${c.title}** by ${c.issuer}\n`;
|
|
});
|
|
return res;
|
|
}
|
|
return "Cris has completed multiple certifications from Cisco, freeCodeCamp, and other reputable institutions to continuously improve his software development skills.";
|
|
}
|
|
},
|
|
{
|
|
name: 'blog',
|
|
keywords: ['blog', 'articles', 'writing', 'posts', 'read'],
|
|
response: () => {
|
|
if (this.data.articles && this.data.articles.length > 0) {
|
|
let res = `Cris occasionally writes about tech. Here are his latest articles:\n\n`;
|
|
this.data.articles.slice(0, 2).forEach(a => {
|
|
res += `- **[${a.title}](${a.url})**: ${a.excerpt}\n`;
|
|
});
|
|
return res;
|
|
}
|
|
return "Cris shares his thoughts on software development and technology in his Blog section. Feel free to check it out on the site!";
|
|
}
|
|
},
|
|
{
|
|
name: 'experience',
|
|
keywords: ['experience', 'years', 'coding', 'how long'],
|
|
response: () => {
|
|
let years = this.data.settings ? this.data.settings.years_coding : "several";
|
|
return `Cris has been coding for **${years} years** and has completed multiple projects ranging from front-end designs to complex full-stack applications.`;
|
|
}
|
|
},
|
|
{
|
|
name: 'social',
|
|
keywords: ['github', 'linkedin', 'instagram', 'tiktok', 'social', 'facebook'],
|
|
response: () => {
|
|
if (this.data.settings) {
|
|
return `You can connect with Cris on his social platforms:\n- [GitHub](${this.data.settings.github_url})\n- [LinkedIn](${this.data.settings.linkedin_url})\n- [Instagram](${this.data.settings.instagram_url})\n- [TikTok](${this.data.settings.tiktok_url})`;
|
|
}
|
|
return "You can find links to Cris's GitHub, LinkedIn, and other social media profiles at the bottom of this page in the contact section.";
|
|
}
|
|
},
|
|
{
|
|
name: 'contact',
|
|
keywords: ['contact', 'hire', 'email', 'reach', 'work together', 'message'],
|
|
response: () => {
|
|
return "If you'd like to reach out, you can scroll down to the bottom of the page and use the **Contact Form** to send Cris a direct message. He usually replies within 24 hours!";
|
|
}
|
|
}
|
|
];
|
|
|
|
let bestMatch = null;
|
|
let maxScore = 0;
|
|
|
|
for (const intent of intents) {
|
|
let score = 0;
|
|
for (const keyword of intent.keywords) {
|
|
if (text.includes(keyword)) {
|
|
// Exact word matches get higher score than partial
|
|
const regex = new RegExp(`\\b${keyword}\\b`, 'i');
|
|
if (regex.test(text)) {
|
|
score += 2;
|
|
} else {
|
|
score += 1;
|
|
}
|
|
}
|
|
}
|
|
if (score > maxScore) {
|
|
maxScore = score;
|
|
bestMatch = intent;
|
|
}
|
|
}
|
|
|
|
if (bestMatch && maxScore > 0) {
|
|
return bestMatch.response();
|
|
}
|
|
|
|
// Fallback
|
|
return "I'm not quite sure how to answer that! I mostly know about Cris's **projects, skills, and background**. If you have a specific question for Cris, I recommend using the **Contact Form** at the bottom of the page to send him an email directly.";
|
|
}
|
|
}
|
|
|
|
// Make globally available
|
|
window.PortfolioChatEngine = PortfolioChatEngine;
|