Skip to content

Instantly share code, notes, and snippets.

@kinisoftware
Created February 22, 2020 11:33
Show Gist options
  • Select an option

  • Save kinisoftware/741ee22ece7c35c05900a2f2a4141049 to your computer and use it in GitHub Desktop.

Select an option

Save kinisoftware/741ee22ece7c35c05900a2f2a4141049 to your computer and use it in GitHub Desktop.
class EscogerComidaIntent : RequestHandler {
override fun canHandle(input: HandlerInput): Boolean {
return input.matches(Predicates.intentName("escoger_comida"))
}
override fun handle(input: HandlerInput): Optional<Response> {
if (!input.attributesManager.sessionAttributes.containsKey(AttributeConstants.FOOD)
|| !input.attributesManager.sessionAttributes.containsKey(AttributeConstants.RESTAURANT)
) {
return input.responseBuilder
.withSpeech("Comienza seleccionando el tipo de comida como pizza o hamburguesa")
.withShouldEndSession(false)
.build()
}
val request = input.requestEnvelope.request
val intentRequest = request as IntentRequest
val intent = intentRequest.intent
val slots = intent.slots
val order = slots["comprar"]!!.value
val restaurant = input.attributesManager.sessionAttributes[AttributeConstants.RESTAURANT]
val text = "Okay, ¡gran elección! Vamos a comprar $order en $restaurant."
return input.responseBuilder
.withSpeech(text)
.withShouldEndSession(true)
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment