const { checkAndRefreshAccessToken } = require('../utils/refreshToken'); const { checkExistingContactRequest, insertContactRequest } = require('../utils/contactRequestDB'); const fetch = require('node-fetch'); const { sendEmail } = require('../utils/sendEmail'); //Getting Vapi Usage Flag (Whether to use or not) const { useVapi} = require("../config"); const assistant_url = 'https://api.vapi.ai/call'; const submitContactForm = async (req, res) => { const { name, email, phone, subject, message } = req.body; console.log('Received contact form submission:', req.body); if (!name || !email || !phone || !subject || !message) { return res.status(400).send({ error: 'All fields are required.' }); } await checkAndRefreshAccessToken(); const existingRequest = await checkExistingContactRequest(name, email, subject); if (existingRequest) { console.log("Your contact request with the same subject is in queue"); return res.status(400).send({ error: 'Your contact request with the same subject is in queue' }); } await insertContactRequest(name, email, phone, subject, message); console.log('Contact request added successfully'); try{ // 🔹 Email to User const userEmailSubject = `Contact Form Submission: ${subject}`; const userEmailContent = `
Thank you for reaching out to us! We have received your message and will get back to you soon.
Your Submitted Information:
Name: ${name}
Email: ${email}
Subject: ${subject}
Message:
${message}
We appreciate your interest and are excited to help you. If you have any immediate questions, please feel free to reply to this email directly.
Best regards,
The Genomatics Team
This email was sent in response to your contact form submission on the Genomatics platform.
Dear Team,
A new contact form with some general enquiry/request has been submitted. Details are as follows:
Name: | ${name} |
Email: | ${email} |
Phone: | ${phone} |
Subject: | ${subject} |
Message: | ${message} |
Please follow up with the requester accordingly.
Best regards,
Genomatics System