โกCustom Actions
Getting Started with Custom Actions
Custom Actions are a powerful feature of our automation suite, allowing you to write and execute your own JavaScript code within automations. You can even share these Custom Actions with others!
Structure of Actions
A Custom Action comprises three parts:
Input: The data that you want to pass into the action. This is defined via the UI.
Output: The data that the action returns. This is also defined via the UI.
Script: The JavaScript code that processes the input and generates the output.
To learn more about Inputs and Outputs, see this article.
The Script
Your script will run inside a V8 sandbox environment, which supports ES2020 syntax and exposes standard JavaScript APIs (e.g., Math, String, Array, etc.).
Packages
In addition to vanilla JavaScript APIs, you can also import and use certain packages within your scripts. Currently, the following packages are available:
@compass/http
- Simplified HTTP request functionalities@compass/wallet
- Utilities to work with wallets@compass/api
- Query the Compass API easily@compass/cache
- Store and retrieve temporary data to be reused across automations@compass/utils
- Utility functions
Click on the links to access detailed documentation for each package.
Scripting Environment
The sandbox environment imports your script as a module, and it should export a function as default. This function receives a context
object as the first argument. The context.inputs
property contains the input values passed to the action, as defined by the inputs.
Your function (which can be asynchronous) should return an object with keys that match those defined in the outputs.
Example
Here is a basic example of a script that makes a GET request:
In this script, the url
is passed as an input, and the resulting data is returned as an items
output.
Custom Actions provide an incredibly flexible way to extend the capabilities of our automation suite, and we're excited to see what you'll build with them!
Last updated