Sequences

Configure and execute a serie of actions or sending messages, based on an event that occurred in the conversation.

All the sequences that are needed can be created, in any context of the conversation. But only one will remain active per user at any given time.

Can be very useful when it comes to sending reminder messages in the development of a sales funnels for instance.

Start a sequence

To start a sequence, the following method is used, which can be called within an action block or in a callback in the Conversation class:

start_sequence(context_route=String)

Start a sequence in the same context

start_sequence "sign_up_sequence"

Stat a sequence in a different context

start_sequence "profile/sign_up_sequence"

Executing actions

Sequences are defined within the sequences() method of a Context class by calling the following method:

sequence(sequence_name=String|Symbol, &block)

In turn, this will receive as parameters the name of the sequence and a block with one or several calls to the past() method, one for each action of the sequence.

past(time_elapsed=ActiveSupport::Duration, &block)

This last method will execute the code in the block argument, when the time defined in the time_elapsed argument has elapsed since the start of the sequence.

Stop a sequence

It will stop automatically after the execution of the last block in the sequence, but if it's necessary to stop it prematurely, the following method can be called:

stop_sequence(sequence_name=String|Symbol)

Full Example

The example below will attempt to get the user to complete the registration process by sending two reminders: one at 20 minutes and one at 3 hours.

In case the user does the registration process, we will stop the sequence prematurely.

Sequence daemon

This functionality has a independent process that must be running by calling the following commands in terminal:

Foreground

Background

With other Kogno's processes

It can also be started with the other Kongo daemons like http and schedule_messages by running:

Logs

See the logs in logs/sequences.log.

Configuration

It could be the case when after the activation of a sequence, a user continues the conversation with the app and in between, receives a programmed message from an active sequence.

To avoid this problem, define the minimum time elapsed since the last message from the user, that the sequence must wait in order to execute the next block, by modifying the configuration file config/application.rb.

Last updated

Was this helpful?