on_intent¶
The on_intent syntax provides a way to define handlers for specific user intents in your AviScript skills.
Syntax¶
Parameters¶
intent_name: A string matching the name of an intent defined in your skill's intents directory
Scope Variables¶
When an intent handler is triggered, the following constants are available in the scope:
name: The name of the matched intentintent: TheIntentobject containing extracted slots and information
Example¶
on_intent "get_weather" {
let location = intent.optional("location", "current");
let date = intent.optional("date", "today");
speak.say("weather_report", #{
"location": location,
"date": date
});
// Fetch and display weather data
let weather_data = http.get("/api/weather", #{
"location": location,
"date": date
});
// Process weather_data and respond to user
}
Intent Object Methods¶
The intent object provides several methods to access slot data:
get(slot_name): Get a slot value or null if not presentget_raw(slot_name): Get the raw slot valuerequire(slot_name): Get a slot value or throw an error if not presentoptional(slot_name, default_value): Get a slot value or return default if not presentexists(slot_name): Check if a slot existsequal(slot_name, value): Check if a slot equals a specific valuein_list(slot_name, list): Check if a slot value is in a listin_dict(slot_name, dict): Check if a slot is a key in a dictionaryobj(): Get the full intent object as a mapcount(): Get the number of slotsall(): Get all slots as a map