<textarea id="user-input" placeholder="Copy paste your meeting notes..."></textarea>
Submit
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.getElementById('send-button').addEventListener('click', sendMessage);
function removeSpecialCharsAtStart(str) {
return str.replace(/^[^a-zA-Z]+/, '');
}
function formatResponse(responseText) {
// Add a newline before the key phrase "%%Action Items%%"
return responseText.replace(/----/g, '\n----');
}
async function sendMessage() {
const userInput = document.getElementById('user-input').value;
const chatHistory = document.getElementById('chat-history');
// Display user's message
chatHistory.innerHTML += `User: ${userInput}
`;
const controller = new AbortController();
const signal = controller.signal;
// Set a timeout to abort the fetch request
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds
try {
const response = await fetch('https://meetingchat.vercel.app/api/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ meetingchat: userInput }),
signal: signal,
mode: 'cors' // Add this line to enable CORS
});
const data = await response.json();
// Display Chatbot's response
const formattedResponse = formatResponse(removeSpecialCharsAtStart(data.result));
chatHistory.innerHTML += `Bot: ${formattedResponse}
`;
} catch (error) {
if (error.name === 'AbortError') {
chatHistory.innerHTML += `Error: Request timed out
`;
} else {
chatHistory.innerHTML += `Error: ${error.message}
`;
}
} finally {
clearTimeout(timeoutId);
}
// SQL POSTING
try {
const post = await fetch('http://localhost:808/newmeeting', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userInput),
});
if (post.status === 201) {
const sqldata = await post.json();
const responseText = await post.text();
console.log(responseText);
} else {
console.log('Error posting to SQL');
}
} catch (error) {
console.log('Error: ' + error);
}
}
});
</script>