0.0.6 • Published 7 years ago

flockos v0.0.6

Weekly downloads
13
License
ISC
Repository
github
Last release
7 years ago

FlockOS SDK for node.js

Installation

npm install flockos

Usage

First, require the module, then set your app id and app secret.

var flock = require('flockos');

flock.appId = '<app id>';
flock.appSecret = '<app secret>';

To verify event tokens, you can either use flock.events.verifyToken:

flock.events.verifyToken(token);

Or, if you use express, we provide a convenient middleware to automatically verify all event tokens, whether they are sent to the event listener URL or a widget or browser URL:

var app = express();
app.use(flock.events.tokenVerifier);

To handle events an express router is provided. If you use this, you can listen for all incoming events on flock.events.

app.post('/events', flock.events.listener);

flock.events.on('client.slashCommand', function (event, callback) {
    // handle slash command event here
    ...
    // invoke the callback to send a response to the event
    callback(null, { text: 'Received your command' });
});

To call a method, use flock.callMethod.

flock.callMethod('chat.sendMessage', token, {
    to: 'u:wufu4udrcewerudu',
    text: 'hello'
}, function (error, response) {
    if (!error) {
        console.log(response);
    }
});