If the built-in Action connectors don't meet your needs then you can use one of the Custom Actions for greater control over how Clause responds to obligations that are emitted by your contracts.

Custom Actions allow you to use dynamic values in your integration. For example, the message sent to an interested party via email could include the value of a payment as computed by the Smart Clause®.

Currently, your custom action will need to also include any secrets or API keys that are required to perform the integration.

To configure a Custom Action:

  1. Select + Add Additional Action from the Smart Clause configuration panel.
  2. Choose Custom as the Action Type
  3. Select your Target from the drop-down menu
  4. Provide a transform object in the Transform field.

The Transform should be provided in the JSONata format. This format allows you to write expressions that will be evaluated at runtime to build the output object based on values in the Smart Clause response or obligation object.

Note that in the future you will be able to create default transformations graphically and will not need to understand JSON or JSONata.

The online JSONata test tool is great for testing your transformation before using it in Clause. 

How the transform works

To give you full flexibility to determine which values are locked into your contract and which values are stored externally, the transform combines the response object (referred to as response in the transform) and the event object (the raw obligation object that causes this Action to be processed).

Let's look at an example to understand how this works.

In this scenario we use the Fragile Goods sample to send messages to Slack broadcasting the payments due for each completed delivery.

Note that sample response and event objects for each of the Accord Project templates is available in the Accord Project template library.

Triggering a fragile goods clause will return the following value, we call this the response.

{
    "$class": "io.clause.demo.fragileGoods.PayOut",
    "amount": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 186.02,
        "currencyCode": "USD"
    },
    "transactionId": "06739290-bf4b-11e8-a73b-ed1e57c6b98c",
    "timestamp": "2018-09-23T16:09:18.649Z"
}

In order to allow Clause to perform a Slack notification we need to transform this object into a io.clause.outbound.physical.alerts.atticus.AtticusSlackMessage.

This integration model expects a JSON object that looks like:

{
    "$class": "io.clause.outbound.physical.alerts.atticus.AtticusSlackMessage",
    "url": "MY_SLACK_WEBHOOK_URL",
    "message": "MY_MESSAGE"
}
You can create a Slack Webhook by following the instructions at https://api.slack.com/incoming-webhooks

The following JSONata transform achieves the required transformation. See the JSONata docs for further guidance on how to construct your transform.

{
    "$class": "io.clause.outbound.physical.alerts.atticus.AtticusSlackMessage",
    "url": "https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZ",
    "message":"*Fragile Goods Payout*\n" & response.amount.doubleValue & " " & response.amount.currencyCode
}

Sample Transformations

To help you to get started here are some sample connection configurations that you can copy into Clause.

  1. HTTP Action
  2. Zapier via HTTP Action
  3. Stripe Action
  4. Ether Transfer Action
  5. Ethereum Transaction Action
  6. MQTT Publish Action