Composing actions
Let's go through an example of a manifest for a composite action. This action gets uses the OpenWeather api to fetch the weather by a location name. However, since the open weather api does not offer the functionality to fetch the weather by location name directly, we need break the flow into two steps:
-
Get the latitude and longitude by location name
-
Get the weather by latitude and longitude
{
"name": "get-weather-by-location-name",
"description": "Get weather by location name",
"version": "0.0.1",
"kind": "composition",
"manifest_version": 1,
"repository": "github.com/tgirotto/get-weather-by-location-name",
"license": "MIT",
"inputs": [
{
"name": "weather_config",
"type": "WeatherConfig",
"required": true
}
],
"steps": {
"get_coordinates": {
"uses": "tgirotto/openweather-coordinates-by-location-name:0.0.1",
"inputs": [
{
"location_name": "{{inputs[0].location_name}}",
"open_weather_api_key": "{{inputs[0].open_weather_api_key}}"
}
]
},
"get_weather": {
"uses": "tgirotto/openweather-current-weather:0.0.1",
"inputs": [
{
"lat": "{{steps.get_coordinates.outputs[0].lat}}",
"lon": "{{steps.get_coordinates.outputs[0].lon}}",
"open_weather_api_key": "{{inputs[0].open_weather_api_key}}"
}
]
}
},
"outputs": [
{
"name": "response",
"description": "Simplified weather information for the location",
"type": "CustomWeatherResponse",
"value": {
"location_name": "{{inputs[0].location_name}}",
"weather": "{{steps.get_weather.outputs[0].weather[0].description}}"
}
}
],
"types": {
"WeatherConfig": {
"location_name": "string",
"open_weather_api_key": "string"
},
"CustomWeatherResponse": {
"location_name": "string",
"weather": "string"
}
}
}
The most interesting bit is in the steps section, where the mapping between inputs and outputs of different actions happens. For example:
"lat": "{{steps.get_coordinates.outputs[0].lat}}"
means that the outputs of the get_coordinates step will be used to resolve the "lat" property of the input that's going to be used in the get_weather step. Pretty simple, no?