$reactions.timeout
This method sets a timeout — an automatic transition to another state if there is no input from the user.
Syntax
$reactions.timeout({ interval: 10, targetState: "/Start/Timeout" });
$reactions.timeout({ interval: "10 seconds", targetState: "./Timeout" });
The method accepts an object with the following properties:
interval
— the time interval during which input from the user is expected.targetState
— the state where the bot will switch to if there is no user input during this time.
Interval format
The value of interval
can be either a number or a string.
- As a number, it means the timeout duration in seconds.
- As a string, it signifies the timeout duration in human-readable format.
An interval cannot exceed 99 hours.
String values of interval
must be matched by the following regular expression:
(\s*(?<h>\d{0,2})\s*(hours|hour|h))?(\s*(?<m>\d{0,2})\s*(minutes|minute|min|m))?(\s*(?<s>\d{0,2})\s*(seconds|second|sec|s))?\s*
Examples of interval
string values
5 seconds
1 sec
3s
1 min
1 minute
10 minutes
1 hour
10 hours
3 min 1 sec
1h5m3s
Usage details
Only one timeout can be active at a time. If the method is called multiple times in the same state, the script will produce an error.
How to use
In the following example, the bot asks the user to rate the service.
- If the user gives a rating, the bot records it to analytics using the
$analytics.setNps
method and says goodbye. - If the user fails to give a rating for 5 minutes, the bot gives up waiting and proceeds to say goodbye by its own.
state: ServiceEvaluation
a: Thank you for your time. How would you rate your experience with us?
script: $reactions.timeout({ interval: "5 minutes", targetState: "/Goodbye" });
state: GetEvaluation
q: $regex<\d+>
a: Thank you. Your opinion is very important to us.
script: $analytics.setNps(parseInt($parseTree.text));
go!: /Goodbye
state: Goodbye
a: Take care and goodbye!