New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-slack

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-slack

Express middleware to handle Slack requests

  • 1.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Slack Express Middleware

Usage

const {PORT, SCOPE, TOKEN, CLIENT_ID, CLIENT_SECRET} = process.env,
      slack = require('express-slack'),
      express = require('express'),      
      app = express();

// the path for OAuth, slash commands, and event callbacks
app.use('/slack', slack({
  scope: SCOPE,
  token: TOKEN,
  store: 'data.json'
  client_id: CLIENT_ID,
  client_secret: CLIENT_SECRET
}));

// handle the "/test" slash commands
slack.on('/test', (payload, bot) => {
  bot.reply('works!');
});

app.listen(PORT, () => {
  console.log(`Server started on ${PORT}`);
});

API

Middleware

const slack = require('express-slack'),
      express = require('express'),      
      app = express();

app.use('/slack', slack({
  scope: 'bot,commands',
  token: 'gIkuvaNzQIHg97ATvDxqgjtO',
  store: 'data/team.json'
  client_id: 'XXXXXXXXXXXX',
  client_secret: 'XXXXXXXXXXXX'
}));
ArgumentDescription
scopeThe Slack OAuth scope to request
client_idThe Slack OAuth Client Id code
client_secretThe Slack OAuth Client Secret code
tokenThe Slack Verification Token (optional)
storeA string path to a filestore or a custom store object

Events

// handle RTM messages
slack.on('message', (payload, bot) => { });

// handle all slash commands
slack.on('slash_command', (payload, bot) => { });

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

// handle multiple events
slack.on('googlebot', '/test', 'slash_command', (payload, bot) => { });

// wildcard support
slack.on('*', (payload, bot) => { });
EventDescription
*****All events
messageAll RTM events
slash_commandAll Slash Commands
eventAll Event API callbacks
webhookAll WebHook callbacks
interactive_messageAll Interactive message callbacks
[/command]Any specific slash command
[event type]Any specific event type
[trigger word]Any trigger from outgoing webhooks

Bot

Bots are preloaded with the appropriate token and are context aware. So you can reply to messages and send ephemeral updates to a message.

slack.on('message', (payload, bot) => {
  bot.replyPrivate('loading...');

  bot.reply({
    text: 'Everything is working!',
    attachments: [{
      title: "Slack API Documentation",
      title_link: "https://api.slack.com/",
      text: "Optional text that appears within the attachment",
      fields: [{
        title: "Priority",
        value: "High",
        short: false
      }]
    }]
  });

  // the token is already set
  bot.send('channels.info', { channel: 'C1234567890' }).then(data => {
    // results from API call
  });
});
MethodsDescription
saySend a message
replySend a public reply to the event
replyPrivateSend an ephemeral reply to the event
sendCall any Slack API endpoint

Data Store

A key/value store to maintain team/bot information and store custom setings. The store follows the same interface of a single BotKit Store

slack.store.all().then(results => {
  // list of all items
});

slack.store.get(id).then(record => {
  // return a single record by key
});
MethodsDescription
getGet a single record by id
allGet all saved records
saveSave a record

Client

The Slack client is a way to call the API outside of an event.

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.send('chat.postMessage', message).then(data => {
  // Success!
});

// respond to webhooks
slack.send('https://hooks.slack.com/services/T0000/B000/XXXX', message);
Instances
// create an instance with defaults
let instance = slack.client({
  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
instance.send('chat.postMessage', message);

Keywords

FAQs

Package last updated on 02 Mar 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc