npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keen-botkit

v1.0.2

Published

Bot Kit Integration for Keen IO

Downloads

17

Readme

Keen IO BotKit Integration

We've made it very easy to track messages and conversations within your Slack bot (built with bot-kit), so you can analyze the usage of your bot.

If you have custom needs, you can always fork this project and make modifications.

Read to get started? Create a free Keen IO account to grab your projectId and writeKey.

Install

Keen IO Bot-Kit is available via NPM.

npm install keen-botkit --save

If you want to use the example code, you can also clone it directly from Git.

git clone [email protected]:nemo/keen-botkit.git

Note that after cloning, you'll have to install the dependencies (which is just keen-js:

npm install

Look at example section for how to use the example.

Usage

The integration works by adding middleware to Botkit using its middleware system. We intersect every interaction and send an event to Keen IO.

Specifically, on the send and receive middleware. To initialize the middleware, you have to pass an initialized Keen IO client from keen-js):

var KeenBotKitIntegration = require('keen-botkit');

// Initialize Keen IO client
var client = new Keen({
    projectId: "<projectId>",
    writeKey: "<writeKey>"
});

// prepare middleware
var receiveMiddleware = KeenBotKitIntegration.botKitReceiveMiddleware(client);
var sendMiddleware = KeenBotKitIntegration.botKitSendMiddleware(client);

And then simply apply the middleware to your Botkit controller:

var controller = Botkit.slackbot({
    debug: true,
});

controller.middleware.receive.use(receiveMiddleware);
controller.middleware.send.use(sendMiddleware);

Collection Name

By default, the middleware sent events to collections named message_received and message_sends for received messages and sent messages respectively. You can modify this behavior by passing in a collection option:

var KeenBotKitIntegration = require('keen-botkit');

var receiveMiddleware = KeenBotKitIntegration.botKitReceiveMiddleware(client, {
  collection: 'user_messages'
});

var sendMiddleware = KeenBotKitIntegration.botKitSendMiddleware(client, {
  collection: 'bot_messages'
});

Payload

In the spirit of customizability, you can modify the payload that is sent to Keen by providing a payload object or function to modify the payload before it goes out:

var KeenBotKitIntegration = require('keen-botkit');

// Works for both botKitSendMiddleware and botKitReceiveMiddleware
var sendMiddleware = KeenBotKitIntegration.botKitSendMiddleware(client, {
  payload: function(message, callback) {
    // Modify message or pass your own payload
    message._user_id = '10';

    callback(null, message);
  }
});

var sendMiddleware = KeenBotKitIntegration.botKitSendMiddleware(client, {
  payload: {
    static_attribute: 9000
  }
});

Debug

By default, errors are logged. But if you want to get some logs on successful event saves – just pass in debug: true as the second argument when you initialize the middleware:

var KeenBotKitIntegration = require('keen-botkit');

var receiveMiddleware = KeenBotKitIntegration.botKitReceiveMiddleware(client, {debug: true});
var sendMiddleware = KeenBotKitIntegration.botKitSendMiddleware(client, {debug: true});

Example

There's a short example included in the slack_bot_example.js file.

Note that you have to get a Bot token from Slack and then run the example from the command line:

token=<MY TOKEN> node slack_bot_example.js

If you want to view the events that are sent to Keen IO on your own account, you should replace the credentials on line 79.

Contributing

This is an open source project that started within the Keen IO Community - you can read more about its creator here. We'd love future involvement from the community! 💖 If you are interested in getting involved, please see CONTRIBUTING.md to get started.