Conditional statements allow you to specify when a particular content item or forwarding or redirecting path will be selected.
Example usages:
- You want to provide a specific response a particular slot is not provided to then prompt for the slot value
- You want to provide a specific welcome message, by using a segment, depending on when the user was last seen
- You want redirect a user to another handler depending on if they have linked their account or not.
The following is a list of popular functions that are available. All of these return either true or false, some take parameters and some do not. You can use these functions to create a conditional strings.
They can be simple, such as a conditional if the user has been active within the last two months
activeWithin(2, "months")
or not active within two months, notice the leading exclamation point to negate the boolean the function returns:
!activeWithin(2, "months")
They can also be more complex, this is for a user that is starting a session and has not linked their account yet:
isNewSession() && !hasLinkedAccount()
The following is a list of popular functions that are available.
Active Within
The user has been active within the provided amount. This can be used to provide a response to a user that has used the application before but are coming back after some time and need a refresher.
activeWithin(amount: number, format: DurationFormat)
For example, the user is active within the last five days.
activeWithin(5, "days")
The available formats are "years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds".
Fits Schedule
The current time for the user fits within the provided schedule.
fitsSchedule(start: string, startFormat: string, durationAmount: number, durationFormat: string, timeZone?: string)
fitsSchedule("2019-09-11T00:00", "YYYY-MM-DDTmm:ss", 5, "days")
Is Request Type
isIntentRequest()
isLaunchRequest()
isInputUnknownRequest()
Note: These do not have parameters.
Request IDs
To match based on the ID of the request:
isRequestID(id: string | string[])
You can either provide a single string or an array of strings.
isRequestID("LaunchRequest")
or
isRequestID(["FooIntent", "BarIntent"])
which will return true for either of the two IDs provided.
Slot Exists
hasSlot(name: string)
slotExists(name: string)
slotEquals(name: string, value: string)
slotEquals("university", "University of Virginia")
Common Patterns
Slot filling
slotDoesNotExist("required_slot_name")
Required condition and one of two possibilities
REQUIRED && (OPTION_1 || OPTION_2)
fitsSchedule("2019-09-11T18:40", "YYYY-MM-DDTmm:ss", 210, "minutes") && ( slotEquals("team", "one") || slotEquals("team", "two")
Comments
0 comments
Please sign in to leave a comment.