Fixed TS Errors
This commit is contained in:
@@ -11,7 +11,7 @@ export async function createConversation(
|
|||||||
channel_instance_id,
|
channel_instance_id,
|
||||||
subject,
|
subject,
|
||||||
customer_id = null,
|
customer_id = null,
|
||||||
contact_person_id = null
|
contact_person_id = null,
|
||||||
}: {
|
}: {
|
||||||
tenant_id: number
|
tenant_id: number
|
||||||
contact: { email?: string; phone?: string; display_name?: string }
|
contact: { email?: string; phone?: string; display_name?: string }
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export async function addMessage(
|
|||||||
direction = 'incoming',
|
direction = 'incoming',
|
||||||
payload,
|
payload,
|
||||||
raw_meta = null,
|
raw_meta = null,
|
||||||
|
external_message_id = null,
|
||||||
}: {
|
}: {
|
||||||
tenant_id: number
|
tenant_id: number
|
||||||
conversation_id: string
|
conversation_id: string
|
||||||
@@ -17,6 +18,7 @@ export async function addMessage(
|
|||||||
direction?: 'incoming' | 'outgoing' | 'internal' | 'system'
|
direction?: 'incoming' | 'outgoing' | 'internal' | 'system'
|
||||||
payload: any
|
payload: any
|
||||||
raw_meta?: any
|
raw_meta?: any
|
||||||
|
external_message_id?: string
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (!payload?.text) throw new Error('Message payload requires text content')
|
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,
|
key: apiKey,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// @ts-ignore
|
||||||
server.log.error("[M2M Auth] Fehler beim Prüfen des API-Keys:", err);
|
server.log.error("[M2M Auth] Fehler beim Prüfen des API-Keys:", err);
|
||||||
return reply.status(500).send({ error: "Internal Server Error" });
|
return reply.status(500).send({ error: "Internal Server Error" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,15 @@ const helpdeskInboundEmailRoutes: FastifyPluginAsync = async (server) => {
|
|||||||
text,
|
text,
|
||||||
message_id,
|
message_id,
|
||||||
in_reply_to,
|
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) {
|
if (!tenant_id || !from?.address || !text) {
|
||||||
return res.status(400).send({ error: 'Invalid payload' })
|
return res.status(400).send({ error: 'Invalid payload' })
|
||||||
@@ -42,7 +50,7 @@ const helpdeskInboundEmailRoutes: FastifyPluginAsync = async (server) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 3️⃣ Konversation anhand In-Reply-To suchen
|
// 3️⃣ Konversation anhand In-Reply-To suchen
|
||||||
let conversationId: number | null = null
|
let conversationId: string | null = null
|
||||||
if (in_reply_to) {
|
if (in_reply_to) {
|
||||||
const { data: msg } = await server.supabase
|
const { data: msg } = await server.supabase
|
||||||
.from('helpdesk_messages')
|
.from('helpdesk_messages')
|
||||||
@@ -55,16 +63,13 @@ const helpdeskInboundEmailRoutes: FastifyPluginAsync = async (server) => {
|
|||||||
// 4️⃣ Neue Konversation anlegen falls keine existiert
|
// 4️⃣ Neue Konversation anlegen falls keine existiert
|
||||||
let conversation
|
let conversation
|
||||||
if (!conversationId) {
|
if (!conversationId) {
|
||||||
const { usedNumber } = await useNextNumberRangeNumber(server, tenant_id, 'tickets')
|
|
||||||
conversation = await createConversation(server, {
|
conversation = await createConversation(server, {
|
||||||
tenant_id,
|
tenant_id,
|
||||||
contact,
|
contact,
|
||||||
channel_instance_id: channel_id,
|
channel_instance_id: channel_id,
|
||||||
status: 'open',
|
|
||||||
subject: subject || '(kein Betreff)',
|
subject: subject || '(kein Betreff)',
|
||||||
customer_id: customer,
|
customer_id: customer,
|
||||||
contact_person_id: contactPerson,
|
contact_person_id: contactPerson,
|
||||||
ticket_number: usedNumber,
|
|
||||||
})
|
})
|
||||||
conversationId = conversation.id
|
conversationId = conversation.id
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -71,8 +71,14 @@ async function findCustomerOrContactByEmailOrDomain(server,fromMail, tenantId) {
|
|||||||
const helpdeskInboundRoutes: FastifyPluginAsync = async (server) => {
|
const helpdeskInboundRoutes: FastifyPluginAsync = async (server) => {
|
||||||
// Öffentliche POST-Route
|
// Öffentliche POST-Route
|
||||||
server.post('/helpdesk/inbound/:public_token', async (req, res) => {
|
server.post('/helpdesk/inbound/:public_token', async (req, res) => {
|
||||||
const { public_token } = req.params
|
const { public_token } = req.params as { public_token: string }
|
||||||
const { email, phone, display_name, subject, message } = req.body
|
const { email, phone, display_name, subject, message } = req.body as {
|
||||||
|
email: string,
|
||||||
|
phone: string,
|
||||||
|
display_name: string
|
||||||
|
subject: string
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return res.status(400).send({ error: 'Message content required' })
|
return res.status(400).send({ error: 'Message content required' })
|
||||||
|
|||||||
Reference in New Issue
Block a user