Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@slack/socket-mode

Package Overview
Dependencies
Maintainers
10
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slack/socket-mode

Official library for using the Slack Platform's Socket Mode API

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
386K
increased by4.89%
Maintainers
10
Weekly downloads
 
Created

What is @slack/socket-mode?

@slack/socket-mode is an npm package that allows developers to interact with Slack's Socket Mode API. This package enables real-time communication with Slack by establishing a WebSocket connection, which can be used to receive events and send messages without the need for a public HTTP endpoint.

What are @slack/socket-mode's main functionalities?

Establishing a WebSocket connection

This code sample demonstrates how to establish a WebSocket connection using the @slack/socket-mode package. The `App` class is instantiated with the necessary tokens, and the `start` method is called to initiate the connection.

const { App } = require('@slack/socket-mode');
const app = new App({
  appToken: 'xapp-1-A1234567890-123456789012-abcdef1234567890abcdef1234567890abcdef',
  token: 'xoxb-123456789012-1234567890123-abcdef1234567890abcdef1234567890'
});

(async () => {
  await app.start();
  console.log('⚡️ Bolt app is running!');
})();

Listening for events

This code sample shows how to listen for 'message' events using the @slack/socket-mode package. When a message event is received, the event details are logged, and a response is sent back to the user who sent the message.

app.event('message', async ({ event, say }) => {
  console.log(event);
  await say(`Hello, <@${event.user}>!`);
});

Sending messages

This code sample demonstrates how to send messages using the @slack/web-api package in conjunction with @slack/socket-mode. The `WebClient` class is used to send a message to a specific channel.

const { WebClient } = require('@slack/web-api');
const web = new WebClient('xoxb-123456789012-1234567890123-abcdef1234567890abcdef1234567890');

(async () => {
  await web.chat.postMessage({
    channel: '#general',
    text: 'Hello, world!'
  });
})();

Other packages similar to @slack/socket-mode

Keywords

FAQs

Package last updated on 25 Oct 2022

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