Functions
Using functions, you can provide custom code and link it to your event sources, automations, or snap-kit actions. Functions are written in JavaScript and can be used to transform events, send notifications, or perform any other custom logic including network calls.
In order to create a snap-in version, functions must be defined as shown in the code samples. Functions are packaged and provided as an artifact at the time of snap-in version creation and then used to deploy functions to snap-in versions. An artifact may contain multiple function definitions. The artifact is a zip file containing the following files:
Function manifest
The function manifest consists of the following fields:
name
: It is the function name that should match the corresponding function name in the folder.description
: It describes the function.
Synchronous execution with synchronization key
To ensure that function executions are processed in order, FIFO, for a given context such as a user or conversation, enable synchronization support in your function’s manifest and use a synchronization key, sync_id.
The platform uses the sync_id as the message group for FIFO processing. This ensures that all executions with the same sync_id are processed in order, preventing race conditions or duplicate conversations. Use cases for synchronous execution include:
- Ensuring order of message processing for chatbots or messaging integrations.
- Preventing duplicate or out-of-order actions when multiple events are triggered.
To enable this:
-
Enable synchronization in manifest
- In your function’s manifest, add the field:
- This tells the platform to use a FIFO queue for this function.
- In your function’s manifest, add the field:
-
Set the synchronization key
-
When triggering an automation, include the sync_id in your rego policy along with the
event_key
. For example:rego -
The sync_id groups related executions for ordered processing.
-
-
Execution behavior
- If
supports_synchronization
is true and a sync_id is provided, executions with the same sync_id are processed in order. - If no sync_id is provided, executions are grouped by a random string.
- If
supports_synchronization
is false, the sync_id is ignored and executions are processed as usual.
- If
Each function should be registered in src/function-factory.ts
to be available for execution.
Refer to the function invocation for details about the exact payload of the function.