DEV Community

TJ-MD for WayScript

Posted on • Originally published at wayscript.com

Tutorial: Integrating your app with Slack in 3 Minutes

Introduction

In this tutorial, we will build a Slack messaging system for a web app using WayScript. We integrate Slack in a demo web app built using Flask 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.

Step One: Setting up WayScript

Select Build From Scratch from the Dashboard

Build from scratch

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

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

Webhook select

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

Step Two: Set up the Slack API

Drag the Slack module from the Library as the second step in your recipe.

slack step

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

slack channel

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

message select

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

bot

Step Three: Implement the Webhook in your Code

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

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

Here's a video of this tutorial featuring Jesse a co-founder of WayScript.

Top comments (0)