feat(chat): add contact inbox sources with per-user hide filters
This commit is contained in:
@@ -242,7 +242,7 @@ async function upsertThread(input: {
|
||||
|
||||
if (existing) {
|
||||
const data: Prisma.OmniThreadUpdateInput = {
|
||||
contactId: input.contactId,
|
||||
contact: { connect: { id: input.contactId } },
|
||||
};
|
||||
if (input.title && !existing.title) {
|
||||
data.title = input.title;
|
||||
@@ -283,12 +283,42 @@ async function upsertThread(input: {
|
||||
|
||||
await prisma.omniThread.update({
|
||||
where: { id: concurrentThread.id },
|
||||
data: { contactId: input.contactId },
|
||||
data: { contact: { connect: { id: input.contactId } } },
|
||||
});
|
||||
return concurrentThread;
|
||||
}
|
||||
}
|
||||
|
||||
async function upsertContactInbox(input: {
|
||||
teamId: string;
|
||||
contactId: string;
|
||||
channel: "TELEGRAM";
|
||||
sourceExternalId: string;
|
||||
title: string | null;
|
||||
}) {
|
||||
return prisma.contactInbox.upsert({
|
||||
where: {
|
||||
teamId_channel_sourceExternalId: {
|
||||
teamId: input.teamId,
|
||||
channel: input.channel,
|
||||
sourceExternalId: input.sourceExternalId,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
teamId: input.teamId,
|
||||
contactId: input.contactId,
|
||||
channel: input.channel,
|
||||
sourceExternalId: input.sourceExternalId,
|
||||
title: input.title,
|
||||
},
|
||||
update: {
|
||||
contactId: input.contactId,
|
||||
...(input.title ? { title: input.title } : {}),
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
}
|
||||
|
||||
async function ingestInbound(env: OmniInboundEnvelopeV1) {
|
||||
if (env.channel !== "TELEGRAM") return;
|
||||
|
||||
@@ -325,6 +355,13 @@ async function ingestInbound(env: OmniInboundEnvelopeV1) {
|
||||
businessConnectionId,
|
||||
title: asString(n.chatTitle),
|
||||
});
|
||||
const inbox = await upsertContactInbox({
|
||||
teamId,
|
||||
contactId,
|
||||
channel: "TELEGRAM",
|
||||
sourceExternalId: externalChatId,
|
||||
title: asString(n.chatTitle),
|
||||
});
|
||||
const rawEnvelope = {
|
||||
version: env.version,
|
||||
source: "omni_chat.receiver",
|
||||
@@ -337,7 +374,7 @@ async function ingestInbound(env: OmniInboundEnvelopeV1) {
|
||||
normalized: {
|
||||
text,
|
||||
threadExternalId: externalChatId,
|
||||
contactExternalId,
|
||||
contactExternalId: externalContactId,
|
||||
businessConnectionId,
|
||||
},
|
||||
payloadNormalized: n,
|
||||
@@ -393,6 +430,7 @@ async function ingestInbound(env: OmniInboundEnvelopeV1) {
|
||||
await prisma.contactMessage.create({
|
||||
data: {
|
||||
contactId,
|
||||
contactInboxId: inbox.id,
|
||||
kind: "MESSAGE",
|
||||
direction,
|
||||
channel: "TELEGRAM",
|
||||
|
||||
Reference in New Issue
Block a user