fixed team chats

This commit is contained in:
Iyeoluwa Akinrinola
2025-05-16 18:03:15 +01:00
parent 463923278a
commit 730009ae87
21 changed files with 1655 additions and 63 deletions
+33 -1
View File
@@ -623,15 +623,47 @@ async def channel_message_webhook(request: ChannelMessageWebhook):
print("=" * 50)
# Find the chat associated with this OpenWebUI channel
print(f"Looking for chat with OpenWebUI channel ID: {request.channel_id}")
print(f"Number of chats in system: {len(chat_service.chats)}")
# Debug: Print all chats and their channel IDs
print("All chats in the system:")
for cid, chat in chat_service.chats.items():
is_team = chat.get('is_team_chat', False)
channel_id = chat.get('openwebui_channel_id', 'None')
print(f" Chat ID: {cid}, Is Team Chat: {is_team}, OpenWebUI Channel ID: {channel_id}")
chat_id = None
for cid, chat in chat_service.chats.items():
if chat.get('is_team_chat') and chat.get('openwebui_channel_id') == request.channel_id:
chat_id = cid
print(f"Found matching chat: {cid}")
break
if not chat_id:
print(f"No chat found for OpenWebUI channel {request.channel_id}")
return {"status": "error", "message": "No chat found for this channel"}
# If no chat exists for this channel, create one
print("Creating a new team chat for this channel...")
try:
new_chat_id = chat_service.create_chat(
user_id=request.user_id,
title=f"Channel Chat {request.channel_id}",
model_id=config.DEFAULT_MODEL,
is_team_chat=True
)
# Manually set the OpenWebUI channel ID for this chat
chat_service.chats[new_chat_id]['openwebui_channel_id'] = request.channel_id
chat_service._save_chats()
print(f"Created new chat with ID {new_chat_id} for channel {request.channel_id}")
# Use this new chat
chat_id = new_chat_id
except Exception as e:
print(f"Error creating new chat for channel: {str(e)}")
return {"status": "error", "message": "No chat found for this channel and failed to create one"}
# Skip messages from the AI assistant to avoid loops
if request.user_id == "ai-assistant":