feat(mail): tag mail threads source=crm-mail (list separately from chat)
ingest() puts metadata on the interaction, not the thread, and listThreads filters THREAD metadata — so MailService now tags the thread directly after deposit (source=crm-mail). Lets the CRM list mail threads apart from Messenger chat (source=crm-messenger). 7 tests. NOTE: requires an IIOS redeploy. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { IngestService } from '../interactions/ingest.service';
|
||||
import { ActorResolver, type MessagePrincipal } from '../identity/actor.resolver';
|
||||
import { TemplateService } from '../templates/template.service';
|
||||
@@ -55,8 +57,12 @@ export class MailService {
|
||||
private readonly ingest: IngestService,
|
||||
private readonly sender: TemplatedSender,
|
||||
private readonly actors: ActorResolver,
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
/** Marks a thread as CRM mail so it lists separately from chat (Messenger uses source=crm-messenger). */
|
||||
static readonly SOURCE = 'crm-mail';
|
||||
|
||||
async postInternal(principal: MessagePrincipal, input: PostInternalInput): Promise<{ threadId: string; interactionId: string }> {
|
||||
const { content } = await this.templates.render(input.source, input.vars ?? {}, { channel: 'INTERNAL', ...(input.locale ? { locale: input.locale } : {}) });
|
||||
return this.deposit(principal, input.recipientUserId, content, input.idempotencyKey, 'PORTAL');
|
||||
@@ -103,6 +109,13 @@ export class MailService {
|
||||
await this.actors.ensureParticipant(res.threadId, senderActor.id);
|
||||
await this.actors.ensureParticipant(res.threadId, recipientActor.id);
|
||||
|
||||
// Tag the thread as CRM mail (thread metadata) so it lists separately from Messenger chat.
|
||||
// ingest() puts req.metadata on the interaction, not the thread, so we set it here directly.
|
||||
await this.prisma.iiosThread.update({
|
||||
where: { id: res.threadId },
|
||||
data: { metadata: { source: MailService.SOURCE } as Prisma.InputJsonValue },
|
||||
});
|
||||
|
||||
return { threadId: res.threadId, interactionId: res.interactionId };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user