-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better documentation #1
Comments
+1 this. How to integrate it effectvely in django? How can I replace the default channels tutorial with channels-handlers? Thanks! |
@gabriel-gn thanks, those are great ideas. Do you need anything in particular to get started? |
Where do I create pydantic models for channels handlers in my custom channels app and where do I call them? (assuming I have a "routing.py" and "consumers.py" files) How can I send a message with what I have without needing to use |
For instance, I chose to have a single channel that each user would listen on (an inbox of sorts). Consequently, I designed the interface to be the following: class ChatConsumer(AsyncConsumerHandlerMixin, AsyncJsonWebsocketConsumer):
handler_classes = [ChatHandler]
...
async def send_message(self, message, user_ids):
# Serialize message
serialized_message = self.serialize_message(message)
# Send message to room group
for user_id in user_ids:
await self.channel_layer.group_send(
f"inbox_{user_id}",
{"type": "message.outgoing", "content": serialized_message},
)
async def message_outgoing(self, event):
"""
Sends a message to the participant
"""
# Deserialize message
message = self.deserialize_message(event["content"])
# Send message to WebSocket
await self.send_json(content=message) This can be used in the following manner from within the handler: # Send typing notification to all participants
output_message = self.serialize_message(
"chat.typing",
{"thread": message.thread, "sender": self.get_current_user().pk},
)
participants = await retrieve_thread_participants(message.thread)
await self.consumer.send_message(output_message, participants) Does that help? |
Thanks a lot! I will try those 😄 |
This project needs comprehensive documentation. Optimally, it would be stored on ReadTheDocs.
The text was updated successfully, but these errors were encountered: