Add channel-scoped conversations for iMessage, WhatsApp, and email

Revert get_conversation_for_user to use Conversation.get() with
MultipleObjectsReturned fallback. Add channel field to Conversation
model and get_conversation_for_channel helper so each messaging
channel gets its own isolated conversation per user.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 19:39:39 -04:00
parent a693874662
commit 3ba93c55f4
5 changed files with 45 additions and 21 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ from quart import Blueprint, request, jsonify
from blueprints.users.models import User
from blueprints.conversation.logic import (
get_conversation_for_user,
get_conversation_for_channel,
add_message_to_conversation,
)
from blueprints.conversation.agents import main_agent
@@ -178,7 +178,7 @@ async def webhook():
# Get or create conversation
try:
conversation = await get_conversation_for_user(user=user)
conversation = await get_conversation_for_channel(user=user, channel="imessage")
await conversation.fetch_related("messages")
except Exception as e:
logger.error(f"Failed to get conversation for user {user.username}: {e}")