Tutorial: Integrating your app with Slack in 3 Minutes
Tags: tutorial, python, flask, slack
Published: 2020-05-06 13:39:13

---
title: "Tutorial: Integrating your app with Slack in 3 Minutes"
canonical_url: https://wayscript.com/learn/integrating-slack-3-minutes
---
##Introduction
In this tutorial, we will build a Slack messaging system for a web app using [WayScript](https://wayscript.com/). We integrate Slack in a demo web app built using [Flask](http://flask.pocoo.org/) with Python and pushing the data to Slack using WayScript.

*If you prefer to watch vs. read, check out the video at the bottom of this post*

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.

[Here is a GitHub Repo sample server you can use for testing.](https://github.com/wayscript/code_snippets/tree/master/flask_demo)

##Step One: Setting up WayScript
Select Build From Scratch from the Dashboard

![Build from scratch](https://cdn.wayscript.com/blog_img/35/build_from_scratch.png)

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 received, drag in the 'Trigger' module from the Logic Modules.

![trigger](https://cdn.wayscript.com/blog_img/35/drag_trigger.png)

Once you have dragged in the Trigger Module, change the trigger mode from Time to Web Hook.

![Webhook select](https://cdn.wayscript.com/blog_img/35/webhook_select.png)

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).

![slack](https://cdn.wayscript.com/blog_img/35/trigger_output.png)

##Step Two: Set up the Slack API
Drag the Slack module from the Library as the second step in your recipe.

![slack step](https://cdn.wayscript.com/blog_img/35/slack_step.png)

Next, select the channel you want to pass your message to.

![slack channel](https://cdn.wayscript.com/blog_img/35/slack_channel_select.png)

Under Inputs, select your message variable as the message to pass to Slack.

![message select](https://cdn.wayscript.com/blog_img/35/slack_message_select.png)

Then, type in the name of your 'Bot'.

![bot](https://cdn.wayscript.com/blog_img/35/create_bot.png)

##Step Three: Implement the Webhook in your Code
```python
import requests
import json
​
def send_to_slack( message ):
    url = 'https://wayscript.com/api'

    params = { 'api_key'    : '',  #TODO, Insert API KEY 
                     'program_id' : 0,  #TODO, Insert Program ID
                     'variables'  : json.dumps( [ message ] ) }
​
    requests.post( url, params = params ) #This sends the message to your 
WayScript Script
```

Your API Key and Program ID are available to copy and paste from the Trigger Module (see image above).


Now every time your code executes, your bot will post your message to Slack!

![slack post](https://cdn.wayscript.com/blog_img/35/slack_post.png)

##Other
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.

Let us know your thoughts in the comments below or to our [Discord](https://discord.gg/nchf9E9) channel.

Here's a video of this tutorial featuring Jesse a co-founder of WayScript.
{% youtube aVl-ixd7gL8 %}