In this tutorial, we will build a Slack messaging system for a web app. We integrate Slack in a demo web app built using Flask with Python and pushing the data to Slack using WayScript.
The WayScript / Slack integration allows you to rapidly build a process for custom Slack messaging. This can be used for custom error reporting, status messaging, recording user interactions, and much more. With WayScript, you can get slack integrated into your code in 3 minutes.
Step One: Setting up WayScript
Select Build From Scratch from the Dashboard
In this example, we name the program 'Slack Reporter'. Pressing create brings you into the WayScript Editor.
Set up a Webhook API Trigger
We are going to pass data from our web app to WayScript via a POST Request api call. To set up your WayScript recipe to trigger when a request is recieved, drag in the 'Trigger' module from the Logic Modules.
Once you have dragged in the Trigger Module, change the trigger mode from Time to Web Hook.
To set up the Trigger Module, we want to tell the Module what data will be passed through the Webhook. For this example, we are going to pass a single string called 'Message'. Under Outputs, add a variable and name it Message. This message variable can now be used in later steps of your recipe (in this case we can pass the message to Slack).
Step Two: Set up the Slack API
Drag the Slack module from the Library as the second step in your recipe.
Next, select the channel you want to pass your message to.
Under Inputs, select your message variable as the message to pass to Slack.
Then, type in the name of your 'Bot'.
Step Three: Implement the Webhook in your Code
Your API Key and Program ID are available to copy and paste from the Trigger Module (see image above).
Now everytime your code executes, your bot will post your message to Slack!
The Slack API also allows you to send messages to Users not just channels. To do this, change the mode from 'Work with Channels' to 'Work with Users', then select the user to message.
The Trigger Module also lets you pass multiple variables not just one. Just comma separate these in your post request.