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

slack-ux

v1.0.2

Published

A simple way to create slack bots for a conversational user experience. This is a wrapper around the slackbots package geared mainly towards channels

Downloads

4

Readme

SlackBot

A simple way to create slack bots for a conversational user experience. This is a wrapper around the slackbots package geared mainly towards channels

Installation

npm install slack-ux

Methods

  • setSuggestions(suggestions) (return: null) - sets the suggestions object that defines the keywords and the functions to invoke,
  • isChannelConversation(message) (return: boolean) - returns a true/false of whether this message is a channel conversation,
  • isMyChannel(message) (return: promise) - returns true/false of whether this message is from the configured channel,
  • getChannelDetails(message) (return: promise) - returns a channel object with channel details,
  • postChannelMessage(message) (return: null) - posts a message to the channel configured by in the settings,
  • isFromBot(message) (return: boolean) - returns a true/false of whether the message event was just generated because of the bot posting to the channel,
  • isChatMessage(message) (return: boolean) - returns a list of all channels in the team,
  • callAction(message) (return: promise) - invokes the appropriate action function is the message matches any of the suggestions,
  • getChannels() (return: promise) - returns a list of all channels in the team,
  • getGroups() (return: promise) - returns a list of all groups in the team,
  • getUsers() (return: promise) - returns a list of all users in the team,
  • fns (return: null) - fns objects to hold all the invoked functions,
  • getImChannels() (return: promise) - returns a list of bots direct message channels in the team,
  • getChannel(name) (return: promise) - gets channel by name,
  • getGroup(name) (return: promise) - gets group by name,
  • getUser(name) (return: promise) - gets user by name,
  • getUserByEmail(name) (return: promise) - gets user by name,
  • getChannelId(name) (return: promise) - gets channel ID by name,
  • getGroupId(name) (return: promise) - gets group ID by name,
  • getUserId(name) (return: promise) - gets user ID by name,
  • getChatId(name) (return: promise) - it returns or opens and returns a direct message channel ID,
  • postEphemeral(id, user, text, params) (return: promise) - posts an ephemeral message to channel and user by ID,
  • postMessage(id, text, params) (return: promise) - posts a message to channel | group | user by ID,
  • updateMessage(channelId, timestamp, text, params) (return: promise) - updates a message in a channel,
  • postTo(name, message [, params, callback]) (return: promise) - posts a message to channel | group | user by name,
  • postMessageToUser(name, message [, params, callback]) (return: promise) - posts a direct message by user name,
  • postMessageToGroup(name, message [, params, callback]) (return: promise) - posts a message to private group by name,
  • postMessageToChannel(name, message [, params, callback]) (return: promise) - posts a message to channel by name.
  • openIm(userId) (return: promise) - opens a direct message channel with another member in the team

Usage


const Bot = require('slack-ux');

var bot= new Bot({
    token:'xoxb-111111111111-abcdefghijklmnopqrstuvwx', // Add a bot https://my.slack.com/services/new/bot and copy the token 
    name:'mybot',
    channel:'mychannel'
});
bot.setSuggestions({
    "greetMe":["hello","say hi","greet","welcome"],
    "sayGoodBye":["leave","bye"]
});
bot.on('start', function(){
    bot.postChannelMessage("Hi welcome to the channel");
});
bot.on('message',function(msg){
    //Check what type of message it is
    if(bot.isChatMessage(msg) && !bot.isFromBot(msg) && bot.isChannelConversation(msg)){
        bot.isMyChannel(msg).then(res=>{ //Checks if this is a message form the channel mentioned in the settings
            if(res)
                bot.callAction(msg);
        })
    }
});

bot.fns.greetMe = function(){ //This name should the key in suggestions
    bot.postChannelMessage("Hi how are you?");
}

bot.fns.sayGoodBye = function(){ //This name should match the key in the suggestions
    bot.postChannelMessage("Goodbye!");
}

Alt text

Response Handler

The simplest way for handling response is callback function, which is specified as a last argument:

bot.postMessageToUser('user1', 'hi', function(data) {/* ... */});
bot.postMessageToUser('user1', 'hi', params, function(data) {/* ... */});

But also you can use promises.

Error:

bot.postMessageToUser('user1', 'hi').fail(function(data) {
    //data = { ok: false, error: 'user_not_found' }
})

Success:

bot.postMessageToUser('user', 'hi').then(function(data) {
    // ...
})

Error and Success:

bot.postMessageToUser('user', 'hi').always(function(data) {
    // ...
})