2023-10-04 17:14:06 +00:00
|
|
|
import json
|
2023-10-04 21:28:06 +00:00
|
|
|
from services.redis import redis
|
2023-10-14 11:52:04 +00:00
|
|
|
from validators.inbox import Message
|
2023-10-04 17:14:06 +00:00
|
|
|
|
|
|
|
|
2023-10-14 06:38:12 +00:00
|
|
|
async def notify_message(message: Message, chat_id: str):
|
2023-10-04 17:14:06 +00:00
|
|
|
channel_name = f"chat:{chat_id}"
|
|
|
|
data = {**message, "kind": "new_message"}
|
|
|
|
try:
|
2023-10-04 21:20:43 +00:00
|
|
|
await redis.publish(channel_name, json.dumps(data))
|
2023-10-04 17:14:06 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(f"Failed to publish to channel {channel_name}: {e}")
|