Socket
Book a DemoInstallSign in
Socket

slack-micro

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slack-micro

A micro client to interact with Slack's Web API

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Slack Micro Client

This is a zero dependency node.js client for Slack's Web API

The goal of this project was to build a node.js client that can be dropped into serverless functions without requiring a massive dependency tree. This client covers two main scenarios: making requests and handling responses.

Install

npm i slack-micro --save

Requests

Usage

slack('method name or url', {payload}) // returns a promise

Examples

let slack = require('slack-micro');

let message = {
  unfurl_links: true,
  channel: 'C1QD223DS1',
  token: 'xoxb-12345678900-ABCD1234567890',
  text: "I am a test message http://slack.com",
  attachments: [{
    text: "And here's an attachment!"
  }]
}

// send message to any Slack endpoint
slack('chat.postMessage', message).then(response => {
  // Success!
});

// respond to webhooks
slack('https://hooks.slack.com/services/T0000/B000/XXXX', message);

Defaults

let slack = require('slack-micro');

slack.defaults = {
  unfurl_links: true,
  channel: 'C1QD223DS1',
  token: 'xoxb-12345678900-ABCD1234567890'  
};

let message = {
  text: "I am a test message http://slack.com",
  attachments: [{
    text: "And here's an attachment!"
  }]
};

// send message to any Slack endpoint
slack('chat.postMessage', message);

Responses

Usage

// event handler
slack.on('event name', [... 'event name',] callback)

// http server
slack.listen(port, 'path') // return http server

// digester
slack.digest('JSON string' or {message})

Examples

let slack = require('slack-micro');

slack.on('/test', message => {
  // handle the "/test" slash commands
});

slack.on('slash_commands', message => {
  // handle all slash commands
});

slack.on('googlebot', message => {
  // handle the outgoing webhooks trigger word "googlebot"
});

slack.on('googlebot', '/test', 'slash_commands', message => {
  // handle multiple events
});

slack.on('*', message => {
  // wildcard support
});

// Simple WebServer
slack.listen(3000, '/slack/incoming');


// AWS Lambda handler
exports.handler = (event, context, callback) => {
  slack.digest(event.body); // parses the body  
}

RTM

let slack = require('slack-micro'),
    WebSocket = require('ws'),
    rtm = null;

slack.defaults = {
  token: 'xoxb-12345678900-ABCD1234567890'
};

slack('rtm.start').then(data => {    
  rtm = new WebSocket(data.url);
  rtm.on('message', slack.digest);
});

slack.on('*', message => {
  // watch for any RTM event
});

Keywords

slack

FAQs

Package last updated on 29 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts