Structure

Automation Cards are simple, invisible processes that execute logic internally. Depending on the Type you chose when creating the Card, you will have various differening methods available to you.

Triggers

Triggers will traditionally hook in to some system or logic that allows them to listen for data. For example, using a WebSocket, polling an external API, or even something as simple as setInterval. Regardless of how they decide they want to trigger, they will all call the same function to trigger the overall Automation to begin execution. For example:

async mounted() {
    await super.mounted();

    setInterval(() => {
        this.trigger(); // This call will begin execution of the Automation.
    }, 5000);
}

This is a very basic example of how Triggers function - more information, including I/O to other Cards, is covered in the Triggers documentation.

Conditions

Conditions, whilst not called until an Automation is triggered, are still able to use WebSockets and other asynchronous boot operations before reporting to the App that they are ready. This is done via the mounted method. Along with this, there is an asynchronous function that will be called when the Condition is being asked whether to resolve or not. For example:

async run(input) {
    if (true) {
        throw new Error('You shall not pass!');
    }
}

There isn't a whole lot that goes in to Conditions - but you can read further on how to report failures and prevent an Automation from proceeding on the Conditions documentation.

Actions

Much like Conditions, Actions are also able to asynchronously boot before telling the App that it is ready for execution. Also very similar to the Conditions footprint is the method of execution, called when an Automation is triggered and all (if any) Conditions pass. For example:

async run(input) {
    // Do any business logic here, such as posting a Tweet.
}

Given the wide range of integrated services in the CastHub Ecosystem, you can achieve a lot of interesting and complex operations with Actions. You can read about usage further in the Actions documentation.

How do I debug it?

Now that you understand the underlying structure of an Automation Card, let's go over how to debug it.

Flow and Debugging