How to send a message with WebSocket?

Viewed 334

I've my Firefox Network tab opened in DevTools and I want to send a message through WhatsApp where it uses WebSockets to communicate. Here's what it looks like when a message is sent:

Whatsapp on devtools

Now, I want to send a Web Socket message via Python but I can't find a way. I googled it but can't find a proper solution on how to achieve this. I don't know exactly what parameters to provide in to send a message.

Here's my code so far:

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0',
    'Accept': '*/*',
    'Accept-Language': 'en-US,en;q=0.5',
    'Sec-WebSocket-Version': '13',
    'Origin': 'https://web.whatsapp.com',
    'Sec-WebSocket-Extensions': 'permessage-deflate',
    'Sec-WebSocket-Key': 'yVoOx/6Sn1wyiv9R3OopPQ==',
    'Connection': 'keep-alive, Upgrade',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'Upgrade': 'websocket',
    'TE': 'Trailers',
}

response = requests.get("http://wss://web.whatsapp.com/ws", headers=headers)
0 Answers
Related