Horilla CRM uses Django Channels and WebSockets to push notifications to connected browsers. Automations and system events can be delivered via notification, email, or both.
This post is Part 10 of 28 in the Horilla CRM Technical Blog series.
What is real-time notifications in Horilla CRM?
Real-time notifications in Horilla CRM enable you to:
- NotificationConsumer per authenticated user
- Redis channel layer in production
- ASGI deployment with Uvicorn workers
- HTMX loads detail when user clicks a toast
WebSocket routing
# horilla/contrib/notifications/routing.py
from horilla.urls import re_path
from . import consumers
websocket_urlpatterns = [
re_path(r"ws/notifications/$", consumers.NotificationConsumer.as_asgi()),
]
ASGI deployment (Uvicorn + Gunicorn) is required in production — covered in Part 28.
NotificationConsumer
# horilla/contrib/notifications/consumers.py
class NotificationConsumer(AsyncWebsocketConsumer):
async def connect(self):
user = self.scope["user"]
if user.is_anonymous:
await self.close()
return
self.group_name = f"notifications_{user.id}"
await self.channel_layer.group_add(self.group_name, self.channel_name)
await self.accept()
async def notification_message(self, event):
await self.send(text_data=json.dumps(event["data"]))
Each authenticated user joins notifications_{user_id}. Server-side code calls create_notification(), which publishes to the group.
Creating notifications
# horilla/contrib/notifications/methods.py (usage)
from horilla.contrib.notifications.methods import create_notification
create_notification(
user=recipient,
message="Lead assigned to you",
redirect=lead.get_detail_url(),
)
Automations (Part 7) can deliver via “notification” or “both” (mail + push).
HTMX + WebSockets together
| Layer | Role |
|---|---|
| HTMX | Page fragments, forms, lists |
| WebSockets | Badge counts, toasts, live alerts |
Clicking a notification typically triggers an HTMX hx-get into #mainContent — hybrid architecture without a SPA build step.
Infrastructure
- Redis as channel layer backend (same Redis as Celery)
- AUTH middleware on WebSocket scope — anonymous connections rejected
Benefits of Real-Time Notifications in Horilla CRM
- Instant alerts for assignments and workflow events
- No polling — efficient for sales teams
- Complements server-rendered HTMX UI
Real-time notifications keep teams responsive. Deploy with ASGI + Redis and wire automations to the notification channel.
Continue the series
- Previous: Part 9 — A Complete Guide to REST APIs in Horilla CRM Using Django REST Framework
- Next: Part 11 — A Complete Guide to KPI Widgets and ECharts in Horilla CRM
More posts are at Horilla Blogs; share feedback on GitHub.