Building Slack Apps with Tines: Part 1
Intro
Let's face it, most of us have wanted to build an app at one point or another. It often starts with a novel idea. You think, "The world needs this". And so, fraught with inspiration, you start feverishly building.

And then things happen. Maybe real life gets in the way. Maybe you find you need to learn an entirely new framework or acquaint yourself with a particularly frustrating API. Either way, problems mount. Development slows.

We need a way to maintain that momentum. A great way to do that is to lower the barrier to entry and simplify things so we can focus less on the other junk (infrastructure, app/play store requirements, hosting, etc) and more on the heart of our app (business logic, functionality, user experience, and so on).
Enter Slack
Let me start by saying it doesn't have to be Slack, we're simply starting with Slack. If you want to use Telegram, Teams, or another chat app entirely, by all means. Chances are I'll eventually do a guide on those as well. But until then...
Slack offers a great deal of functionality right out of the gate even for free plans. So if your goal is to simply develop an application with which your friends and family can interact, or automate aspects of your lives, I would say look no further.
In general, Slack's API is fairly easy to work with. But there are still a few nuances one should be aware of.
- 200 Isn't 100%: You'll often receive a 200 status code even if your call didn't succeed. Slack includes an 'ok' field in most responses, which is a boolean you should check to assess your success.
- It's OK to be a Blockhead: Eventually you'll probably need more sophisticated formatting for your messages. This is where blocks and attachments come in. These are essentially arrays of objects. We'll get into that down the road, but if you want to tinker be sure to check out Slack's handy dandy Block Kit Builder.
- Home is Where the Heart is: When you create an App, it comes with a Home page within Slack you (and your users) can access. You can publish something called 'Views' (more on that later) specific to each user. This is a phenomenal way to present persistent information specific to your end users and make actions available to them without worrying about individual shortcuts. Take a look at the docs and don't forget about this very powerful feature.
Tines
First - I am in no way affiliated with Tines. Anything I say or write is strictly reflective of my own viewpoints. That being said...
I come from a traditional AWS/Python background and let me just say - Tines has spoiled me. Tines is a magnificent no-code automation platform that abstracts an astounding amount of repetitive, thankless work to which we've all grown accustomed. The amount of time I've saved related to token retrieval, rotation, and revocation alone is considerable. And that doesn't compare to the amount of time saved spinning up Webhooks in Tines (which is criminally simple).
If you're in an enterprise environment and at all in the market for a SOAR platform or otherwise interested in doing a lot with a little - I would highly recommend giving them a shot.
I may write an article on the ins and outs of Tines, but until then give their docs and/or bootcamp a gander.
The cherry on top - They have a community edition in which users can build three free Stories (more on Stories some other time). Let me tell you: You can do a lot with a single Story (let alone three).
Prereqs
- A Slack account (sign up here )
- You built or are a member of an existing Workspace; I highly recommend creating one if you're just testing/tinkering (read more here)
Setting Up Our Slack App
Creating Our App
- Visit https://api.slack.com/apps and navigate to the "Your Apps" section to begin creating a new Slack application
- Click the "Create New App" button to get started
- Select the option "From Scratch"
- Give your app a name - choose something descriptive but remember you can modify it later if needed
- After filling in the app name and workspace, click the "Create App" button to move on

Adding Scopes
In order for us to install our new app, we'll need to first add at least one scope.
There are a couple of ways to know what scope(s) your bot will need.
-
Search the Permission Scopes Catalog for what you're trying to accomplish. For example, sending a DM to a channel is a very common goal. To do this, you would add the chat:write scope

-
Another option is to search Slack's Web API methods. You'll find the scope(s) you need under the method's 'Required scopes' field. Using our above example, we find we would need to use the chat.postMessage method. Which leads us to the same required scope (chat:write)

Your bot's permissions aren't set in stone - Slack makes it easy to add and remove scopes as you go based on what you're trying to accomplish. So for now, let's head to the 'OAuth & Permissions' section

Under Bot Token Scopes, we'll add the following scopes to start:
- chat:write (so we can send DM's to a channel of our choice)
- commands (so we can easily ask our bot to do things later on)
- channels:join (so our bot can join public channels in our Workspace)
Install the App
We're finally ready to install our app! Head back to the 'Basic Information' section, click 'Install to Workspace', then click 'Allow' on the next screen.

Before the next step, make sure you check out 'Install App' and grab your bot's 'Bot User OAuth Token'. We'll need it for the next section.

Create a Slack Channel
Back in Slack (it can be the Web version or the Desktop client), create a new Channel. This is where we'll be posting DM's later on.

Before we leave Slack - Let's make a note of our new Channel's ID as well. We get this by clicking into our channel, then on the down arrow next to its heading:

Now grab the Channel ID from the very bottom of the modal that opens:

One more, very important detail - Make sure to add your bot to your new channel. The easiest way to do this is by tagging the bot in a message to said channel. This will prompt Slack to ask you if you'd like to add the corresponding bot.

Scaffolding with Tines
Storing Our Token
Head on over to Tines and click 'Sign Up' if you don't already have an account - Otherwise, get logged in and start by creating a new Text Credential. Tines Credentials are essentially encrypted variables to which our Stories have access at runtime.
- Paste your 'Bot User OAuth Token' you got from Slack into the 'Value' section
- Make sure your allowed Domains only includes 'slack.com'
- Click save

Storing Our Channel ID
I don't know about you, but I won't remember our new Slack Channel's ID. Let's stick it in a Tines Resource so we won't have to. Tines Resources act like Global variables. We can use these to store JSON objects, files (such as CSV's), or just plain old text.

Building Our Story
Now we're ready to build! Create a new Story and configure the name, description, logo, and so on as you see fit.

Send a DM
Drag and drop an HTTP Request action onto your canvas and configure it according to the following parameters. Remember, anything appearing between '<<>>' indicates a Resource or Credential value. You can add these with the key combination 'ctrl + space' on Windows, or 'cmd + space' on Mac.
- URL: https://slack.com/api/chat.postMessage
- Content Type: JSON
- Method: POST
- Payload: {"channel": "<< RESOURCE.slack_ff_channel >>", "text": "Anything of your choosing."}
- Headers: {"Authorization": "Bearer << CREDENTIAL.slack_api_token >>"}
Click 'Run' and you should receive a DM in the channel you've configured!


If you're having any trouble configuring your Action, you can copy the JSON below and paste it right into your Story. Just remember to change the Resource and Credential names according to what you've setup in your Tines environment.
{"standardLibVersion":"37","actionRuntimeVersion":"4","agents":[{"disabled":false,"name":"Send Slack DM","description":null,"options":"{\"url\":\"https://slack.com/api/chat.postMessage\",\"content_type\":\"application_json\",\"method\":\"post\",\"payload\":{\"channel\":\"<<RESOURCE.slack_ff_channel>>\",\"text\":\"Winner winner :chicken: dinner\"},\"headers\":{\"Authorization\":\"Bearer <<CREDENTIAL.slack_api_token>>\"}}","position":{"x":585,"y":540},"type":"httpRequest","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"recordType":null,"recordWriters":[],"form":null,"cardIconName":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"originStoryIdentifier":"cloud:98bf19cf1391e1805daf0cbdc3239e4a:9f14dfcd7d12904a7c5651dbe89b3389"}],"links":[],"diagramNotes":[]}
Closing Thoughts, Parting Bots
Let's review what we've accomplished so far. We've:
- Created a brand new Slack app
- Provisioned scopes & permissions for our app
- Installed said app for our Workspace
- Created a dedicate channel
- Created a Tines Story for our app
- Sent our first DM using Tines

But that's really half the equation, right? We need to be able to receive input from our users, process it, and respond accordingly. Something like that would require interactivity - The very topic we'll be focusing on in Part Two.