
Slack comes with a slew of standard integrations, but it’s also really easy to build your own. One of the things that makes Slack so compelling is that it integrates well with all kinds of other applications and services - a perfect fit within API space. Once you get a bot token, working with the Slack API from Node.js is fairly straightforward.Slack is a messaging app that has exploded in popularity among all sorts of teams.

}, ) īelow is what the above message looks like in Slack. const axios = require( 'axios') Ĭonst slackToken = 'xoxb-YOUR-TOKEN_HERE' Note that you must have a #test channel in your Slack The POST request body must contain the channel you want to post to, and the textīelow is how you can send a 'Hello, World' message with Axios. To send a message to a Slack channel, you need to make an HTTP POST request to the endpoint with your Slack token in the authorization header. Installed the app, Slack will give you a bot user token: Making Your First Request Once you've added the above scopes, click "Install App" to install this new Slack app to your workspace. First, make sure you add the following scopes to your bot user: You'll have to add scopes (permissions) to your bot user, and then

Next, go through the steps to create a bot user. You set "Development Slack Workspace" to the Slack Workspace you want to use. In order to get a bot user token, you first need to create a new Slack app. Bot user tokens let you post messages as a bot user, with a custom nameĪnd avatar, as opposed to as an existing user. But, for the purposes of this article, I'll be using bot user tokens. Lets you post messages on behalf of a user. There are several types of Slack token, each with its own permissions. In order to make an API request to Slack, you need a Slack token. However, both and slack areįairly thin wrappers around the Slack API, so, for the purposes of this article, we'll just use axios. I've also used node-slack in the past, but that module is fairly out of date. There are two npm modules that I recommend for working with the Slack API: the official module and the slack module written primarilyīy Brian LeRoux of WTFJS fame. In this article, I'll explain the basics of how to send a Slack message from Node.js.

Slack is the de factoĬommunication platform for many companies, so there's a lot of demand for getting data from Node.js apps to Slack Integrating with the Slack API is becoming an increasingly common task.
