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

easy-slackbot

v0.1.2

Published

Node.js slackbot with customizable commands that makes sense.

Downloads

4

Readme

easy-slackbot npm version Code Climate

Node.js slackbot with customizable commands that makes sense. At it's core, easy-slackbot is a wrapper around the slackbotapi module made by @xBytez. I have tried to improve the ease of use of creating custom commands by providing a high-level way to add functionality.

Installing

$ npm install easy-slackbot --save

Usage

Check out the examples to see how easy-slackbot is used.
Alternatively, check out this cool project by ToukuFM built upon easy-slackbot.

Note: 'use strict'; is required for this bot to run. easy-slackbot uses many Ecmascript 6 features.

Due to the way the slackbotapi works, channels and users cannot be @username or #channelname. They must be accessed by their unique ID. You can find this ID by running the example code with your own API token. If you add the bot to all channels, you can start typing in any of them and check the console output for the event which will list the channel ID and the user ID of the person who is typing. Use this ID to create your custom commands.

Alternatively, use SlackBot.getChannel('#general') to get a channel object which you can use in your code. This also works for the user ID. Simply use SlackBot.getUser('username') and you will get an user object.After that, you can use the ID you extract from these objects to send a new message to a specific user or channel.

Planned Features

  • More detailed documentation
  • Adding custom .on('event', ...) handlers
  • Adding some premade commands to NPM that you can use
  • Basically a high level wrapper around slackbotapi

License

This program is licensed under the GPL-3.0 license.


Documentation

For more detailed information, visit the slackbotapi git repository.These examples use SlackBot.methodName(), but you should be using your created instance of SlackBot. In the example above, you would use bot.getChannel('#general') to get the channel object.

Before connecting

SlackBot.addCommand(command)

* Add a command to the bot.
* @param {Command} command Instance of a Command class.
* @example addCommand(new MyCommand())

SlackBot.addCommandDirectly(command, function)

You can use this to add commands without making use of the supplied Command class. Simply specify a word which the command will be triggered on, and add a function that has 4 arguments (data, commandtext, slack, callback). To respond, simply use callback('your response').

* Add a new command directly without using Command.
* @param {string} cmd Lowercase string of command trigger word.
* @param {Function} func Callback function that accepts 4 arguments.
* @example addCommandDirectly('hello', (a, b, c, cb) => cb('Hey!'))

SlackBot.connect()

This method will either work, or show you an appropriate error message.

* Initializes the registered commands and connects to Slack.

After connecting

SlackBot.getUser(term)

* Get a user by name or ID
* @param  string  term  Search term
* @return object        Returns object with user if found, else null.
* @example getUser("xBytez")

SlackBot.getUserByEmail(term)

* Get a user by e-mail address
* @param  string  term  Search term
* @return object        Returns object with user if found, else null.
* @example getUserByEmail("[email protected]")

SlackBot.getChannel(term)

* Get a channel by name or ID
* @param  string  term  Search term
* @return object        Returns object with channel if found, else null.
* @example getChannel("general")

SlackBot.getIM(term)

* Get IM by name or ID
* @param  string  term  Search term
* @return object        Returns object with IM if found, else null.
* @example getIM("xBytez")

SlackBot.sendTyping(channel)

* Indicates the user/bot is typing by sending a typing message to the socket
* @param  string channel  Channel/IM ID
* @example sendTyping("C0D12BCLV")

SlackBot.sendMsg(channel, text)

* Sends a message to a channel, private group or already existing IM/PM.
* @param  string channel  Channel/IM ID
* @param  string text  Message
* @example sendMsg("C0D12BCLV", "The cake is a lie!")

SlackBot.sendPM(userID, text)

Using SlackBot.sendIM(userID, text) will work too.

* Send a direct message, if not created, create one.
* @param  string userID Destination User ID
* @param  string text   Message
* @example sendPM("U0489398N")

SlackBot.getSlackData()

* Get current saved data
* @return object Returns object with locally saved data
* @example getSlackData()