Last active
February 7, 2018 07:58
-
-
Save tylerlong/3ab9d32e637b6163caa5d9e8e32cebb7 to your computer and use it in GitHub Desktop.
My awesome bot
This file contains 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 RingCentral = require('ringcentral') | |
const dotenv = require('dotenv') | |
dotenv.config() | |
const token = JSON.parse(process.env.token) | |
const rc = new RingCentral({ | |
server: RingCentral.server.sandbox, | |
appKey: '', | |
appSecret: '' | |
}) | |
rc.platform().auth().setData(token) | |
const subscription = rc.createSubscription() | |
subscription.on(subscription.events.notification, message => { | |
if (message.body.creatorId !== token.owner_id) { // not a message from the bot | |
if (message.body.text === 'ping') { | |
rc.platform().post('/glip/posts', { | |
groupId: message.body.groupId, | |
text: 'pong', | |
attachments: undefined | |
}) | |
} | |
} | |
}) | |
subscription.setEventFilters(['/glip/posts']).register().then(() => { | |
console.log('subscription registered') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment