inbox/services/presence.py
2023-10-14 09:38:12 +03:00

13 lines
387 B
Python

import json
from services.redis import redis
from validators.chat import Message
async def notify_message(message: Message, chat_id: str):
channel_name = f"chat:{chat_id}"
data = {**message, "kind": "new_message"}
try:
await redis.publish(channel_name, json.dumps(data))
except Exception as e:
print(f"Failed to publish to channel {channel_name}: {e}")