Receive Messages from Aleph

Receive Messages from the aleph server with WebSockets.

Usage

// Websocket URL:
// "wss://<TARGET SERVER>/api/ws0/messages?
// query_1=value&query_2=value"

// Example url:
// "wss://api2.aleph.im/api/ws0/messages?
// msgType=POST&contentTypes=chat"

const url = 'wss://api2.aleph.im/api/ws0/messages'

const connection = new WebSocket(url) 

connection.onmessage = (e) => { 
  console.log(JSON.parse(e.data))
}

Only one msgType can be queried at a time. All other query parameters are comma-separated strings if multiple values are passed.

If multiple values are passed for one query parameter, messages that match at least one of the values will be returned.

If multiple query parameters are passed, messages that match ALL conditions will be returned.

Query parameters

Query parametersDescription

msgType

Message type. Value: POST, AGGREGATE, or STORE

addresses

Addresses listed in the

  • content address (item_content.address)

  • or sender (sender) attribute of the Message.

If multiple addresses are passed, any message with one of the queried addresses in the content address or sender attribute will be returned.

refs

Refs listed in content refs (item_content.ref)

contentTypes

Message content types (item_content.type)

channels

Message channel.

tags

Message content content tag. (item_content.content.tags).

If multiple tags are passed, messages with at least one of the tags present in the content content tags will be returned.

hashes

hashes listed in the item hash(item_hash) or transaction hash (tx_hash)

time.startDate & time.endDate

Filtering messages on the time attribute (time).

If only the start date is passed, messages with "time" being greater than the start date will be returned.

If only the end date is passed, messages with "time" being less than the end date will be returned.

If both start and end dates are passed, messages with "time" in between the start date and end date will be returned.

history

Default: 10

The number of Messages to retrieve.

The default number returned is 10 if none is passed. Minimum #: 10, Maximum #: 200. Values outside this range will be ignored.

Last updated