Writing actions
Actions are the foundation of tools built with Interval. Actions are just async functions which means anything you can do within a JavaScript function is possible within an action. And by extension, if you know how to write JavaScript functions, you know how to write Interval actions.
But actions have access to special functionality that other functions don't, namely they can:
- be run by a member of your organization from the Interval dashboard,
- collect input and display output through I/O methods,
- and send push notifications to members of your organization.
Defining an action
Actions are identified by slugs that are defined in your code and are unique to your organization.
An action can be defined in two ways. The simplest and most common is to provide an async function as the value in your key:value map of actions. If you want to set additional metadata for an action in code, you can specify an object containing a handler
function instead:
import Interval from "@interval/sdk";
const interval = new Interval({
apiKey: "<YOUR API KEY>", // get an API key at https://interval.com/dashboard/develop/keys
actions: {
refund_user: async () => {
// action logic here
},
import_data: {
handler: async () => {
// action logic here
},
name: "Import data",
description: "Imports data.",
backgroundable: true,
},
},
});
interval.listen();
Did this section clearly explain what you wanted to learn?