16 Feb 2023: More possibilities for scheduling stacks

Neelke Stadler Updated by Neelke Stadler

A stack can schedule the execution of another stack (or itself) at some time in the future. This is useful to automatically sent a notification, say, 2 days from now.

Sometimes you need to remind people of things or check in on how they are doing. Stacks allow you to schedule a notification to automatically be sent in the future.

Remember if your message is scheduled to be delivered in more than 24 hours you can only initiate the conversation using an approved template.

Let's look at the scheduling options in stacks.

A stack can be scheduled using either the in argument or the at argument.

Scheduling based on relative time (in seconds)

The in argument requires a relative time expressed in seconds. The scheduled stack will execute after the number of seconds specified.

schedule_stack("<uuid-of-the-stack-to-schedule>", in: seconds)

Scheduling at an exact time

The at argument requires an exact date, in a datetime format. This date can be expressed using one of our expressions. The scheduled stack will execute at the date and time that has been defined.

If you wanted to schedule a stack exactly two days from now you could do:

schedule_stack("<uuid-of-the-stack-to-schedule>", at: datetime_add(now(), 2, "D"))

Scheduling at an exact time but relating to another date

Or if you wanted to schedule a stack to run at 9am, the next Monday after a certain date you could do:

base_date = date(2023, 2, 08))
schedule_stack("<uuid-of-the-stack-to-schedule>", at: datetime_next("monday", "09:00", base_date))

Cancelling a scheduled stack

A stack that was previously scheduled can also be canceled, using our cancel_scheduled_stacks function:

card TextCard, then: MaybeCancel do
schedule_stack("<uuid-of-the-stack-to-schedule>", at: datetime_next("monday", "09:00", base_date))
schedule_stack("<uuid-of-the-stack-to-schedule>", at: datetime_next("tuesday", "09:00", base_date))
keep_going = ask("Do you want to keep receiving these messages? Type STOP to cancel them")
end

card MaybeCancel when keep_going == "STOP" do
cancel_scheduled_stacks("<uuid-of-the-stack-to-cancel>")
end

card MaybeCancel do
schedule_stack("40ac549a-a883-4c26-b3a2-6eaf8f799edb", at: datetime_next("friday", "10:00"))
end

Please note that this function cancels all scheduled stacks with the given UUID for that recipient, so in the example above, both scheduled stacks would be canceled.

More documentation and examples

Was this article helpful?

9 March 2023: More data in BigQuery!

13 Feb 2023: Automatically mark messages as DONE

Contact