File size: 830 Bytes
f71fc0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import socketio
import time

TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsInVzZXJuYW1lIjoidGVzdHVzZXIiLCJpYXQiOjE3ODMxODU0OTEsImV4cCI6MTc4NTc3NzQ5MX0.02ooFo1eRDfz0Wlsz9kzVFVkDIMLbCw_eZ8YrOw3P9g"
BASE_URL = "https://Brighton233j-Messenger-back-database.hf.space"

sio = socketio.Client()

@sio.event
def connect():
    print("Connected! Sending message to JOY...")
    sio.emit("send_message", {
        "token": TOKEN,
        "recipient_id": 0,
        "content": "Hey JOY, are you working?"
    })

@sio.on("new_message")
def on_message(data):
    print(f"[msg] sender_id={data['sender_id']}: {data['content']}")

@sio.event
def connect_error(data):
    print("Connection failed:", data)

sio.connect(f"{BASE_URL}?token={TOKEN}", socketio_path="/socket.io", transports=["websocket"])
time.sleep(6)
sio.disconnect()