Get websocket connection to WhatsApp using Python or JavaScript?

Viewed 2650

I copy the websocket request from the chrome network tab and try to use it as fetch and clearly is not working because fetch only support HTTP(S).

Is there a way I can connect to WhatsApp websocket connection by either Python or JavaScript?

3 Answers

I don't know If this will help, you can always use WebSocket in node.js . Similarly, socketio module is available in python.

I tried this in my local machine but the socket server throwed an unexpected Forbiden 403 error.

Anyway, this is the example:

const WebSocket = require('ws')
var socket = new WebSocket("wss://web.whatsapp.com/ws")

socket.onopen = (e)=>console.log("connected")

socket.onmessage = (e)=>console.log("msg",e)

socket.onerror = (e)=>console.log("error",e)

WebSocket Github repo link

You need to use the flask-socketio and for javascript socket library. The steps are to connect and then send data to the function mentioned. You need to read the documentation as it is pretty simple.

You can get connect to socket in chrome using

let socket = new WebSocket("wss://web.whatsapp.com/ws");


socket.onopen = (e)=>console.log("connected")

socket.onmessage = (e)=>console.log("msg",e)

socket.onerror = (e)=>console.log("error",e)

but you can't listern messages.

Related