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

stdbot

v0.5.1

Published

Standard Node.js chat interface for bots.

Downloads

10

Readme

stdbot npm version

Basically, Hubot as a library.

Overview

stdbot aims to provide a universal API for bots to interact with chat rooms, via a number of adapters.

Adapters

Installation

npm install --save stdbot
npm install --save stdbot-flowdock # Use the adapter of your choice

Usage

const Stdbot = require('stdbot')
const Flowdock = require('stdbot-flowdock')

const bot = Stdbot(Flowdock({
  token: 'my-token',
  flows: ['main']
}))

Tweak the code with the adapter of your choice, and its specific options (documented in the adapter readme).

Events

The bot object is an EventEmitter.

  • All errors are sent through the error event.
  • You can listen for message events.

See objects for message format.

Methods

  • send a message in the context of another message (for example, same thread).
  • reply to a message, mentioning its author.
  • edit a message you sent.
  • messageRoom to send a message to a room without context.

Each of these methods return a promise yielding the message object representing the message you sent.

  • mention an user in the adapter format (for example prefixing its name by a @.
  • address a message to an user for example by mentioning them and adding a suffix like , or : .
  • mentions to get the list of users mentioned in a message.
  • isMentioned to tell if a user is mentioned in a message.
  • end the stream to stop listening.

Example

bot.on('message', message => {
  // Send a message in the same thread
  message.send(`Hello, ${bot.mention(message.author)}!`)
  // bot.send(message, `Hello, ${bot.mention(message.author)}!`)

  // Same, but mention the message author
  message.reply(`Hello, ${bot.mention(message.author)}!`)
  // bot.reply(message, `Hello, ${bot.mention(message.author)}!`)

  // Edit your own message (if supported by adapter)
  message.send(`Hello, ${bot.mention(message.author)}!`)
    .then(myMessage => myMessage.edit(bot.address(message.author, 'Hello!')))
    // .then(myMessage => bot.edit(myMessage, bot.address(message.author, 'Hello!')))
    .then(myEditedMessage => {})
})

// Send a message in a room
bot.messageRoom('main', 'Hello, world!')

Objects

Object structure is strongly inspired by Schema.org naming, especially Person for users and EmailMessage for messages.

User

| Name | Type | Description | |------------|----------|------------------------------| | raw | Object | Raw user object from adapter | | id | String | User ID | | name | String | User nickname |

Some adapters may provide other information, like fullName, email, image, url.

Message

| Name | Type | Description | |----------|----------|---------------------------------| | raw | Object | Raw message object from adapter | | id | String | Message ID | | author | User | User who sent the message | | text | String | Message text content |

Why not Hubot?

The main reason to not use Hubot in some cases is because Hubot and its adapters can hardly be used as a library. Neither Hubot nor its adapters are meant to be required by third party code:

  • Hubot and its adapters require CoffeeScript to run, and the code is not precompiled to JavaScript, requiring you to run your whole project through CoffeeScript if you want to require it.
  • Hubot will take ownership of the whole console output and process error handling, which is not suitable when used as a library.
  • Hubot adapters can't be used standalone because they depend completely on the Hubot environment.

This is okay, since Hubot is not a library, and its adapters are not designed for portability. stdbot is an alternative that you can use in your own applications, instead of having your scripts be executed inside Hubot.

See also

  • Switch, similar project, built around RxJS. Unlike stdbot, switch aims to be exhaustive in the events and features exposed by the adapter, while stdbot is more like a common denominator between supported adapters, with a simple but limited feature set.