The new Slack platform is in beta. Your feedback is most welcome.

Scheduled Triggers

Invoke a Workflow at specific time intervals

Scheduled Triggers are an automatic type of Trigger. This means that once the Trigger is created, they do not require any user input.

Need a Workflow to happen on a daily, weekly, or annual cadence? A Scheduled Trigger is your best bet.

There are two steps to setting up a Scheduled Trigger:

  1. Define the Trigger
  2. Create the Scheduled Trigger, either via the CLI or at runtime

1. Define the Trigger

A Trigger contains a Typescript payload with the following parameters:

Parameters

Field Description Required
type The type of Trigger: scheduled
name The name of the Trigger
workflow Path to Workflow that the Trigger initiates
description The description of the Trigger
inputs The inputs provided to the Workflow
schedule When and how often the trigger will activate. See below

The schedule object

Field Description Required
start_time A date string of the first scheduled trigger
timezone timezone string to use for scheduling
frequency details on what cadence Trigger will activate. See below
occurrence_count The maximum number of times Trigger will run
end_time if set, this Trigger will not run past the provided date string

The frequency object

Field Description Daily Weekly Monthly Yearly
type How often the Trigger will activate. Can be daily, weekly, monthly or yearly
on_days The days of the week the Trigger should activate on
repeats_every How often the Trigger will repeat, respective to frequency.type
on_week_num The nth week of the month the Trigger will repeat

The inputs object

Pass any of these values into a Workflow's inputs!

Field Description Required
type The type of Trigger: scheduled
team_id A unique identifier for the workspace/team where the Trigger occurred.
enterprise_id A unique identifier for the enterprise where the Trigger occurred.
event_timestamp A UNIX timestamp in seconds indicating when the Trigger occurred.
data.user_id A unique identifier for the user

Example TypeScript payload

The following is a TypeScript payload creating a Scheduled Trigger:

  name: "Example",
  type: "scheduled",
  workflow: "#/workflows/example",
  inputs: {
    example: { value: "example" },
  },
  schedule: {
    start_time: "2022-03-01T14:00:00Z",
    end_time: "2022-06-01T14:00:00Z",
    timezone: "UTC",
    frequency: {
      type: "monthly",
      on_days: ["Monday"],
      on_week_num: 3,
      repeats_every: 2,
    },
  },

2. Create the Scheduled Trigger

There are two ways to create a Scheduled Trigger. You can:

Create a Scheduled Trigger with the CLI

To create a Scheduled Trigger with the CLI, you'll need to create a trigger file. The trigger file contains the payload you used to define your Trigger.

TypeScript trigger files take the following form:

import { Trigger} from “deno-slack-api/types.ts”;

const trigger : Trigger<typeof ExampleWorkflow.definition> = {
  // your TypeScript payload 
}

export default trigger;

Once you have created a trigger file, use the following command to create the Scheduled Trigger:

slack trigger create --trigger-def "path/to/trigger.ts"

Create a Scheduled Trigger at runtime

Create a Scheduled Trigger at runtime using the client.workflows.triggers.create method within the relevant Function file.

const triggerResponse = await client.workflows.triggers.create<typeof ExampleWorkflow.definition>({
  // your TypeScript payload
});