56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { createLead, type LeadRow } from "./leadService.server";
|
|
|
|
type BaseIngestionInput = {
|
|
tenantId: string;
|
|
userId?: string | null;
|
|
sourceId?: string | null;
|
|
zustaendigerUserId?: string | null;
|
|
vorname?: string | null;
|
|
nachname?: string | null;
|
|
email?: string | null;
|
|
telefon?: string | null;
|
|
message?: string | null;
|
|
submitterIpHash?: string | null;
|
|
isDemoData?: boolean;
|
|
};
|
|
|
|
export async function ingestFormLead(input: BaseIngestionInput & { formId: string; submissionId: string; values: Record<string, unknown> }): Promise<LeadRow> {
|
|
return createLead({
|
|
...input,
|
|
quelle: "form",
|
|
quelleDetail: { formId: input.formId, submissionId: input.submissionId },
|
|
sourceOrigin: `form:${input.formId}`,
|
|
rohdaten: { values: input.values, submissionId: input.submissionId },
|
|
});
|
|
}
|
|
|
|
export async function ingestEmailLead(input: BaseIngestionInput & { messageId: string; mailbox?: string | null; subject?: string | null }): Promise<LeadRow> {
|
|
return createLead({
|
|
...input,
|
|
quelle: "email",
|
|
quelleDetail: { messageId: input.messageId, mailbox: input.mailbox ?? null },
|
|
sourceOrigin: input.mailbox ? `email:${input.mailbox}` : "email",
|
|
rohdaten: { messageId: input.messageId, subject: input.subject ?? null },
|
|
});
|
|
}
|
|
|
|
export async function ingestAirCallLead(input: BaseIngestionInput & { callId: string; direction?: string | null; answeredAt?: string | null }): Promise<LeadRow> {
|
|
return createLead({
|
|
...input,
|
|
quelle: "aircall",
|
|
quelleDetail: { callId: input.callId, direction: input.direction ?? null },
|
|
sourceOrigin: "aircall",
|
|
rohdaten: { callId: input.callId, answeredAt: input.answeredAt ?? null },
|
|
});
|
|
}
|
|
|
|
export async function ingestCustomLead(input: BaseIngestionInput & { sourceKey: string; payload: Record<string, unknown> }): Promise<LeadRow> {
|
|
return createLead({
|
|
...input,
|
|
quelle: "custom",
|
|
quelleDetail: { sourceKey: input.sourceKey },
|
|
sourceOrigin: `custom:${input.sourceKey}`,
|
|
rohdaten: input.payload,
|
|
});
|
|
}
|