diff --git a/src/modules/helpdesk/helpdesk.conversation.service.ts b/src/modules/helpdesk/helpdesk.conversation.service.ts index 15efe7b..b7edc2b 100644 --- a/src/modules/helpdesk/helpdesk.conversation.service.ts +++ b/src/modules/helpdesk/helpdesk.conversation.service.ts @@ -11,7 +11,7 @@ export async function createConversation( channel_instance_id, subject, customer_id = null, - contact_person_id = null + contact_person_id = null, }: { tenant_id: number contact: { email?: string; phone?: string; display_name?: string } diff --git a/src/modules/helpdesk/helpdesk.message.service.ts b/src/modules/helpdesk/helpdesk.message.service.ts index 71f0c4c..2d942eb 100644 --- a/src/modules/helpdesk/helpdesk.message.service.ts +++ b/src/modules/helpdesk/helpdesk.message.service.ts @@ -10,6 +10,7 @@ export async function addMessage( direction = 'incoming', payload, raw_meta = null, + external_message_id = null, }: { tenant_id: number conversation_id: string @@ -17,6 +18,7 @@ export async function addMessage( direction?: 'incoming' | 'outgoing' | 'internal' | 'system' payload: any raw_meta?: any + external_message_id?: string } ) { if (!payload?.text) throw new Error('Message payload requires text content') diff --git a/src/plugins/auth.m2m.ts b/src/plugins/auth.m2m.ts index 2523b23..58e6c3c 100644 --- a/src/plugins/auth.m2m.ts +++ b/src/plugins/auth.m2m.ts @@ -33,6 +33,7 @@ export default fp(async (server: FastifyInstance, opts: { allowedPrefix?: string key: apiKey, }; } catch (err) { + // @ts-ignore server.log.error("[M2M Auth] Fehler beim Prüfen des API-Keys:", err); return reply.status(500).send({ error: "Internal Server Error" }); } diff --git a/src/routes/helpdesk.inbound.email.ts b/src/routes/helpdesk.inbound.email.ts index 7c0b9fb..5b24a4d 100644 --- a/src/routes/helpdesk.inbound.email.ts +++ b/src/routes/helpdesk.inbound.email.ts @@ -21,7 +21,15 @@ const helpdeskInboundEmailRoutes: FastifyPluginAsync = async (server) => { text, message_id, in_reply_to, - } = req.body + } = req.body as { + tenant_id: number + channel_id: string + from: {address: string, name: string} + subject: string + text: string + message_id: string + in_reply_to: string + } if (!tenant_id || !from?.address || !text) { return res.status(400).send({ error: 'Invalid payload' }) @@ -42,7 +50,7 @@ const helpdeskInboundEmailRoutes: FastifyPluginAsync = async (server) => { }) // 3️⃣ Konversation anhand In-Reply-To suchen - let conversationId: number | null = null + let conversationId: string | null = null if (in_reply_to) { const { data: msg } = await server.supabase .from('helpdesk_messages') @@ -55,16 +63,13 @@ const helpdeskInboundEmailRoutes: FastifyPluginAsync = async (server) => { // 4️⃣ Neue Konversation anlegen falls keine existiert let conversation if (!conversationId) { - const { usedNumber } = await useNextNumberRangeNumber(server, tenant_id, 'tickets') conversation = await createConversation(server, { tenant_id, contact, channel_instance_id: channel_id, - status: 'open', subject: subject || '(kein Betreff)', customer_id: customer, contact_person_id: contactPerson, - ticket_number: usedNumber, }) conversationId = conversation.id } else { diff --git a/src/routes/helpdesk.inbound.ts b/src/routes/helpdesk.inbound.ts index 96752f7..49e8ec7 100644 --- a/src/routes/helpdesk.inbound.ts +++ b/src/routes/helpdesk.inbound.ts @@ -71,8 +71,14 @@ async function findCustomerOrContactByEmailOrDomain(server,fromMail, tenantId) { const helpdeskInboundRoutes: FastifyPluginAsync = async (server) => { // Öffentliche POST-Route server.post('/helpdesk/inbound/:public_token', async (req, res) => { - const { public_token } = req.params - const { email, phone, display_name, subject, message } = req.body + const { public_token } = req.params as { public_token: string } + const { email, phone, display_name, subject, message } = req.body as { + email: string, + phone: string, + display_name: string + subject: string + message: string + } if (!message) { return res.status(400).send({ error: 'Message content required' })