Creating a Slack Bot in 10 minutes or less

Creating a Slack Bot in 10 minutes or less

All of a sudden the world is going crazy over chat bots, with some going as far as saying it will be the next revolution. I call this bull, and have the Google trends to prove it.

Nevertheless, I really like making bots so here a quick guide on how to get yourself a Slack bot up and running in no time.

Step1: Get a connection token

Go to your team settings page and create a new bot. We are looking for the API token to use in our code.

Step2: Getting your WS endpoint

So the Slack way of doing things is pretty sweet, it uses a Real Time Messaging API to communicate. You first need to do a simple HTTP GET call to get your endpoint, and then use a Websocket to connect to it.

You can use any coding language, but since you will be connected for (hours,days,months,years) it's best to use something that is designed to run for a long time. We will be using Node.js in this example.

Step3: Connecting to the API

Once you have the correct endpoint, all that remains is to connect to the well documented API.

This will emit the 'rawmessage' event every time something comes in over the socket. Let's capture it:

That's really all there is to it ... Github link here.

About Lumturio
It is our wish to offer advanced security monitoring to all CMS users worldwide; we believe that the future is online and that if we want that future to be bright everyone and everything deserves to be secure.

Read more stories here.

 

要查看或添加评论,请登录

Sam Hermans的更多文章

社区洞察

其他会员也浏览了