How to efficiently reference variables
A variable is a field that you can access during a conversation. Intent parameters are an example of variables.
Why use variables?
Variables allow you to personalize conversations based on user input or the external environment. For example, in a "check weather" scenario, the intent parameter "city" is a variable. This is because a user might provide different cities in response to the question, "Which city's weather do you want to check?". The intent parameter is not a static value. You can reference this variable using `${check_weather.city}`. Then, you can use the `${check_weather.city}` variable as an API parameter to call an external weather interface and retrieve the requested results.
How to reference variables
Intent parameter references
Reference method: Use `${intent.slot.origin}` for the original value and `${intent.slot}` for the normalized value.
Scenarios: You can use this method in built-in function nodes and response nodes to reference intent parameters.
Example: In a weather check scenario, a user says, "Check the weather in Hangzhou for the day after tomorrow." Dialog Studio assigns "the day after tomorrow" to the "time" intent parameter of the "check_weather" intent. You can use `${check_weather.time.origin}` to reference the original value, "the day after tomorrow", and `${check_weather.time}` to reference the normalized value, "2018-07-23".
External environment variable references
Reference method: `${var}`
Scenarios: You can use this method in built-in function nodes and response nodes to reference external environment variables. To reference an external variable, you must first write the variable to the `ext` field in the session, and then pass it to Dialog Studio through the session API.
Example: In an E-commerce scenario, an external system passes the user's logon status to Dialog Studio as an environment variable through the session API. For example, the content might be `{"isLogin": true, "nickName": "James"}`. To reference the user's logon status, you can use `${isLogin}`.
Function return result references
Reference method: `${functionOutput}`
Scenarios: You can use this method to reference the result returned by an upstream function node in the immediately following response node.
Example: In a provident fund balance query scenario, a function node calls the provident fund query API after the conversation starts. In the subsequent response node, you can retrieve the balance information using `${functionOutput}`.
Global variable references
Reference method: `${global.var}`
Scenarios: You can use this method in built-in function nodes and response nodes to reference global variables.
Example: In an E-commerce scenario, a user selects an order. A user-defined function records the order ID in a global variable, for example, `OrderId=146860783793347518`. To reference the order ID in a built-in function node or a response node, you can use `${global.OrderId}`.