Fixed TS Errors
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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" });
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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' })
|
||||
|
||||
Reference in New Issue
Block a user