inbox/services/presence.py
Untone 7a561603ed
All checks were successful
deploy / deploy (push) Successful in 1m12s
debug-notify
2023-10-17 13:59:43 +03:00

15 lines
482 B
Python

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