Actions for the Capacitor Plugin
Airship Actions provide a convenient way to automatically perform tasks by name in response to push notifications, Message Center App Page interactions, and JavaScript.
An action describes a function, which takes an optional argument and performs a predefined task, producing an optional result. Actions may restrict or vary the work they perform depending on the arguments they receive, which may include type introspection and runtime context.
The Airship SDK includes built-in actions for common tasks, and you can create custom actions to extend functionality.
For a complete list of available built-in actions, see the Actions User Guide.
Running Actions
You can run actions programmatically using the Airship.actions.run() method. The method returns a Promise that resolves with the action result. The action value can be a string, number, boolean, null, object, or array.
// Run an action with a string value using async/await
try {
const result = await Airship.actions.run("action_name", "action_value");
console.log("Action result:", result);
} catch (error) {
console.error("Action error:", error);
}
// Run an action with an object value
try {
const result = await Airship.actions.run("action_name", {
key: "value",
number: 42
});
console.log("Action result:", result);
} catch (error) {
console.error("Action error:", error);
}
// Run an action without a value
try {
const result = await Airship.actions.run("action_name");
console.log("Action result:", result);
} catch (error) {
console.error("Action error:", error);
}
// Run an action using Promise.then()
Airship.actions.run("action_name", "action_value")
.then((result) => {
console.log("Action result:", result);
})
.catch((error) => {
console.error("Action error:", error);
});Custom Actions
You can register custom actions with an Airship extender and with native SDK APIs. See the native platform documentation for details:
Categories