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-wrapi

v1.1.0

Published

Slack Web API Client Library

Downloads

218

Readme

Slack Web API

The simplest library for Slack Web API.

Call Slack Web API endpoints just like functions

NPM version Build Status Coverage Status

Installation

Install via npm

npm install slack-wrapi --save

Usage

Create a Slack client with the API token.

const slackWrapi = require('slack-wrapi');

const slack = new slackWrapi(SLACK_API_TOKEN);

// Now you are ready to make API calls to Slack.

Function names match with Slack API endpoints (methods) as per the documentation.

Just provide parameters and a callback or get back a Promise.

API calls follow this syntax:

slack.apigroup.action(queryString, callback);

  • queryString - (as required) API method parameters as key-value pairs.

If no callback is provided, the function returns a Promise object.

Post a message with callback:

// ES5 Syntax with callback
slack.chat.postMessage({
    "channel": "#general",
    "text": "Hello World!"
  },
  function(err, res) {
    if (!err) {
      console.log('Message posted: ', res.ts);  
    }
  }
)

Post a message. Get back a Promise:

// ES2015 Promise
slack.chat.postMessage({
  "channel": "#general",
  "text": "Hello World!"
})
.then((res) => {
  console.log('Message posted: ', res.ts);  
})
.catch(console.error);

Post a message via async/await:

// ES2017 async/await
(async () => {
  try {
    const res = await slack.chat.postMessage({
      "channel": "#general",
      "text": "Hello World!"
    });

    console.log('Message posted: ', res.ts);  
  }
  catch(err) {
    console.error(err);
  }
})();

Call any Slack Web API methods with the client object.

Examples

Lists custom emojis for a team.

slack.emoji.list(function(err, data) {
  if (!err) {
    console.log(data);
  }
});

Lists all channels in a Slack team.

slack.channels.list({exclude_archived:1}, function(err, data) {
  if (!err) {
    console.log(data);
  }
});

Gets information about a private group.

slack.groups.info({channel:"G1234567890"}, function(err, data) {
  if (!err) {
    console.log(data);
  }
});

Adds a reaction to an item.

slack.reactions.add({
    name: "thumbsup",
    file: "F1234567890",
    file_comment: "Fc1234567890",
    channel:"G1234567890",
    timestamp: "1234567890.123456"
  },
  function(err, data) {
    if (!err) {
      console.log(data);
    }
  }
);

Gets information about a user.

slack.users.info({user: "U1234567890"}, function(err, data) {
  if (!err) {
    console.log(data);
  }
});

Post chat messages to Slack.

slack.chat.postMessage({
    "channel": "#general",
    "text": "Hello <@u12345678|world>!",
    "username": "Wrapi Bot",
    "as_user": false,
    "parse": "full",
    "link_names": 1,
    "attachments": [{"pretext": "pre-hello", "text": "text-world"}],
    "unfurl_links": true,
    "unfurl_media": false
  },
  function(err, data) {
    if (!err) {
      console.log(data);
    }
  }
)

Check user's current Do Not Disturb settings.

slack.dnd.info({
    "user": "U1234"
  },
  function(err, data) {
    if (!err) {
      console.log(data);
    }
  }
)

API Methods

api

apps.permissions

apps.permissions.resources

apps.permissions.scopes

apps.permissions.users

apps

auth

bots

channels

chat

conversations

dialog

dnd

emoji

files.comments

files

groups

im

migration

mpim

oauth

pins

reactions

reminders

rtm

search

stars

team

team.profile

usergroups

usergroups.users

users

users.profile

License

MIT