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

relax-js

v0.0.1

Published

Node.js Client for Relax

Downloads

3

Readme

Relax-js

Relax-js is a Node.js client for interacting with Relax – a multitenant message broker for Slack.

There are two primary functions that this client library lets you perform:

  1. Spin up new Slack bots on Relax
  2. Listen for events generated by Relax

Getting Started

If you're just getting started with Relax and don't already have a Relax Go instance up and running, go ahead and get that set up first by following the instructions here (Don't worry you don't need any prior knowledge of Go). If you use Heroku, there's a "Deploy to Heroku" button to help you get up and running super quickly.

Once you've done that, take note of the following environment variables configured on your Relax Go instance (you'll need to use the exact same ones for your Node.js app):

  • REDIS_URL
  • RELAX_BOTS_KEY
  • RELAX_BOTS_PUBSUB
  • RELAX_EVENTS_QUEUE
  • RELAX_MUTEX_KEY

If you haven't already, go ahead and create a new Node.js app. Next, install the relax-js node module in either of the following ways:

Install directly with npm:

$ npm install relax-js

or add to your package.json file and then npm install:

"relax-js": "0.0.1"
$ npm install

Usage

Before using this module, make sure your environment variables (the 5 listed above) are set and match the ones used on your Relax Go instance. If they aren't set, Relax-js will throw errors.

Initialize a new Relax-js instance

var Relax = require('relax-js');
// create new relax instance
var relax = new Relax();

Spin up a new bot running on Relax

You can create a new bot for your Slack team here if you haven't already. The Slack API should also be able to provide you with your team's uid, which you will need along with your bot's token in order to spin up a bot on Relax.

relax.createBot(teamUid, botToken);

Listen for bot events from Relax

Here is an example of setting up an event handler for new messages. For information about all events generated by Relax, go here.

// Set up your event listeners
relax.on('message_new', function (data) {
  console.log('Heard new message!', data);

  // data object should look something like this:
  // {
  //   type: 'message_new',
  //   user_uid: 'UXXXXXXXX',
  //   channel_uid: 'DXXXXXXXX',
  //   team_uid: 'TXXXXXXXX',
  //   im: true, // or false
  //   text: 'This is a message',
  //   relax_bot_uid: 'UXXXXXXXX',
  //   timestamp: '1462579994.000021',
  //   provider: 'slack',
  //   event_timestamp: '1462579994.000021',
  //   namespace: '' 
  // }
});

// Start listening for messages
relax.start();

License

MIT