Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sendevent@1.0.0 Generic-ish transform to dump an entire context into a sendEvent call
// Merges the original context with the expected contract and then filters out the original context's properties
$ ~> | $ |
{
"instanceId": $.originatorId,
"event": "CONTINUE",
"context": $ ~> | $ | {}, ["originatorId"] |
}, [
$filter($keys($),
function($key) {
$key != "instanceId" and $key != "context" and $key != "event"
})
]
|
// Renamed "instanceId" to "originatorId" as to not confuse the instanceId of the parent machine (origin) and the child machine.
{
"originatorId": "12345",
"tenantId": "initech"
"firstName": "Steve",
"phoneNumber": "+14155551212",
/* ...whatever else you need in the payload */
}
// {
// "instanceId": "12345",
// "event": "CONTINUE",
// "context": {
// "firstName": "Steve",
// "phoneNumber": "+14155551212",
// "tenantId": "initech"
// }
// }
@scarabaeus
Copy link
Author

scarabaeus commented Aug 12, 2022

FYI The "function" is not a raw JavaScript function, but a JSONata evaluated function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment