Git Product home page Git Product logo

botmetrics.js's Introduction

Botmetrics

Botmetrics is a service that lets you collect & analyze metrics from your bots (Slack, Facebook, Kik, Telegram and more).

This Node.JS client lets you register your bot with Botmetrics and starts metrics collection.

Installation

To install this as part of your Node.JS project, add this to your dependencies in your application's package.json:

botmetrics

or run

$ npm install --save botmetrics

Usage (Facebook)

Register your Facebook bot with Botmetrics. Once you have done so, navigate to "Bot Settings" and find out your Bot ID and API Key.

Set the following environment variables with the Bot ID and API Key respectively.

BOTMETRICS_BOT_ID=your-bot-id
BOTMETRICS_API_KEY=your-api-key

track

Call the track API in the webhook receiver that handles all of your Facebook messenger callbacks.

BotMetrics.track(req.body);

If you are using an Express app, this is what it would look like:

// Remember to run `npm install --save botmetrics` in your app.
//
// If you are using an Express-based app, parse the request body
// and pass along req.body as an argument to Botmetrics
// for example:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var Botmetrics = require('botmetrics');

app.use(bodyParser.json()); // for parsing application/json

app.post('/webhooks', function(req, res) {
  Botmetrics.track(req.body);
  res.status(200).send("");
});

app.listen(5000, function () {
  console.log('facebook bot listening on port 5000!');
});

Usage (Slack)

Log in to your BotMetrics account, navigate to "Bot Settings" and find out your Bot ID and API Key.

Set the following environment variables with the Bot ID and API Key respectively.

BOTMETRICS_BOT_ID=your-bot-id
BOTMETRICS_API_KEY=your-api-key

Once you have that set up, every time you create a new Slack Bot (in the OAuth2 callback), and assuming the bot token you received as part of the OAuth2 callback is bot-token, make the following call:

BotMetrics.registerBot('bot-token', function(err, status) {

});

Retroactive Registration

If you created your bot in the past, you can pass in createdAt with the UNIX timestamp of when your bot was created, like so:

BotMetrics.registerBot('bot-token', {createdAt: 1462318092}, function(err, status) {

});

Messaging a user or channel

You can use Botmetrics to message a user (via DM) or a channel for a given team. You can do this like this:

BotMetrics.message('slack-team-id', {user: 'USLACKBOT', text: 'hello there'}, function(err, status) {

});

For a channel, pass the Slack Channel ID as a parameter:

BotMetrics.message('slack-team-id', {channel: 'CCAFEDEAD1', text: 'hello there'}, function(err, status) {

});

To send attachments, you can send an attachments array:

Botmetrics.message('slack-team-id', {channel: 'CCAFEDEAD', attachments: [{"fallback": "hello", "text": "hello"}] }, function(err, status) {
  expect(status).to.be.true;
  expect(scope.isDone()).to.be.true;
  done();
});

To read more about Slack attachments, you can check it out at this Slack API Docs page.

BotMetrics will queue your message for sending. If your message is correctly formatted, you will receive status=true in the callback.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/botmetrics/botmetrics.js. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

botmetrics.js's People

Contributors

arunthampi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.