Sequences
Configure and execute a serie of actions or sending messages, based on an event that occurred in the conversation.
Last updated
Was this helpful?
Configure and execute a serie of actions or sending messages, based on an event that occurred in the conversation.
Last updated
Was this helpful?
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.
To start a sequence, the following method is used, which can be called within an or in a callback in the class:
start_sequence(context_route=String)
Sequences are defined within the sequences()
method of a 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.
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)
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.
This functionality has a independent process that must be running by calling the following commands in terminal:
It can also be started with the other Kongo daemons like http
and schedule_messages
by running:
See the logs in logs/sequences.log
.
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 .