You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@slack/socket-mode

Package Overview
Dependencies
Maintainers
10
Versions
25
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

2.0.4
latest
Source
npmnpm
Version published
Weekly downloads
472K
-19.56%
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

slack

FAQs

Package last updated on 27 Mar 2025

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