feat: hand off upsell conversations to humans
This commit is contained in:
1 parent
5ad7f1bf77
commit
e8f56b42e6
4 files changed
+32
-2
No files matched your search
@@ -2,6 +2,7 @@ import type { OpenRouterClient } from '../ai/openrouter.js';
|
||||
import type { ConversationStateRepository } from '../database/repositories.js';
|
||||
import type { Logger } from '../utils/logger.js';
|
||||
import type { RateLimiter } from '../utils/rate-limiter.js';
|
||||
import { findSellerSignal } from '../reddit/api.js';
|
||||
import type { ActiveChat, ChatMessage } from './chat/types.js';
|
||||
import type { ChatService } from './chat/service.js';
|
||||
import {
|
||||
@@ -40,6 +41,8 @@ export class ConversationAutomationService {
|
||||
private readonly rateLimiter: RateLimiter,
|
||||
private readonly logger: Logger,
|
||||
private readonly dryRun = false,
|
||||
private readonly sellerKeywords: readonly string[] = [],
|
||||
private readonly sellerDomains: readonly string[] = [],
|
||||
) {}
|
||||
|
||||
async processUnreadConversations(signal?: AbortSignal): Promise<ConversationAutomationResult[]> {
|
||||
@@ -72,6 +75,17 @@ export class ConversationAutomationService {
|
||||
if (state.automation.lastIncomingKey === incomingKey) return null;
|
||||
if (state.automation.status !== 'active') return null;
|
||||
|
||||
const sellerSignal = findSellerSignal(latest.text, [...this.sellerKeywords], [...this.sellerDomains]);
|
||||
if (sellerSignal) {
|
||||
return this.finish(
|
||||
conversation,
|
||||
conversationId,
|
||||
state,
|
||||
incomingKey,
|
||||
'human-required',
|
||||
`Potential upsell detected (${sellerSignal.kind}: ${sellerSignal.value}).`,
|
||||
);
|
||||
}
|
||||
if (hasReceivedImage(messages)) {
|
||||
return this.finish(conversation, conversationId, state, incomingKey, 'image-received', 'The user shared an image.');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user