mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 03:11:12 -05:00
feat: Implement ticket system and reply button
This commit is contained in:
@@ -66,7 +66,7 @@ const handler = async (req: Request): Promise<Response> => {
|
||||
// Fetch submission
|
||||
const { data: submission, error: fetchError } = await supabase
|
||||
.from('contact_submissions')
|
||||
.select('id, email, name, subject, thread_id, response_count')
|
||||
.select('id, email, name, subject, thread_id, response_count, ticket_number')
|
||||
.eq('id', submissionId)
|
||||
.single();
|
||||
|
||||
@@ -89,8 +89,9 @@ const handler = async (req: Request): Promise<Response> => {
|
||||
}, 429, corsHeaders);
|
||||
}
|
||||
|
||||
const messageId = `<${crypto.randomUUID()}@thrillwiki.com>`;
|
||||
const finalSubject = replySubject || `Re: ${submission.subject}`;
|
||||
const ticketNumber = submission.ticket_number || 'UNKNOWN';
|
||||
const messageId = `<${ticketNumber}.${crypto.randomUUID()}@thrillwiki.com>`;
|
||||
const finalSubject = replySubject || `Re: [${ticketNumber}] ${submission.subject}`;
|
||||
|
||||
// Get previous message for threading
|
||||
const { data: previousMessages } = await supabase
|
||||
@@ -100,7 +101,13 @@ const handler = async (req: Request): Promise<Response> => {
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(1);
|
||||
|
||||
const inReplyTo = previousMessages?.[0]?.message_id || `<${submission.thread_id}@thrillwiki.com>`;
|
||||
const originalMessageId = `<${ticketNumber}.${submission.id}@thrillwiki.com>`;
|
||||
const inReplyTo = previousMessages?.[0]?.message_id || originalMessageId;
|
||||
|
||||
// Build reference chain for threading
|
||||
const referenceChain = previousMessages?.[0]?.message_id
|
||||
? [originalMessageId, previousMessages[0].message_id].join(' ')
|
||||
: originalMessageId;
|
||||
|
||||
// Send email via ForwardEmail
|
||||
const forwardEmailResponse = await fetch('https://api.forwardemail.net/v1/emails', {
|
||||
@@ -117,8 +124,9 @@ const handler = async (req: Request): Promise<Response> => {
|
||||
headers: {
|
||||
'Message-ID': messageId,
|
||||
'In-Reply-To': inReplyTo,
|
||||
'References': inReplyTo,
|
||||
'X-Thread-ID': submission.thread_id
|
||||
'References': referenceChain,
|
||||
'X-Thread-ID': submission.thread_id,
|
||||
'X-Ticket-Number': ticketNumber
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user