WebSocket Subscriptions

Use WebSocket subscription to get real-time data from Orangepill

Listen for events on your Realm so your integration can automatically trigger reactions. Orangepill uses Websocket to notify your application when an event occures in your Realm. WebSockets are particularly useful for asynchronous events like when a new account is created, new transaction is processed or when incoming deposits are receieved.

Events

EventDescription

user.created

New user is successfully created.

user.updated

User is updated.

user.deleted

User is deleted. All related content is cascade deleted: identities, virtual currencies, accounts, transactions, deposits, withdrawals.

identity.created

New identity is successfully created.

identity.updated

Identity is updated.

identity.deleted

Identity is deleted.

persons.sync.started*

Two-way synchronization of persons started.

persons.sync.done*

Two-way synchronization succesfully finished.

person.created*

Person profile is created.

person.updated*

Person profile is updated.

person.deleted*

Person profile is deleted.

person.assigned*

Person is assigned to Identity.

person.unassigned*

Person is unassigned from Identity.

company.created*

Company profile is created.

company.updated*

Company profile is updated.

company.deleted*

Company profile is deleted.

CHANNEL.message.sent*

Message is sent to CHANNEL. CHANNEL is sms, whatsapp, html and any other enabled.

CHANNEL.message.failed*

Message failed to CHANNEL. CHANNEL is sms, whatsapp, html and any other enabled.

account.creating

New account is being created.

account.created

Account is successfully created.

account.failed

Account creation has failed.

account.updated

Account has been updated.

account.incoming

Incoming balance.

account.outgoing

Outgoing balance.

transaction.processing

New transaction is created and being processed.

transaction.updated

Transaction is updated.

transaction.done

Transaction is successfully processed.

transaction.failed

Transaction processing failed.

deposit.pending

Incoming deposit detected.

deposit.received

Incoming deposit received.

deposit.processing

Deposit is stored and processing.

deposit.gas

Gas is withdrawn for ERC20, BEP20, TRC20 deposit processing.

deposit.processed

Deposit is successfully processed.

deposit.failed

Deposit processing failed.

withdrawal.creating

New withdrawal is created and being processed.

withdrawal.processed

Withdrawal is successfully processed.

withdrawal.failed

Withdrawal processing failed.

currency.created

Virtual currency is successfully created.

currency.failed

Virtual currency failed creating.

currency.issued

New Virtual currency supply issued.

currency.destroyed

Virtual currency supply destroyed.

alias.created

Alias successfully created.

alias.updated

Alias successfully updated.

alias.deleted

Alias successfully deleted.

apps.forward.done

Transaction was successfully forwarded.

apps.forward.failed

Transaction forwarding failed.

apps.payment.pending

Apps.Payment is created and pending.

apps.payment.status

Apps.Payment status change.

apps.payment.processing

Apps.Payment is being processed.

apps.payment.done

Apps.Payment is successfully processed.

apps.payment.failed

Apps.Payment processing failed.

apps.deposit.pending

Apps.Deposit is created and pending.

apps.deposit.processing

Apps.Deposit is being processed.

apps.deposit.done

Apps.Deposit is succesfully processed.

apps.deposit.failed

Apps.Deposit processing failed.

Events marked with * supported with Infobip extension enabled.

Event data

Each notification will include name of the event and id of the entity affected by event. If details of event are of your interest, use information from event data to retrieve entity details.

{
    "type": "notification", // event notification
    "event": "transaction.processed", // event name
    "data": "63967141191e9023f356df9f", // id of affected entity
    "timestamp": "162553625262" // Date.now()
}

Connect to WebSocket notification server using URL wss://stream.orangepill.cloud.

To subscribe for notification events use your Realm Key in message.

{ "type": "subscribe", "realm": <YOUR_REALM_KEY> }

You can unsubscribe from receiving notification events using similar message.

{ "type": "unsubscribe", "realm": <YOUR_REALM_KEY> }

In successful response to subscribe and unsubscribe events you will receive object.

{ "type":"info", "realm":"c9d4744c-0eae-4457-a665-2c18b9ac132b", "timestamp": 1671547687 }

If subscribe is not successful you will receive info and error objects.

{ "type":"info", "realm":"NONE", "timestamp": 1671547687 }
{ "type":"error", "realm":"Invalid Realm Key.", "timestamp": 1671547687 } }

Subscribe event response.

{ "type":"subscribe", "realm":"c9d4744c-0eae-4457-a665-2c18b9ac132b", "timestamp": 1671547687 } }

Unsubscribe event response.

{ "type":"unsubscribe", "realm":"c9d4744c-0eae-4457-a665-2c18b9ac132b", "timestamp": 1671547687 } }

Example using JavaScript

Use https://api.orangepill.cloud for live example of Event Stream Explorer.

// JavaScript example

const ws = new Sockette('wss://stream.orangepill.cloud', {
  timeout: 5e3,
  maxAttempts: 10,
  onopen: e => subscribe(),
  onmessage: e => message(e),
  onreconnect: e => {console.log('Reconnecting...'); subscribe();},
  onmaximum: e => {console.log('Stop Attempting!')},
  onclose: e => {console.log('Closed!'); cancelKeepAlive();},
  onerror: e => {console.log('Error:')}
});


function message(message) {

    var notification = JSON.parse(message.data);
    
    var event = notification.data.event;
    var data = notification.data.data;
    var timestamp = notification.data.timestamp;      

    // handle event with your logic
    switch (event) {
        case "account.created":
            // your logic here
        break;
        // ....
    }
}

function subscribe() {

    const realm = "<YOUR_REALM_KEY>";
    const obj = { "type": "subscribe", "realm": realm }
    ws.send(JSON.stringify(obj));
    keepAlive();

}

function unsubscribe() { 

    const realm = "<YOUR_REALM_KEY>";
    const obj = { "type": "unsubscribe", "realm": realm }
    ws.send(JSON.stringify(obj));
    
}

let timerId = 0; 

function keepAlive(timeout = 10000) { 
    ws.send('PING');  
    timerId = setTimeout(keepAlive, timeout);  
}

function cancelKeepAlive() {  
    if (timerId) {  
        clearTimeout(timerId);  
    }  
}

Last updated