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

@getstation/slack

v13.0.0

Published

Slack API client written in JS

Downloads

120

Readme

A Slack Web API client :seedling::raised_hands::two_hearts:

  • Written in modern JavaScript; tested for Node and the browser
  • Complete support for the Slack Web API
  • Perfect symmetry: JS method signatures match Web API docs
  • Choose your async adventure: all methods accept either a Node style errback or return a Promise
  • Opt into an OO style class instance that applies token to all methods
  • Well tested, CI, and Apache2 licensed
  • Only one dependency: tiny-json-http
  • Tiny: 7kb browserified/minified

Install :star2::package:

npm i slack

Usage :sparkles::rocket:

slack mirrors the published API docs exactly because its generated from those docs! The default interface are stateless functions and has remain unchanged since 1.0.0 and that will continue to be the case.

var slack = require('slack')

// logs {args:{hello:'world'}}
slack.api.test({hello:'world'}, console.log)

// :new: opt into promises
slack.api.test({nice:1}).then(console.log).catch(console.log)

Due to popular demand an OO style is supported. For an instance of Slack all methods come prebound with the token parameter applied.

const token = process.env.SLACK_BOT_TOKEN
const Slack = require('slack')
const bot = new Slack({token})

// logs {args:{hyper:'card'}}
bot.api.test({hyper:'card'}).then(console.log)

Using async/await in Node 8.x:

let token = process.env.SLACK_BOT_TOKEN
let Slack = require('slack')
let bot = new Slack({token})

;(async function main() {
  // logs {args:{hyper:'card'}}
  var result = await bot.api.test({hyper:'card'})
  console.log(result)
})()

Choose whichever style works best for your project deployment needs and team preference. :hearts::beer:

Error Handling

Some methods (like slack.dialog.open) provide additional context for errors through a response_metadata object. This will be exposed as a messages properties on the errors that are thrown.

slack.dialog.open(options).catch(err => {
  console.log(err.messages)
})

Specialized Electron Support

Electron ships its own HTTP module called electron.net which can have better performance and offers more extensive HTTP proxy handling. You can opt into Electron support by passing useElectronNet:true to the Slack constructor.

import {app, BrowserWindow, net} from 'electron'
import Slack from 'slack'

const slack = new Slack({useElectronNet:true})

You can setup an HTTP authentication proxy logic by passing login to the constructor.

function login(authInfo, callback) {
  callback('username', 'password')
}

const slack = new Slack({useElectronNet:true, login})

Read more about electron.net from the source!

Test Setup :lock::key::point_left:

Clone this repo and create a file called .env in the root with the following:

SLACK_BOT_TOKEN=xxxx
SLACK_CLIENT_ID=xxxx
SLACK_CLIENT_SECRET=xxxx

You can get a SLACK_TOKEN for testing here. You need to register an app for a SLACK_CLIENT_ID and SLACK_CLIENT_SECRET. The tests require the app to have the channels:history scope. You can read about bot tokens here.

Testing :green_heart::green_heart::green_heart:

:point_right: In Node:

npm test

:point_right: Or the browser:

npm run btest

Slack Web API :tada::honeybee::triangular_flag_on_post:

The entire Slack Web API is supported. All method signatures accept a params object and either a Node style callback (an errback) or, if absent, it will return a Promise. Required params are documented inline below.

Contributing

The code for the client is generated by scraping the Slack Web API documentation. Regenerate from the latest Slack documentation by running :runner::

npm run generate

Portions of this README are generated as well; to make edits, update readme.tmpl and run the same command :cloud::umbrella::sunny::sunflower:.