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. Use gzip to compress message data.

  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
func ConnectMixinBlaze(token string) (*websocket.Conn, error) {
header := make(http.Header)
header.Add("Authorization", "Bearer "+token)
u := url.URL{Scheme: "wss", Host: "blaze.mixin.one", Path: "/"}
dialer := &websocket.Dialer{
Subprotocols: []string{"Mixin-Blaze-1"},
}
conn, _, err := dialer.Dial(u.String(), header)
if err != nil {
return nil, err
}
return conn, nil
}

Python code snippet. example can be found here

def on_open(ws):
def run(*args):
print("ws open")
Message = {"id":str(uuid.uuid1()), "action":"LIST_PENDING_MESSAGES"}
Message_instring = json.dumps(Message)
fgz = StringIO()
gzip_obj = gzip.GzipFile(mode='wb', fileobj=fgz)
gzip_obj.write(Message_instring)
gzip_obj.close()
ws.send(fgz.getvalue(), opcode=websocket.ABNF.OPCODE_BINARY)
while True:
time.sleep(1)
thread.start_new_thread(run, ())
if __name__ == "__main__":
while True:
encoded = mixin_api_robot.genGETJwtToken('/', "", str(uuid.uuid4()))
#websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://blaze.mixin.one/",
on_message = on_message,
on_error = on_error,
on_close = on_close,
header = ["Authorization:Bearer " + encoded],
subprotocols = ["Mixin-Blaze-1"],
on_data = on_data)
ws.on_open = on_open
ws.run_forever()

Then analyze message sent by server. Follow the guide.