Creating a workflow

Creating a slack hook from a contact form

Introduction

In this tutorial, we will create a workflow that will send a slack message when the webhook is called by a contact form. In the next tutorial we will then add the sending of an email to the workflow.

Workflows allow the chaining of api requests while keeping state. Here we will put to chain units into our chain. The first will take the inputs of the contact form and create a string. The second will post this string to a slack channel. This string can be then be modified via the CMS interface.

Add CMS entry

Create a new CMS entry (from the Product Factory menu). This will correspond to the message that you will receive on Slack. The text encapsulated by ${..} are variables that we will later map from our form to our slack message.

Key: Contact form slack hook
Message: Name: ${name} ; email: ${email} ; subject: ${subject} ; message:${message}

Add API request

We will now add an API request to map the parameters from the web form to the parameters in our slack message.

First create a new request (Low code menu). The /cms/substitute endpoint is a utility function provided by Digis that makes it easy to create custom strings during a workflow.

Host: `https://workflow.digis.io`
URI: /cms/substitute
Method: POST
Label: Contact form to message

We can test it with the following request:

POST https://workflow.digis.io/cms/substitute

Query Parameters

NameTypeDescription

params

string

Dictionary where keys are the variables from the cms entry and values are the substitute values

uuid

string

The uuid of the cms entry

{
    "title": "",
    "message": "Name: name ; email: email ; subject: subject ; message:message"
}

Create mappings

The next step is to define the mappings of the API request.

Add an input for each parameter (email, name, subject, message) using the following schema:

Name: params.email
Body Type: payload
Name Override: `email`

We then also need to add some extra inputs for authorisation and to specify the uuid to use.

For authorisation, you can use the following settings:

Name: Authorization
Body type: Headers
Default value: ...

For the uuid, you need to take the uuid of the cms entry (copy it from the url) and create an input as follow:

Name: uuid
Body type: Payload
Default value: <uuid>

Next we have to add an output:

Name: message
Body type: Payload
Name override: msgOut

We can test with the following request

POST https://workflow.digis.io/request/exec

Path Parameters

NameTypeDescription

params

string

{"uuid": "<uuid of request>"}

Query Parameters

NameTypeDescription

data

string

Dictionary of variables and substitute values

{
    "msgOut": "Name: name ; email: test ; subject: subject ; message:message"
}

Create a slack request

Create a new API request

Label: slack:send message to channel
host: https://hooks.slack.com
URI: <slack hook uri>
Method: post

Add the following inputs:

Type: In
Name: text
Body type: payload

Make sure the text input then has name override set to msgOut

Type: In
Name: channel
Body type: payload

Create an API request chain

Next we have to add an api request chain to link the request together. Create a new chain (Name: Landing page - contact form).

Add a chain unit:

Name: Contact form to message
Request: Contact form to message

Add another chain unit

Name: slack:send message to channel
Request: slack:send message to channel
previous: Contact form to message

We can test with the following request:

POST https://workflow.digis.io/request/chain/exec

Path Parameters

NameTypeDescription

params

string

{"uuid": "<uuid of request chain>"}

Query Parameters

NameTypeDescription

data

string

Dictionary of variables and substitute values

{
    "email": "test",
    "name": "name",
    "subject": "subject",
    "message": "message",
    "msgOut": "Name: name ; email: test ; subject: subject ; message:message"
}

Using the workflow webhook

We can now use the workflow webhook from the cloud. Simply call it as described above. Here is an example body

{
	"params": {
		"uuid": "<chain uuid>"
	},
	"data": {
		"email": "test",
		"name": "name",
		"subject": "subject",
		"message": "message"
	}
}

Troubleshooting

You can test each of the individual steps of the chain as shown above in the examples.

N.B. currently the product service must be restarted to take into account changes in the workflows

Last updated