How do I know what triggered my CC task?

I have a CC task that can be called from the App, triggered by a webhook or called from another CC task. How do I differentiate between these triggers in my CC task?

1 Like

One can differentiate which action triggred the task by inspecting the this.source property within the scope of the run function. Here is a list of all the availible options:

export async function run() {
    if (this.source == CloudCode.WEBHOOK) {
        // CC Task invokeed from Webhook
    } else if (this.source == CloudCode.EDITOR_TEST) {
        // CC Task invoked from Test Task Button
    } else if (this.source == CloudCode.ENQUEUE) {
        // CC Tasked invoked from anotherr CC task
    } else if (this.source == CloudCode.WEB) {
        // CC Task invoked from an HTTP Request
    } else if (this.source == CloudCode.APP) {
        // CC Task invoked from App
    } else if (this.source == CloudCode.IDP) {
        // CC Task invoked from a successful IDP attempt
    } else if (this.source == CloudCode.SCHEDULER) {
        // CC Task invoked from a schedule 
    }
}
3 Likes