mirror of
https://github.com/FranP-code/inbox-negotiator.git
synced 2025-10-13 00:42:26 +00:00
feat: Enhance conversation history retrieval and logging for negotiation responses
This commit is contained in:
@@ -544,20 +544,26 @@ async function processNegotiation(
|
||||
counterOfferContext,
|
||||
);
|
||||
|
||||
// Create conversation message for the AI-generated response
|
||||
const messageType = counterOfferContext
|
||||
? "counter_offer"
|
||||
: "negotiation_sent";
|
||||
await client.from("conversation_messages").insert({
|
||||
debt_id: record.id,
|
||||
message_type: messageType,
|
||||
direction: "outbound",
|
||||
subject: emailResult.subject,
|
||||
body: emailResult.body,
|
||||
from_email: record.metadata?.toEmail || "user@example.com",
|
||||
to_email: record.metadata?.fromEmail || record.vendor,
|
||||
message_id: `ai-generated-${Date.now()}`,
|
||||
});
|
||||
// Create conversation message only for auto-responses (counter-offers)
|
||||
// Regular negotiation generation doesn't create messages since they're not sent yet
|
||||
if (counterOfferContext) {
|
||||
await client.from("conversation_messages").insert({
|
||||
debt_id: record.id,
|
||||
message_type: "counter_offer",
|
||||
direction: "outbound",
|
||||
subject: emailResult.subject,
|
||||
body: emailResult.body,
|
||||
from_email: record.metadata?.toEmail || "user@example.com",
|
||||
to_email: record.metadata?.fromEmail || record.vendor,
|
||||
message_id: `auto-counter-${Date.now()}`,
|
||||
ai_analysis: {
|
||||
strategy: emailResult.strategy,
|
||||
confidence: emailResult.confidenceLevel,
|
||||
projectedSavings: emailResult.projectedSavings,
|
||||
isAutoGenerated: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Update debt record with AI-generated content - using provided client
|
||||
const { error: updateError } = await client
|
||||
|
||||
Reference in New Issue
Block a user