Using Automate to create workflows

Automate is a tool for integrating cloud applications, automating marketing, sales and business processes. This guide demonstrates how you can use Serialized Reactions to trigger Automate workflows every time a specific event is stored in Serialized.

Our goal is to receive an email every time a CaptureCompleted event of aggregate type payment is stored in Serialized.

Setting up Automate

Sign up or log in to Automate and click Create a Bot.

Step 1 - Select trigger app

Click the “Webhooks” icon and choose “Incoming Hook”.

Step 2 - Setup webhook

Click “Setup webhook” and copy/write down the URL displayed in the popup window.

Click “I’m Done” - The webhook will now wait for you to post some test data.

Open a terminal/command prompt and send the following POST request:

curl -i https://wh.automate.io/webhook/<your-key> \
  --header "Content-Type: application/json" \
  --data '
  {  
    "value1": "Test1",
    "value2": "Test2",
    "value3": "Test3",
    "value4": "Test4",
    "value5": "Test5",
    "value6": "Test6",
    "value7": "Test7",
    "value8": "Test8",
    "value9": "Test9"
  }
'

When the request has been received by the webhook, inspect the data and click “Looks Good” to close the popup.

Step 3 - Select action app

Click the “Select Action app” dropdown and click the “Email” icon.

Click the “Send and Email” action.

Enter your email address in the “To” field.

Enter a subject, eg. “Payment notification”

Now, drag n’ drop the “value1” field from the “Output Fields” list into the “Email Body” box.

Step 4 - Save and activate the Bot

Click “Save” and toggle to Bot “On”.

Step 5 - Creating the Serialized Reaction definition

We need to tell Serialized to subscribe to the feed created by the aggregate type payment and to react to all events of type CaptureCompleted by POST:ing to our Automate webhook. The targetUri should end with your generated webhook key you received in the previous steps.

Serialized Automate integration supports up to nine variable values:

{ "value1" : "", "value2" : "" ... "value9" : "" }.

Simple templating is supported and event data can be accessed using dot (.) notation.

curl -i https://api.serialized.io/reactions/definitions \
  --header "Content-Type: application/json" \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  --data '
  {
    "reactionName": "automate-payment-notifier",
    "feedName": "payment",
    "reactOnEventType": "CaptureCompleted",
    "action": {
      "actionType": "AUTOMATE_POST",
      "targetUri": "https://wh.automate.io/webhook/<your-key>",
      "valueMap": {
        "value1": "Payment made by ${event.data.customerId} with amount ${event.data.amount}."
      }
    }
  }
'

Step 6 - Store an event and trigger the workflow!

Now it’s time to trigger the Reaction and the Automate workflow. Let’s post an event to Serialized!

curl -i https://api.serialized.io/aggregates/payment/fea1934e-90ad-469d-b557-cf63d122cd60/events \
  --header "Content-Type: application/json" \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  --data '
  {  
     "events": [
        {  
           "eventType": "CaptureCompleted",
           "data": {  
              "customerId": "some-test-id-1",
              "amount": 12345
           }
        }
     ]
  }
'

Open up your mailbox and voila!