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

rxbot

v0.0.22

Published

rex.js is a Slack bot framework built on top of rx.js. The conversation context is modelled using observables which fits well with the asynchronous nature of instant messaging and means you can use the huge library of rx operators to define how your bot w

Downloads

20

Readme

rex.js is a Slack bot framework built on top of rx.js. The conversation context is modelled using observables which fits well with the asynchronous nature of instant messaging and means you can use the huge library of rx operators to define how your bot works.

rex.js also allows for flexible plugins that provide additional functionality such as authorization.

Here's a simple, but complete bot:

const Bot = require('rexjs').Bot;
var botx = new Bot(slackBotToken);

bot.connect().then(() => {
   bot.say('hi everybody');
});

bot.hear('hello')
   .reply('hi hi')
   .start();

The start() method is necessary to start the observable and calls subscribe() under the hood.

Replying back to a user is easy. In this example the bot will randomly respond with either "hi" or "yo" in the original channel or private message:

bot.hear("hi")
   .reply("(hi|yo)")
   .start();

Or you can use say to talk to another user or channel:

bot.hear("hi")
   .say("@bob", "(hi|yo) bob")
   .start();

bot.hear returns an observable of message objects. A message looks like this:

class Message {
	text: string;
	user: User;
	channel: string;
	privateMessage: boolean;
}

And as the converation is an observable any standard Rx operators can be used. This opens up a huge range of options for jobs like filtering, debouncing etc:

// only reply once within a ten second period, and ignore anything not in #random
bot.hear("hi")
   .filter(m => m.channel == "#random")
   .debounce(() => Rx.Observable.timer(10000))		
   .reply("hi")
   .start();

The bot.hear() method supports a powerful string matching language. For example:

// responds to either "hi" or "hello" 
bot.hear("(hi|hello)")		
// * matches anything, e.g. "hi bob"
bot.hear("hi *")			

And you can also capture arguments which will be added to the message object:

bot.hear("say {word}")
   .reply(m => "Ok, saying " + m.word)
   .start();

Arguments can also be typed as below. Note here that reply() can also take a lambda function that takes a message and returns a string allowing for much more flexible responses:

bot.hear("{first:number} + {second:number}")
   .reply(m => m.first + m.second)
   .start();

Combined with the rx.js do() operator you can start to build more complex and useful bots:

var request = require('request');				
bot.hear("ping google")
   .do(m => {  
		request('http://www.google.com', function (error, response, body) { 
			bot.say("google's status is: " + response.statusCode);
		}); 
   })
   .start();

If you need to ask the user for more information you can use the ask() operator. This will wait for the user to reply and capture their response in the message object. By default it will be added to the messgae object with the name "ask" like so:

bot.hear("hi")
   .ask("hey, what's your name??")
   .reply(m => "hi " + m.ask)
   .start();

Alternatively you can define how the response should be handled:

bot.hear("hi")
   .ask("hey, what's your name??", { then: (m, resp) => m.name = resp })
   .reply(m => "hi " + m.name)
   .start();

//add predicate here

You can refer to the bot's name using $me:

// this will match to "hi @botname"
bot.hear("hi $me")				
   .reply(m => "hi hi " + m.user.username)
   .start();