When you create a new automation on a site, you can select from various actions to execute after your automation is triggered. Available actions depend on the apps installed on your site and the selected trigger.
If the available actions don't meet your needs, you can create a custom action with functionality tailored to your site. Custom actions are site-specific and independent of any app.
You create custom actions in your site's dashboard using the automation builder. To customize the action's behavior, you use the Automations Actions service plugin, which allows you to add your own code directly in the automation builder.
You can use custom actions to:
Note: Custom actions currently require the use of a Velo service plugin API. While you can use the JavaScript SDK alongside the service plugin, the service plugin itself is implemented using Velo APIs and conventions.
You can implement custom actions using:
When you create a custom action, Wix creates a .js file for you to write your code. You then edit this file in a modal inside the builder.
Wix automatically populates the .js file with the following code:
You must write all your code inside the invoke() method. Wix calls this method each time the automation is triggered, and runs the code inside. It expects an empty object in return, so make sure to leave the return statement as it appears. To write your action code, use the JavaScript SDK APIs just like you would in your site's public or backend files.
When you create a custom action for the first time, Wix automatically adds the Automations Actions service plugin to your site's backend code. For every custom action you create, Wix also adds a folder containing a copy of the .js file from the builder.
Important: You can view your custom action code in the backend files of your site. However, all code must be added and updated directly in the automations builder. Any changes you make in the backend files aren't reflected when the automation runs.
Working directly in the automation builder allows you to:
Depending on the trigger you select, your action expects to receive a payload when the automation is triggered. You can view the payload structure under the Payload view tab while writing your code in the builder. The structure is read-only.
You can access payload data in your code with dot notation. For example:
To edit your action code, return to the automation in the builder and make your changes directly in the custom action modal.
The code file you create for your custom action is associated with the original trigger you selected. Editing the trigger configuration doesn't affect the custom action. However, if you change the trigger, a new code file is created and you'll have to write new code. The initial file you create is still saved, and if you restore the trigger it's associated with, you'll be able to access it again in the automation.