Slack Node



Node Slack SDK The Slack platform offers several APIs to build apps. Each Slack API delivers part of the capabilities from the platform, so that you can pick just those that fit for your needs. This SDK offers a corresponding package for each of Slack’s APIs. Taking Slack Notifications for a Spin. To test my notifications settings and confirm that alerts will be sent to Slack, I decided to throw some high CPU usage at Dillinger. Here's what the high CPU usage looks like in the N Solid application dashboard: And this is what I ended up receiving in Slack my #app-alerts Slack channel: Wrapping Things Up. Node Slackers is a Node.js-focused Slack community. Some Working Groups have discussion channels there. The OpenJSF Slack is a Foundation run Slack with several Node.js channels (channels prefixed by #nodejs-are related to the project). Some Working Groups have discussion channels there. The official Node.js Twitter account is nodejs.

We recently announced a few new features in N|Solid with the release of N|Solid 2.3 - one of which is an expansion to threshold notifications. You can now receive notifications via Slack and webhooks, in addition to the previous email notifications.

  • Slack Interactive Messages for Node The @slack/interactive-messages helps your app respond to interactions from Slack’s interactive messages, actions, and dialogs. This package will help you start with convenient and secure defaults.
  • Track the status and collaborate on experiments and ideas through Slack, saving time and minimizing the need to bounce between applications. Use node.js to handle message menu interactions Sample code by Slack This node.js sample code demonstrates creating.

We’ve worked on making N|Solid threshold alerts more customizable, so you can start consuming them in more places that are a part of your team's natural workflow. As such, I wanted to share a quick run through on how to set up the Slack notifications from N|Solid.

In order to follow along with this guide, you'll need to have N|Solid downloaded, installed, and configured already. You can do this locally on a development environment on Mac or Linux, in a Docker container, or on a server. Check out the N|Solid page to get started, and head over to the N|Solid Docs if you have any questions from there.

Setting Up N|Solid’s Slack Integration

Start in your N|Solid Console in the application dashboard view, with at least one Node.js application connected. For this example, I used Joe McCann’s markdown editor, Dillinger, as an example app:

Setting Up Threshold Notifications

From the application dashboard, select the 'Threshold Settings' link at the top right of the application view:

Choose whether you'd like to turn on threshold notifications for one of the three threshold parameters - CPU, Heap, or Event Loop. In my case, I set Dillinger up with a CPU threshold at 75% CPU usage for 10+ seconds with a 10 second interval (be sure to save changes before proceeding):

Node

Sending N|Solid Notifications to Slack

Slack Node

After saving your threshold notification settings, you’ll need to set up tell N|Solid where to send the notification when the Threshold is triggered. Scroll down further in the threshold settings pane and select the Slack option; this will display a field where you'll enter your Slack webhooks URL:

To set up a Slack Incoming Webhook, check out this page and make sure the Slack team you want to send Threshold Notifications to is selected. On the page, select which channel you’d like your Threshold Notifications posted to - I chose #app-alerts in the NodeSource team:

Add the integration and *copy the URL on the page, *where the channel selector was. Then, head back to the N|Solid Console and paste that URL in the Slack Message option in the Actions section.

Once the Incoming Webhook URL is pasted in, you can scroll back to the top and you should be good to go with Threshold Notifications from N|Solid in Slack!

Taking Slack Notifications for a Spin

To test my notifications settings and confirm that alerts will be sent to Slack, I decided to throw some high CPU usage at Dillinger. Here's what the high CPU usage looks like in the N|Solid application dashboard:

And this is what I ended up receiving in Slack my #app-alerts Slack channel:

Wrapping Things Up

I can’t tell you how excited I am for this feature - it’s been something I’ve wanted to see for quite a while, and we’ve now landed it in N|Solid 2.3.

Slack Node

Huge props are due to Erin Spiceland for her extensive work on shipping the Slack and Webhooks integration, and the entire Engineering team for working to integrate and ship the new features in N|Solid 2.3.

It was a fantastic release, and we’re all looking forward to the next one.

Everyday I spend 30m checking stats from this blog, that’s 180 hours a year !

These stats are useful to know if my articles are relevant (if you quit now I’ll know it and be very sad… 👉👈).
But getting these stats is too long, I have to use Google Analytics, Stripe, my database, etc...
The good news is that I know how to get this data automatically, and I’ll teach you how, with a Slack Bot 🤖.

More precisely, we’re going to build a bot that tells me the money on my Stripe account. This money comes from the donations you make to me through Buy Me A Coffee at the bottom right of the page. We will use Node.JS, Slack API and Stripe API !

You can get the final code on GitHub or you can copy my Glitch project.

Here are the steps:

Slack Node Api

  • Creating a Slack Application
  • Coding a Slack Bot using Bolt.Js
  • Registering to Slack Events
  • Admiring the result !

Creating a Slack Application

To build a Slack Bot, we’ll need to create a Slack App.We have to choose a name and the workspace to install it:then we add permissions so that Slack knows what it has to allows us to do

  • app_mentions:read: allow to read messages that mention the app.
  • chat:write: allow to write messages.
  • im:history: allow to read direct messages to the app.

The full list of permissions is available in the scope section.Now we can install the app to our Slack Workspace !As a bonus, we can customize the app's name, description, color and icon:

Coding a Slack Bot using Bolt.Js

Now that we've created our bot, we can code its behaviors. We’re going to use Bolt.JS (the official framework to build Slack Apps) and Node.Js.To begin with, clone my project from Glitch.Glitch allows us to code our bot and make its code live. That’ll be useful to test the bot without deploying it on a server (you can also use Ngrok).To make this code work, we need our Slack API keys.

We have SLACK_SIGNING_SECRET in the Basic Information section:And SLACK_BOT_TOKEN in Install App:We also need the Stripe Secret API key, which you can find in your Stripe Dashboard:We can now enter your API Keys in the .env file:

Registering to Slack Events

The code in index.js has two parts:

  • Configure and launch the bot
  • Listen and respond to events

Bot configuration is done with the following:

The following code will listen to messages containing ”Am I rich yet?” and respond in the same channel with the total amount of dollars in the Stripe Balance:

If we try our bot now it’ll not work: We didn’t say to Slack which events we want to listen !We can do it in the Event Subscriptions section:We need to specify in the Request URL the HTTP address of our bot, which is GLITCH_URL/slack/events.
In my case: https://foul-cotton-medicine.glitch.me/slack/events.

Now, we can subscribe to 2 events:

  • message.im: We listen to messages posted to direct message channels
  • app_mention: We ONLY listen to messages that mention our bot.

Our bot is basically saying to Slack: “tell me when someone is sending me a direct message, but no other message”.

Node

Now, let’s go to our workspace:

woohoo! I’m poor!

Slack Nodes

Conclusion

Today, you built a Slack Bot that saved you minutes everyday ! Congrats ! 🎉

Slack Node Diagram

But it’s just the beginning. We only saw a bit of what you can do with a Slack Bot. Feel free to check the Bolt.Js documentation to see the possibilities !

You’d find it useful to deploy your bot on Heroku. Thankfully it’s as easy as it sounds, just don’t forget to update the Request URL of your event subscriptions.

Slack Sdk

Please let me know if you found this article useful and show me what you built on Twitter !





Comments are closed.