Skip to content

Instantly share code, notes, and snippets.

@scarabaeus
Last active August 12, 2022 22:46
Show Gist options
  • Save scarabaeus/59c11c747a3131eac9a881b8425a50b9 to your computer and use it in GitHub Desktop.
Save scarabaeus/59c11c747a3131eac9a881b8425a50b9 to your computer and use it in GitHub Desktop.
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

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