Filter detected sellers from conversations

This commit is contained in:
jjbrunton committed 2026-08-09 14:38:03 +01:00
1 parent d5ebdec076
commit 92c54feedc
14 files changed
+97 -7

No files matched your search

+1
View File
@@ -26,6 +26,7 @@ export interface ActiveChat {
messages?: ChatMessage[];
originMessage?: string;
hasReceivedImages?: boolean;
sellerDetected?: boolean;
}
/**
+1
View File
@@ -126,6 +126,7 @@ export class ConversationAutomationService {
const sellerSignal = findSellerSignal(latest.text, [...this.sellerKeywords], [...this.sellerDomains]);
if (sellerSignal) {
state.sellerDetected = true;
return this.finish(
conversation,
conversationId,
+7
View File
@@ -28,6 +28,8 @@ export interface ConversationPersona {
export interface ConversationState {
persona: ConversationPersona;
boundaries: string[];
/** Durable marker set when configured seller or upsell signals are detected. */
sellerDetected: boolean;
/** Kept for backwards compatibility with state written before automation. */
askedForMedia: boolean;
topics: string[];
@@ -125,6 +127,7 @@ export function buildConversationState(messages: ConversationMessage[]): Convers
return {
persona,
boundaries,
sellerDetected: false,
askedForMedia: /\b(send|show|share)\b[^.\n]{0,40}\b(pic|pics|photo|photos|selfie|selfies|video|videos|nudes?)\b/i.test(ownText),
topics,
automation: createConversationAutomationState(),
@@ -178,6 +181,7 @@ export function mergeConversationState(
: saved.persona.relationshipStatus,
},
boundaries: [...new Set([...saved.boundaries, ...observed.boundaries])],
sellerDetected: saved.sellerDetected || observed.sellerDetected,
askedForMedia: saved.askedForMedia || observed.askedForMedia,
topics: [...new Set([...saved.topics, ...observed.topics])],
automation: saved.automation,
@@ -243,6 +247,9 @@ export function parseConversationState(value: string | null | undefined): Conver
: 'unspecified',
},
boundaries: parsed.boundaries.filter((value): value is string => typeof value === 'string'),
sellerDetected: typeof parsed.sellerDetected === 'boolean'
? parsed.sellerDetected
: automation.handoffReason?.startsWith('Potential upsell detected') === true,
askedForMedia: parsed.askedForMedia,
topics: parsed.topics.filter((value): value is string => typeof value === 'string'),
automation,