Receive asset or message notification
Developer can create a websocket client and connect to mixin server to receive message from messenger user. Follow the guide.
  1. 1.
    Use gzip to compress message data.
  2. 2.
    Must send LIST_PENDING_MESSAGES to receive pending messages.
Full example in go lang
Full example in python
Full example in NodeJS
Go lang code snippet
Go_lang_setup_websocket
1
func ConnectMixinBlaze(token string) (*websocket.Conn, error) {
2
header := make(http.Header)
3
header.Add("Authorization", "Bearer "+token)
4
u := url.URL{Scheme: "wss", Host: "blaze.mixin.one", Path: "/"}
5
dialer := &websocket.Dialer{
6
Subprotocols: []string{"Mixin-Blaze-1"},
7
}
8
conn, _, err := dialer.Dial(u.String(), header)
9
if err != nil {
10
return nil, err
11
}
12
return conn, nil
13
}
Copied!
Python code snippet. example can be found here
1
def on_open(ws):
2
def run(*args):
3
print("ws open")
4
Message = {"id":str(uuid.uuid1()), "action":"LIST_PENDING_MESSAGES"}
5
Message_instring = json.dumps(Message)
6
fgz = StringIO()
7
gzip_obj = gzip.GzipFile(mode='wb', fileobj=fgz)
8
gzip_obj.write(Message_instring)
9
gzip_obj.close()
10
ws.send(fgz.getvalue(), opcode=websocket.ABNF.OPCODE_BINARY)
11
while True:
12
time.sleep(1)
13
thread.start_new_thread(run, ())
14
15
if __name__ == "__main__":
16
while True:
17
encoded = mixin_api_robot.genGETJwtToken('/', "", str(uuid.uuid4()))
18
#websocket.enableTrace(True)
19
ws = websocket.WebSocketApp("wss://blaze.mixin.one/",
20
on_message = on_message,
21
on_error = on_error,
22
on_close = on_close,
23
header = ["Authorization:Bearer " + encoded],
24
subprotocols = ["Mixin-Blaze-1"],
25
on_data = on_data)
26
ws.on_open = on_open
27
ws.run_forever()
Copied!
Then analyze message sent by server. Follow the guide.
Copy link