Table of Contents

Setup communication with Slack and BusinessMate by using weebhooks and subscription event part 1

In this document we will guide you how to setup webhooks for both Slack and BusinessMate (BM), so both applications will be able to send and receive messages.

We will build a Slack app that will consist of:

  • Incoming webhooks
  • Event subscriptions

In BusinessMate we will add:

  • A table with a workflow to reply to slack
  • Weebhooks
  • A workflow to handle messages from Slack

 

Create an app in Slack

Login into your workspace in slack and then go to App Directory: https://api.slack.com/apps 

Click on the “Create New App”.

Figure 1. App Directory, create new app

We are going to build the app from scratch, but you can also build the app from a manifest file.

Slack configure

Figure 2. Create app from scratch

Next add an app name and select workspace, and then click on “Create App”. 

Slack configure

Figure 3. Add a name and select workspace

Add incoming webhooks in Slack

Now you should see a page with basic information about the app.

To add a webhook, go to the “Incoming Webhooks” on the side menu.

Figure 4. Basic information

Slack webhook url

On the right top corner switch to on and longer down click on “Add New Webhook to Workspace”.

Then copy the webhook URL and save it.

Figure 5. Incoming Webhook

Create a table in BM

Now go to BusinessMate and login into your account. On the home/default page we can add a table by clicking on the top right button “New Table”.

Figure 6. Create new table in BusinessMate

We are going to call the table “Message Handler”, you can also choose your own name for the table.

Click save to create table.

Figure 7. Naming the table

Next, we are going to add three fields to the table:

  • Short Text: name
  • Short Text: reply
  • Timeline: chat

You can drag and drop the fields from the right menu then give a name to the field.

After adding the fields clicked the save button.

Figure 8. Manage Forms

Create workflow to send messages

We can now add a workflow to send messages to Slack.

Go to the table “Message Handler” and right menu next to add record click on “Workflows”.

Figure 9. Go to workflows page

 Now create a new workflow by clicking on the “New Workflow” button on the right.

Figure 10. Create workflow

We are going to add two steps:

  • Run Script: write to slack
  • Update Record: reset reply (remove reply after send)

Drag and drop the steps into the workflow and then connect them. From the begin step click on the circle and drag the arrow to the run script, and from the run script to update record. 

Figure 11. Add workflow steps

Set begin step

We want to active the workflow when we write a reply.

So, click on the begin step and then the step menu will popup.

For the trigger turn on the “On Update” and mark the “reply” field.

Figure 12. Set trigger in begin step

To not activate the workflow on every record, we are going to add two filters:

  • name is “slack”
  • reply is not empty

In the begin step go to filters menu and then click on the “Add filter” button in the left bottom.

Select the two fields and set the filters.

 The form uses dropdowns, so it is easy to select fields.

When the two filters are added then click on the “Done” button in the bottom right corner.  

Figure 13. Set filters in begin step

Set run script

Now copy the code example to right and go to the run script step.

Paste the code and replace “slack-webhook-url-here” with your Slack webhook URL from chapter 3.

It is optional to add description but for readability reasons we are going to add following text: “write to slack”, so it is easier to see which step does what.

When finish then click on the done button.

Code example: Write to Slack Webhook

        
const axios = require('axios'); const data = { "text": currentRecord.f_reply, } const res = await axios({ method: 'post', url: `slack-webhook-url-here`, headers: { 'Content-Type': 'application/json' }, data }); console.log(res.data);

Set update record step

We can now go to update record step.

This step will add the reply to the chat and reset the reply field.

Add and select the field “chat” then click on the <> icon to right. This will allow us to add code expressions into these fields.

In the “Add message” bar write: currentRecord.f_reply
Do the same for reply field but write in the “Value” bar: null

When finish click on the done button.

Figure 14. Update current record

Activate workflow

To finish the workflow, connect update record step with the end step.

Add a name to the workflow, we are going to called it “reply to slack”.

At last we can activate the workflow in the activate button in the bottom right.

Figure 15. Activate workflow

Create new record

We will now add the record that will receive and send message to Slack.

Go to the table “Message handler” and click on “Add Record” button on the right.

Figure 16. Add record

Write “slack” in name field and click save.

 

Figure 17. Set record parameters

This is the end of first part and next part will cover event subscription for slack and webhook for BusinessMate.