Last active
September 24, 2017 16:34
-
-
Save ernestofreyreg/dd84a72e986bc8415c9c05a0605bdcf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const RTM = require('satori-rtm-sdk') | |
// create an RTM client instance | |
const rtm = new RTM('YOUR_ENDPOINT', 'YOUR_APPKEY') | |
// create a new subscription with 'your-channel' | |
const channel = rtm.subscribe('YOUR_CHANNEL', RTM.SubscriptionMode.SIMPLE) | |
// add channel data handlers | |
// channel receives any published message | |
channel.on('rtm/subscription/data', pdu => { | |
const messages = pdu.body.messages | |
messages.forEach(console.log) | |
}) | |
// client enters 'connected' state | |
rtm.on('enter-connected', () => { | |
const payload = {key: 'value'} | |
rtm.publish('YOUR_CHANNEL', payload) | |
}) | |
// client receives any PDU and PDU is passed as a parameter | |
rtm.on('data', pdu => { | |
if (pdu.action.endsWith('/error')) { | |
rtm.restart() | |
} | |
}) | |
// start the client | |
rtm.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment