Satori Docs

Your definitive guide to subscribing and publishing live data

Streambot™ API for JavaScript Direct link

This article describes the JavaScript API that you use to implement Streambots™.

To initialize a Streambot™, use:

  • config array

To receive messages, use:

  • onMessage function

Initialize a Streambot™ Direct link

config Array

Your JavaScript implementation of a Streambot™ performs the initialization operation when the Streambot™ starts. As shown in the example below, you can access custom configuration data through the config[] array.

The custom configuration can be any data, represented as a JSON object, that you would like to have available to a Streambot™ instance when it starts. This JSON object is entered on the Dev Portal instantiation screen and is made available to a Streambot™ instance via the config[] array. For a simple dispatcher Streambot™ that republishes messages from one channel to another, the configuration might consist of only the name of the channel to which it will republish. For example, the following line specifies example.out as the channel to which the Streambot™ will republish.


This channel name can be retrieved as shown in the following code, where the outputChannel key/value pair is accessed at the start of the script.

var outputChannel = config['outputChannel']

Receive Messages Direct link

The primary function of a Streambot™ is to subscribe to a channel and process the messages it receives from that channel. The Streambot™ could then publish the messages to any channel in its project.

After initialization is complete, the Streambot™ can then receive and process messages as follows.

onMessage Function

To build a JavaScript Streambot™, you need to implement a function called onMessage.

Your onMessage implementation is automatically invoked when a message from the RTM stream is received. This function processes a message received by the Streambot™ from subscribed channels, and may include logic to republish that message to the channels.

Unlike the onSubscriptionData method of the Java Streambot™ which can receive batches of messages, the JavaScript Streambot™ onMessage function receives one message at a time via its message parameter for the channel specified in the channel parameter.

In the example below, onMessage invokes the publish method of the rtm object to republish a message.

console.log('initializing Streambot™...')

var outputChannel = config['outputChannel']
console.log('output channel: %s', outputChannel)

//forward message received from channel to example.out channel
function onMessage(channel, message) {
    console.log("message received: '%s'", message);
    rtm.publish(outputChannel, message)