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:
In BusinessMate we will add:
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.
Figure 2. Create app from scratch
Next add an app name and select workspace, and then click on “Create App”.
Figure 3. Add a name and select workspace
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
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
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:
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
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:
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
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:
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
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);
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
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
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.
Start your 3 months of free trial now. Sign up and start your business flow right away
Get your business mate now