API Examples
Connecting IM Server
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
websocket = await websockets.connect(uri, ssl = ssl_context)Authentication
Obtain Access Token
Authenticate with IM Service using the Access Token
auth = str(user) + "@" + domain + ":" + access_token
secret = base64.b64encode(auth.encode())
uuid4 = uuid.uuid4()
message = {
"login": {
"id": str(uuid4),
"scheme": "access_token",
"secret": secret.decode()
}
}
await websocket.send(json.dumps(message))
response = await websocket.recv()
logger.debug("client_auth response : " + response)
ret = json.loads(response)
if ret["ctrl"]["code"] == 200 :
return ret["ctrl"]["params"]["user"]
else :
logger.error("client_auth [" + str(user) + "] retcode not 200 response : " + response)
return ""Subscribe to P2P Topic
Sending Message to P2P Topic
Get the Topics I Have Subscribed To
Query Topic Details
Obtain Historical Messages
Creating a Group Chat
Join a Group
Sending a Message to a Group
Leave From a Group
Remove a Member from the Group
Delete a Group
Update Group Information
Transfer Group Ownership
Uploading a File to the IM Server
Download the Chat File
Last updated
Was this helpful?