The core of stack.yaml, our auto-generated stack file, should look like this:

We need that location part to pull from the move-to-stack fork of Twilio-Haskell which works with the dependencies of all the other packages.

Get Started with Slack Apps

First, let’s go to https://api.slack.com. Then, click Your Apps in the top right-hand corner. You should see a page like the one below, and then click Create New App.

Pick a name for your bot and pick one of your Slack channels to deploy the bot to. Many groups now have a channel dedicated to testing bots. That’s one channel you could use. You should see something like this image below, which asks for your app name and a team you’re in (like a hackathon you were in, a class you took, a team you were on, or your company):

Click Create App, and then under features on the left-hand side, click on Webhooks. Make sure Activate Incoming Webhooks is on, and then scroll down and click Add New Webhook to Team. That page should look something like this:

You should then see a page asking to confirm your identity. Pick the channel you wish to post to, click Authorize, and you should then see this page:

Copy this webhook URL and paste it into a new file in our project called hook.

Sweet! Now, again on the left column of your app’s page, under Features go to Slash Commands. Click Create New Command, and you should see this following page:

Fill in the text boxes above however you wish. The slash command /redditbot will be followed by a word that is searched for on Reddit. The bot will search Reddit and return a trending post about the word you searched for. Let’s check if the slash command registered. Save your project, open Slack, go to the team and channel you used above, and try your slash command:

If you don’t see the command auto-complete, then go back to Create New Command, check each step, and try again.

Haskell Code: Building the Slack Bot

Now it’s time to examine some code. You will see a lot of packages and libraries imported into our project at the top of Main.hs. Let’s go over the functions our project already has.

First, we have readSlackFile which takes in our hook file and formats it into a type we want–in this case, one of IO Text. We need to read this file to send our message on Slack. Then configIO actually calls the function.