2023-10-04 20:14:06 +03:00
|
|
|
import json
|
2023-10-14 15:59:43 +03:00
|
|
|
|
2023-10-14 17:55:51 +03:00
|
|
|
from services.rediscache import redis
|
|
|
|
from validators.chat import Message
|
2023-10-04 20:14:06 +03:00
|
|
|
|
|
|
|
|
2023-10-14 09:38:12 +03:00
|
|
|
async def notify_message(message: Message, chat_id: str):
|
2023-10-04 20:14:06 +03:00
|
|
|
channel_name = f"chat:{chat_id}"
|
2023-10-16 17:07:01 +03:00
|
|
|
data = {"payload": message, "kind": "new_message"}
|
2023-10-04 20:14:06 +03:00
|
|
|
try:
|
2023-10-05 00:20:43 +03:00
|
|
|
await redis.publish(channel_name, json.dumps(data))
|
2023-10-17 13:59:43 +03:00
|
|
|
print(f"[services.presence] notification was sent successfully {data}")
|
2023-10-04 20:14:06 +03:00
|
|
|
except Exception as e:
|
|
|
|
print(f"Failed to publish to channel {channel_name}: {e}")
|