Replies: 3 comments 2 replies
-
I have not looked at the Instagram websocket, but look this https://github.com/Nerixyz/instagram_mqtt and https://github.com/Sovetnikov/fbns_mqtt |
Beta Was this translation helpful? Give feedback.
2 replies
-
any update on this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Negative |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone, I recently started researching Instagram Chats API for this project. I went onto inspecting the requests on the web and realised that although the contents on Inbox are loaded via. an endpoint, if we want to actually make sending messages, receiving messages, listen for "Typing..." and listen for new messages work, we are required to reverse their WebSocket endpoint (wss://edge-chat.instagram.com/chat). I had no prior experience in reversing WebSocket-based requests so I'd need some inputs from you guys. This is what I have come up with so far.
I tried to connect by sending all the data that was sent previously during my testing. The "messages" List contains all those data. I never received anything back from the server. During my testing on the browser, I have seen 18 sent via. this socket channel (which I am sending) and 15 data were received in response (which I don't get back) after which it's supposed to be connected but with my script, it simply drops the connection.
`
import websocket
import base64
import threading
import time
def convert_base64(base64_str):
return base64.b64decode(base64_str)
def on_message(wsapp, message):
print(">> MESSAGE RECEIVED <<")
print(message)
messages = [
List of all "send" messages in Base64 encoding
]
websocket.enableTrace(True)
wsapp = websocket.WebSocketApp(
"wss://edge-chat.instagram.com/chat",
on_message=on_message,
header={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
},
)
thread = threading.Thread(
target=wsapp.run_forever,
kwargs={
"origin": "https://www.instagram.com",
"host": "edge-chat.instagram.com",
},
)
thread.start()
timeout = 5
while not wsapp.sock.connected and timeout:
time.sleep(1)
timeout -= 1
if timeout == 0:
print("Connection to server timed out")
quit()
sent = False
while wsapp.sock.connected:
if sent == False:
wsapp.send(convert_base64(messages[0]))
wsapp.send(convert_base64(messages[1]))
wsapp.send(convert_base64(messages[2]))
wsapp.send(convert_base64(messages[3]))
wsapp.send(convert_base64(messages[4]))
wsapp.send(convert_base64(messages[5]))
wsapp.send(convert_base64(messages[6]))
wsapp.send(convert_base64(messages[7]))
wsapp.send(convert_base64(messages[8]))
wsapp.send(convert_base64(messages[9]))
wsapp.send(convert_base64(messages[10]))
wsapp.send(convert_base64(messages[11]))
wsapp.send(convert_base64(messages[12]))
wsapp.send(convert_base64(messages[13]))
wsapp.send(convert_base64(messages[14]))
wsapp.send(convert_base64(messages[15]))
wsapp.send(convert_base64(messages[16]))
wsapp.send(convert_base64(messages[17]))
`
If you have any info on how to go about doing this then please let me know!
UPDATE 01
I went to debug further and it seems like using the same "data" won't get me connected to the socket connection as a couple of values like "s", "d" kept changing... I'm assuming that's some sort of auth system in place so I further dug into the source to see how are they exactly generated.
This file was the most interesting so far:
https://www.instagram.com/static/bundles/es6/ConsumerLibCommons.js/7bed7be79f06.js:formatted
It has this "getAccountBadgeData" method that seems to be generating "s" by hitting some endpoint "/api/v1/notifications/badge/".
This is all I got for now if you can help with anything or suggest then let's discuss!
Beta Was this translation helpful? Give feedback.
All reactions