How to store scope data
Each of the three scopes which can be written to at runtime have an associated component for storing data on it:
These aren’t the actual names of the components, rather they are the signature property of their respective components. Signature properties give developers a shorthand way to refer to a component.
To store data in a scope, use the appropriate
*_set component. They accept either the name of a variable, or a dictionary of variable names and values. Both methods are described below.
Using a string
Many triggers and components will output data to
flow.result. Often you’ll want to move that value to another location, otherwise it will be overwritten the next time a trigger or component runs. This is such a common pattern that we’ve added some syntactic sugar to the
*_set components to make this even easier.
- SCOPE_set: VARIABLE
is equivalent to this:
- SCOPE_set: VARIABLE: (@ flow.result )
In this example, we ask the user for their name. Their response is stored at
flow.result, which we then save to
user.name using the
steps: - ask: What is your name? # The user's input is saved to flow.result - user_set: name # Set user.name to flow.result - say: Hello, (@ user.name )!
In this example, the Dialogflow trigger stores the matched intent at
flow.result, which we then move to
triggers: - integration: integration.dialogflow expect: dialogflow steps: - flow_set: intent - say: The intent is (@ flow.intent )
Using a dictionary
Sometimes the value you want to store is not located at
flow.result. Or you may want to set multiple variables at the same time. To do this, provide the
*_set component with a dictionary:
steps: - flow_set: foo: bar count: 1
Updated almost 2 years ago