From the course: Building Bots with Node.js

Subscribing to events - Node.js Tutorial

From the course: Building Bots with Node.js

Start my 1-month free trial

Subscribing to events

- [Narrator] At this point you should have End Rock as well as your application running. The events.epi of slack sends events that we are interested in, to a book URL. To finish our set up, we now have to configure this in Slack. So, first of all I'm going to copy this forwarding URL to https URL of End Rock, here in Vision Studio Code. Now I head over to the Slack api page form a reservation app. There, I click on add features and functionality and I click on Event Subscriptions. Then we'll now click or toggle the switch to enable events, and I will paste in the URL I just got from End Rock. Be careful to remove any spaces in front or the end. And, the route we created should be under bots/slack/events. And, if everything goes fine you should get this verified message. So, this means that this middle ware of Slack that we employed before, received the event and returned a reply that slack understood. Now, we want to subscribe to a few events. This is pretty handy, because it means that we don't have to listen to everything that happens in the workspace. We can select when we want to be notified. So, I scroll down, and I want to subscribe to bot events because we are a bot. I want to set the bot up in a way so, that a direct mention opens up a conversation. Very much like when you're talking to a real person on a public channel. So, I click Add Bot User Event, and there I select the first one app_mention. So, we will listen to all events that mention the bot user. After a conversation has been initiated I want to be able to continue it without having to mention the bot every time. So, I also have to subscribe to a few more message type events. So, I Add Bot User Event, and I will start searching for message and we want message.im that's a message posted in a dark message channel. And, also going to need, messages in private channels, message.groups. And, we also want the messages that go into regular channel. After this is done, let's not forget to save these changes, there is this button on the bottom right. Save Changes. Even though we haven't yet created handles for these events, we can already do a little test. So, I head over to my Slack book space. And, there I will now, mention the bot. We will say something like "Hi". And, you might now get a message that you actually have to invite Rasi to this channel so, I'm just clicking on invite them. Now, it's part of the channel, and I can now again, mention Rasi and write "Hello there". So, now when I look into my application in Vision Studio Code, So, I'm going back to the regular terminal, where node is running. I already see, this message coming in. So, I see an event of type app mention. And, it contains the text "Hello there". Aren't you curious how this request by Slack looked like, the wire, so, what really went through the tunnel, we can easily inspect that by going back to End Rock. And, there you see, this link to that interface, and I click on that. And, this interface let's me inspect really everything that runs through this channel. So, let's look at this first post request, so, this was the URL verification we did before when we installed or configured this event, and when we look further, we see now all the, different events that did run through this channel. So, End Rock also provides us with a very handy tool for debugging such back book requests. In the next video we will bring our right now very simple bot to life by sending a message back to the conversation in Slack.

Contents