viewof chatMessages = {
let queryCount = 0;
let broncosMode = false;
const BRONCOS_FACTS = [
"The 1998 Broncos started 13-0, the best start by any team since the undefeated 1972 Miami Dolphins.",
"Terrell Davis rushed for 2,008 yards despite suffering from debilitating migraines that made him temporarily blind during games.",
"John Elway posted his career-best passer rating of 93.0 at age 38 in his final season.",
"The offensive line used Alex Gibbs' revolutionary zone blocking scheme and was the lightest in the NFL.",
"Shannon Sharpe once trash-talked Derrick Thomas so badly that Thomas got three personal fouls in one drive and was suspended by his own team.",
"Rod Smith was undrafted from Division II Missouri Southern State and became the first undrafted player to reach 10,000 career receiving yards.",
"Jason Elam kicked a 63-yard field goal to tie the NFL record after getting a delay of game penalty that pushed him back 5 yards.",
"Terrell Davis had 2,476 total rushing yards including playoffs, an NFL record for a single season.",
"The Broncos scored 501 points, averaging 31.3 per game, and routinely led by three touchdowns after the first quarter.",
"Center Tom Nalen was a 7th-round pick who was initially cut after training camp before becoming a cornerstone of the offense.",
"Mark Schlereth played through 29 surgeries during his career, including 20 on his knees.",
"Ed McCaffrey and Rod Smith both exceeded 1,000 receiving yards, only the second receiver tandem to do so on the same team.",
"Terrell Davis set a record with seven consecutive 100-yard playoff games, breaking John Riggins' record.",
"The Broncos defeated Miami 38-3 in the playoffs, their first victory over the Dolphins in 30 years.",
"John Elway went 18-0 at home over the two championship seasons, never losing at Mile High.",
"Alex Gibbs kept training camp sessions far from fans because his profanity-laced coaching style was too offensive.",
"Fox missed broadcasting Rod Smith's 80-yard Super Bowl touchdown because they were airing a commercial for The Matrix.",
"Eugene Robinson was arrested for solicitation the night before the Super Bowl, hours after receiving an award for 'high moral character.'",
"John Elway retired exactly 16 years to the day after being traded to Denver.",
"The offensive line created a 'Kangaroo Court' that fined anyone for media interviews, including fining Mike Shanahan $310.",
"Terrell Davis forgot his migraine medication before Super Bowl XXXII and played the second half after being temporarily blind.",
"The Broncos became only the fifth team in NFL history to win back-to-back Super Bowls.",
"John Elway threw for 336 yards in Super Bowl XXXIII at 11.6 yards per attempt, the second-highest in Super Bowl history.",
"The team's offensive line coach Alex Gibbs had a doctorate in French history.",
"Jason Elam made 19 consecutive field goals and was perfect on all 58 extra point attempts.",
"Darrien Gordon intercepted two passes for 108 return yards in the Super Bowl, setting a record.",
"The Giants team that ended Denver's 13-0 streak would later end the Patriots' 18-0 run in Super Bowl XLII.",
"Terrell Davis ran for 199 yards against Miami in the playoffs, a franchise playoff record.",
"The Broncos were later fined nearly $2 million for salary cap violations from 1996-1998.",
"John Elway became the only quarterback to retire immediately after winning a Super Bowl."
];
const container = html`<div style="
border: 1px solid #ddd;
border-radius: 8px;
max-width: 600px;
margin: 20px 0;
">
<div id="messages" style="
height: 400px;
overflow-y: auto;
padding: 15px;
background: #f9f9f9;
"></div>
<div style="
display: flex;
gap: 10px;
padding: 15px;
border-top: 1px solid #ddd;
background: white;
">
<input
type="text"
id="chatInput"
placeholder="Ask me anything..."
style="
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
"
/>
<button id="sendBtn" style="
padding: 10px 20px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
">Send</button>
</div>
</div>`;
const messagesDiv = container.querySelector('#messages');
const input = container.querySelector('#chatInput');
const sendBtn = container.querySelector('#sendBtn');
function addMessage(text, isUser) {
const msg = html`<div style="
margin-bottom: 10px;
padding: 10px;
border-radius: 6px;
${isUser ? 'background: #007bff; color: white; margin-left: 20%;' : 'background: white; margin-right: 20%;'}
">${text}</div>`;
messagesDiv.appendChild(msg);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
async function sendMessage() {
const message = input.value.trim();
if (!message) return;
addMessage(message, true);
input.value = '';
sendBtn.disabled = true;
try {
// If in Broncos mode, just return a random fact
if (broncosMode) {
const randomFact = BRONCOS_FACTS[Math.floor(Math.random() * BRONCOS_FACTS.length)];
addMessage(randomFact, false);
sendBtn.disabled = false;
input.focus();
return;
}
// Check if we've hit the limit
if (queryCount >= 3) {
broncosMode = true;
addMessage("Sorry, the economy is crazy right now. From now on I'll just respond with facts about the 1998 denver broncos", false);
sendBtn.disabled = false;
input.focus();
return;
}
// Increment counter and call API
queryCount++;
const response = await fetch('/.netlify/functions/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
});
const data = await response.json();
addMessage(data.response, false);
} catch (error) {
addMessage('Error: ' + error.message, false);
} finally {
sendBtn.disabled = false;
input.focus();
}
}
sendBtn.onclick = sendMessage;
input.onkeypress = (e) => {
if (e.key === 'Enter') sendMessage();
};
addMessage("Hi! This is definitely Matt for real and not a RAG chatbot. Ask me anything! You get THREE questions!", false);
return container;
}About
About Me
I live in Berkeley, California, with my partner, dog, and son. Prior to becoming a new parent, you could find me sailing, hiking, camping, and biking around Northern California. I also love(d) to cook and brew beer and have placed as high as 2nd place in an international chili cookoff, which I fear will prove to be my life’s greatest accomplishment. Now, I happily spend my time with the wee baby and family.
Photos
