Response Acts in the Alexa Conversations Core Library (ACCL)

In the Alexa Conversations Description Language (ACDL), you associate responses with response acts. Response acts convey to Alexa Conversations some additional information about a response, such as whether the response represents a request for the user to confirm an action, a suggestion to call a new action, and so on.

For example, the Notify response act signifies that the response is an outcome of an action ("In Seattle, it's 65 degrees.") The Request response act signifies that the response is asking the user for information that an action requires "What city?").

To associate a response with a response act, you pass the response() action an expression that derives from ResponseAct. For details about how to use response acts in response definitions, see Using Responses in ACDL.

Syntax

You use response acts when you define a response() action as follows.

action Nothing response(Response response, ResponseAct act, ResponseAct nextAct = nothing, Thing payload = nothing)

The response() action, which is from the Alexa Conversations Core Library (ACCL), accepts one or more ResponseAct arguments. The ResponseAct argument can be one of the following values:

The examples on this page reference the following actions.

action SearchFlightResult searchFlights(City fromCity, City toCity, Date startDate, Date returnDate = nothing)
action BookFlightResult bookFlight(SearchFlightResult searchResult)

Bye

You use the Bye response act to end the conversation. For example, the associated Alexa speech might be, "Thanks for using weather bot. Goodbye."

To inform the user of the result of the current action and end the conversation, you can chain the Bye response act with the Notify response act. For details, see Notify and Bye.

Type declaration:

type Bye : ResponseAct {
}

Example:
The following example shows how to use the Bye response act with the response() action.

sample {
  // "Thanks for using weather bot. Goodbye."
  response(byePrompt, Bye {})
}

ConfirmAction

You use the ConfirmAction response act before an action to confirm that the user wants to invoke the action. For example, the associated Alexa speech might be, "You'd like to know the weather for Seattle, right?"

For an alternative way to use the ConfirmAction response act, you can use the confirmAction() action.

Type declaration:

type ConfirmAction : ResponseAct {
  Action actionName
}

Example:
The following example shows how to use the ConfirmAction response act with the response() action.

sample {
  ...
  response(
    confirmFlightBooking,
    ConfirmAction {actionName = bookFlight},
    payload = FlightResultPayload {searchResult = searchFlightResult})
  ...
}

ConfirmArgs

You use the ConfirmArgs response act to confirm action arguments that the user provided. For example, the associated Alexa speech might be, "That was for Seattle?"

If you use the ConfirmArgs response act for an argument, you must have a corresponding expect() action that provides that specific argument. Alternatively, you can provide an ensure() action, which represents a response() action plus the expect() action.

For an alternative way to use the ConfirmArgs response act, see the confirmArgs() action in the Alexa Conversations Core Library (ACCL).

Type declaration:

type ConfirmArgs : ResponseAct {
  List<Argument> arguments
}

Example:
In the following example, the skill responds to the user with a prompt to confirm the invocation of the bookFlight() action.

sample {
  bookFlightRequest = expect(Invoke, bookFlightEvent)
  ...
  // Ensure that the identified argument has been provided by the user
  ensure(
    {arguments = [searchFlights.arguments.fromCity], response = cityPrompt},
  )

  // Ask the user to confirm that the provided answer is indeed what they want to use
  response(
    confirmFromCityPrompt,
    ConfirmArgs {arguments = [searchFlights.arguments.fromCity]},
    payload = FlightResultPayload { fromCity = bookFlightRequest.fromCity } )
  ...

  searchFlightResult = searchFlights(bookFlightRequest.fromCity, bookFlightRequest.toCity, bookFlightRequest.startDate)
}

If you use the ConfirmArgs response act as an argument, you must provide a corresponding Request response act for the argument, either with the response() action and the Request response act or with the ensure() action.

Therefore, the previous example includes an ensure() action with the fromCity, toCity, and startDate arguments. Alternatively, you can provide response() actions with the Request response act for each argument. You can swap them out for each other, as shown in Request multiple arguments in one response() action.

The payload argument in ConfirmArgs

You don't need to explicitly define the payload argument when you use the ConfirmArgs response act. If you leave it out, the ACDL compiler fills it in using the subsequent action invocation. The following example shows how to use ConfirmArgs with the payload.

// Use ConfirmArgs with the payload
sample {
  bookFlightRequest = expect(Invoke, bookFlightEvent)

  // For brevity, the required ensure() action is left out of this sample

  // Fill in the payload using the arguments from the subsequent action invocation, searchFlights()
  response(confirmFromCityPrompt, ConfirmArgs {arguments = [searchFlights.arguments.fromCity]}, payload = {fromCity = bookFlightRequest.fromCity})
  response(confirmToCityPrompt, ConfirmArgs {arguments = [searchFlights.arguments.toCity]}, payload = {toCity = bookFlightRequest.toCity})
  response(confirmDatePrompt, ConfirmArgs {arguments = [searchFlights.arguments.startDate]}, payload = {startDate = bookFlightRequest.startDate})

  searchFlightResult = searchFlights(bookFlightRequest.fromCity, bookFlightRequest.toCity, bookFlightRequest.startDate)
  ...
}

The following example shows how to use ConfirmArgs without providing the payload. In this case, the ACDL compiler fills in the payload to be the equivalent of the previous sample by using the searchFlights() arguments as follows.

// Use ConfirmArgs without providing the payload. The ACDL compiler will fill in the payload
// to be the equivalent of the previous sample by using the searchFlights() arguments
sample {
  bookFlightRequest = expect(Invoke, bookFlightEvent)

  //For brevity, the required ensure() action is left out of this sample

  response(confirmFromCityPrompt, ConfirmArgs {arguments = [searchFlights.arguments.fromCity]})
  response(confirmToCityPrompt, ConfirmArgs {arguments = [searchFlights.arguments.toCity]})
  response(confirmDatePrompt, ConfirmArgs {arguments = [searchFlights.arguments.startDate]})

  searchFlightResult = searchFlights(bookFlightRequest.fromCity, bookFlightRequest.toCity, bookFlightRequest.startDate)
  ...
}

// Another way of leaving out the payload. The ACDL Compiler will fill in the payload
// to be the equivalent of the first sample by using the searchFlights() arguments
sample {
  bookFlightRequest = expect(Invoke, bookFlightEvent)

  // For brevity, the required ensure() action is left out of this sample

  response(confirmFromCityPrompt, ConfirmArgs {arguments = [searchFlights.arguments.fromCity]}, payload = {})
  response(confirmToCityPrompt, ConfirmArgs {arguments = [searchFlights.arguments.toCity]}, payload = {})
  response(confirmDatePrompt, ConfirmArgs {arguments = [searchFlights.arguments.startDate]}, payload = {})

  searchFlightResult = searchFlights(bookFlightRequest.fromCity, bookFlightRequest.toCity, bookFlightRequest.startDate)
  ...
}

The APL/APLA documents can then use these payload arguments. There are three prompts in the previous example (one for each response() action), so the following example shows the corresponding three content lines, each spliced from their example APLA documents to demonstrate how the payload argument can access the information provided in the dialog sample.

// Taken from confirmFromCityPrompt document
"content": "Just to confirm, you want to book a flight from ${payload.fromCity}?"
// Taken from confirmToCityPrompt document
"content": "Just to confirm, you want to book a flight to ${payload.toCity}?"
// Taken from confirmDatePrompt document
"content": "Just to confirm, you want to book a flight on ${payload.startDate}?"

Notify

You use the Notify response act to inform the user of the result of an action, which is typically an API call. For example, the associated Alexa speech might be, "The weather in Seattle is 65 degrees." You typically precede the Notify() action with an action invocation. The default of success is true, so specifying success is optional for the successful case.

Type declaration:

type Notify : ResponseAct {
  Action actionName
  optional Boolean success
}

Example:
The following example shows how to use the Notify response act with the response() action.

sample {
  ...
  searchFlightResult = searchFlights(bookFlightRequest.fromCity, bookFlightRequest.toCity, bookFlightRequest.startDate)

  // "Your flight from Seattle to Portland on July 31st has been booked"
  response(
    notifyFlightResponse,
    Notify {actionName = searchFlights, success = true},
    payload = FlightResultPayload {searchResult = searchFlightResult})
}

Offer

You use the Offer response act to offer a related action when the user has achieved their initial goal. For example, the associated Alexa speech might be, "Would you like the hour-by-hour forecast?"

To inform the user of the result of the current action and provide an offer, you can chain the Offer response act with the Notify response act. For details, see Notify and Offer.

Type declaration:

type Offer : ResponseAct {
  Action actionName
  optional List<Argument> requestArgs
  optional List<CarryOverArgument> carryOverArguments
}

Example:
The following example shows how to use the Offer response act with the response() action.

sample {
  ...
  // sample: "Do you want to book a return flight from Portland?"
  response (
    offerReturnFlight,
    Offer {actionName = searchFlights},
    payload = OfferReturnFlightPayload { destination = req.toCity } )
  ...
}

ReqAlt

You use the ReqAlt response act to request an alternative response to continue the conversational flow. For example, the associated Alexa speech might be, "Would you like to know the weather for a different city?" You can't use the ReqAlt response act as a standalone response act in a response() action.

To inform the user that Alexa was unable to fulfill the goal with the provided arguments and then request alternative values for the arguments, you can chain the ReqAlt response act with the Notify response act. For details, see Notify and ReqAlt.

Type declaration:

type ReqAlt : ResponseAct {
  List<Argument> arguments
}

ReqMore

You use the ReqMore response act to request to continue the conversational flow after the completion or interruption of an initial goal. For example, the associated Alexa speech might be, "Is there anything else I can do for you?"

To inform the user of the result of the current action and request another goal, you can chain the ReqMore response act with the Notify response act. For details, see Notify and ReqMore.

Type declaration:

type ReqMore : ResponseAct {
}

Example:
The following example shows how to use the ReqMore response act such that the skill responds to the user asking for another goal.

sample {
  ...
  response(
    successPrompt,
    Notify { action = searchFlights, success = true })

  // "What else can I do?"
  response(
    requestMorePrompt,
    ReqMore {})
  ...
}

Request

You use the Request response act to request the user for missing arguments that an action requires. For example, the associated Alexa speech might be, "Which city?"

A Request expression passed to the response() action indicates to Alexa Conversations that the skill should ask the user for information that is needed to invoke an action. The Request expression identifies the arguments for which the request is made.

Type declaration:

type Request : ResponseAct {
  List<Argument> arguments
}

The Alexa Conversations simulator requires that each required argument of an action must be given a value. You can extract the value for an argument from an event by using the expect() action. However, some events might not produce a value for the required argument. For example, the argument value isn't extracted from the utterance or the argument is declared to be optional. In these cases, the skill must ask the user to provide the required value. You represent this request by using a Request response act expression with a response() action.

If the value to be passed to the desired action is the result from a previous invocation of an action and the argument isn't declared to be optional, there is no need to ask the user to provide it.

In the following example, the event doesn't produce any of the required arguments for the searchFlights() action, so the skill should ask the user. You can also use the ensure() action to represent this example with fewer lines.

sample {
  // "Book a flight for me"
  req = expect(Invoke, bookFlightEvent)

  // "From which city?"
  response(response = fromCityPrompt, act = Request {arguments = [searchFlights.arguments.fromCity]})

  // "From Seattle"
  expect(Inform, informCityEvent)

  // "To which city?"
  response(response = toCityPrompt, act = Request {arguments = [searchFlights.arguments.toCity]})

  // "To Portland"
  expect(Inform, informCityEvent)

  // "On which date?"
  response(response = datePrompt, act = Request {arguments = [searchFlights.arguments.startDate]})

  // "On July 31st"
  expect(Inform, informDateEvent)

  // Invoke action
  searchFlightResult = searchFlights(req.fromCity, req.toCity, req.startDate)

  ...
}

Provide all of the request actions explicitly

The following dialog sample uses a separate response() action for each of the required arguments. The searchFlights() action has three required arguments (fromCity, toCity, and startDate), and each of these arguments is covered by a Request response act.

sample {
  // "Book a flight for me"
  expect(Invoke, bookFlightEvent)

  // "From which city?"
  response(response = fromCityPrompt, act = Request {arguments = [searchFlights.arguments.fromCity]})

  // "From Seattle"
  fromCity = expect(Inform, informCityEvent)

  // "To which city?"
  response(response = toCityPrompt, act = Request {arguments = [searchFlights.arguments.toCity]})

  // "To Portland"
  toCity = expect(Inform, informCityEvent)

  // "On which date?"
  response(response = datePrompt, act = Request {arguments = searchFlights.arguments.startDate]})

  // "On July 31st"
  startDate = expect(Inform, informDateEvent)

  searchFlightResult = searchFlights(fromCity.cityName, toCity.cityName, startDate.cityName)
  ...
}

The following dialog sample in which the user provides all of the required information in the opening sentence. The sample still requires Request response acts for each required argument. However, instead of using the response() action, the sample uses the ensure() action from the ACCL. For details, see ensure().

sample {
  // "Book a flight from Seattle to Portland on July 31st"
  bookFlightRequest = expect(Invoke, bookFlightEvent)
  ensure(
    {arguments = [searchFlights.arguments.fromCity], response = fromCityPrompt},
    {arguments = [searchFlights.arguments.toCity], response = toCityPrompt},
    {arguments = [searchFlights.arguments.startDate], response = datePrompt}
  )
  searchFlightResult = searchFlights(bookFlightRequest.fromCity, bookFlightRequest.toCity, bookFlightRequest.startDate)
  ...
}

Request multiple arguments in one response() action

You can request multiple arguments of the same action in a single response() action.

However, this technique doesn't fulfill the requirement of having a separate response() action for each required argument. To cover multiple arguments using one response() action, you must either use additional standalone response() actions for each required argument, or an ensure() action that includes all of the arguments.

The following example uses the ensure() action to request multiple arguments in one response() action.

// Use the "ensure" action
sample {
  expect(Invoke, bookFlightEvent)

  // Multiple arguments of the same action (searchFlights) can be requested in a single expression
  // "From which city and to which city?"
  response(response = toAndFromCityPrompt, act = Request {arguments = [searchFlights.arguments.fromCity, searchFlights.arguments.toCity]})

  // The requirement of having a separate response() action for each required argument can be fulfilled
  // using the ensure action
  ensure(
    {arguments = [searchFlights.arguments.fromCity], response = fromCityPrompt},
    {arguments = [searchFlights.arguments.toCity], response = toCityPrompt}
  )

  // "From Seattle to Portland"
  toAndFromCityResponse = expect(Inform, informToAndFromCityEvent)
  response(response = datePrompt, act = Request {arguments = [searchFlights.arguments.startDate]})
  startDate = expect(Inform, informDateEvent)
  searchFlightResult = searchFlights(toAndFromCityResponse.fromCity, toAndFromCityResponse.toCity, startDate.date)
    ...
}

The following example uses individual response() actions to request multiple arguments in one response() action.

// Use individual "response" actions
sample {
  expect(Invoke, bookFlightEvent)

  // Multiple arguments are being requested at once here
  // "From which city and to which city?"
  response(response = toAndFromCityPrompt, act = Request {arguments = [searchFlights.arguments.fromCity, searchFlights.arguments.toCity]})

  // The requirement of having a separate response() action for each required argument can also be fulfilled
  // using individual response() action expressions
  response(response = fromCityPrompt, act = Request {arguments = [searchFlights.arguments.fromCity]})
  response(response = toCityPrompt, act = Request {arguments = [searchFlights.arguments.toCity]})

  // "From Seattle to Portland"
  toAndFromCityResponse = expect(Inform, informToAndFromCityEvent)
  response(response = datePrompt, act = Request {arguments = [searchFlights.arguments.startDate]})
  startDate = expect(Inform, informDateEvent)
  searchFlightResult = searchFlights(toAndFromCityResponse.fromCity, toAndFromCityResponse.toCity, startDate.date)
  ...
}

Cross reference between response acts and dialog acts

If you develop Alexa Conversations skills by using the developer console, you are familiar with the concept of Alexa response dialog acts. Alexa response dialog acts help Alexa Conversations identify the purpose of Alexa responses within the flow of a dialog. With the ACCL, you specify Alexa response dialog acts by using response acts.

Alexa response dialog acts indicate the purpose of the Alexa response. The following table shows the response act that corresponds to each Alexa response dialog act.

Dialog Act Response Act Description

API Failure

Notify

Alexa is notifying the user that the API call was unsuccessful.

Example: "Weather data for Seattle is not available."

API Success

Notify

Alexa is notifying the user that the API call was successful.

Example: "The weather in Seattle is 65 degrees."

Confirm API

ConfirmAction

Alexa is confirming or denying with the user all required API argument(s) and optional API argument(s) (any number) that belong to an API definition.

Example: "You want the weather for Seattle, right?"

Confirm Args

ConfirmArgs

Alexa is confirming or denying arguments that the user provided.

Example: "That was for Seattle?"

Offer Next API

Offer

Alexa is offering the user a related action when the user has achieved their initial goal.

Example: (Chained with dialog act API Success) "The weather in Seattle is 65 degrees. Would you like the hour-by-hour forecast?"

Request Alt

ReqAlt

Alexa is requesting alternative values for the arguments.

Example: (Chained with dialog act API Success) "The weather in Seattle is 65 degrees. Would you like to know the weather for a different city?"

Request

Request

Alexa is requesting missing arguments that are required for invoking an action.

Example: "Which city?"