Django - Receive Webhooks from WhatsApp Cloud Api

I'm trying to create a chat application with the WhatsApp Cloud API and I'm stuck on how to handle webhooks.

Should I do it with websockets or is there another way to do it?

I already tried with django-channels but I don't know how to receive the webhooks.

If django-channels is the best option, could you tell me how I can receive the webhooks or point me to a tutorial.

Currently I already have the sockets implemented and they connect without problems

from channels.generic.websocket import JsonWebsocketConsumer

class ChatConsumer(JsonWebsocketConsumer):
    """
    This consumer is used to show user's online status,
    and send notifications.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(args, kwargs)
        self.room_name = None

    def connect(self):
        print("Connected!")
        self.room_name = "home"
        self.accept()
        self.send_json(
            {
                "type": "welcome_message",
                "message": "Hey there! You've successfully connected!",
            }
        )

    def disconnect(self, code):
        print("Disconnected!")
        return super().disconnect(code)

    def receive_json(self, content, **kwargs):
        print(content)
        return super().receive_json(content, **kwargs)

Back to Top