Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save kinisoftware/c932c797d8ee9b9b04b260bb1267e1b7 to your computer and use it in GitHub Desktop.
class ListarRestaurantesPorTipoDeComidaIntent : RequestHandler {
override fun canHandle(input: HandlerInput): Boolean {
return input.matches(Predicates.intentName("listar_restaurantes_por_tipo_de_comida"))
}
override fun handle(input: HandlerInput): Optional<Response> {
val request = input.requestEnvelope.request
val intentRequest = request as IntentRequest
val intent = intentRequest.intent
val slots = intent.slots
val foodSlot = slots["comida"]
val food = foodSlot?.value
val text = when (food) {
null -> "Elige algún tipo de comida como pizza o hamburguesa"
else -> {
val cousine = foodSlot.resolutions.resolutionsPerAuthority
.first { it.status.code == StatusCode.ER_SUCCESS_MATCH }.values[0].value.name
if (restaurantsByCousine.containsKey(cousine)) {
input.attributesManager.sessionAttributes[AttributeConstants.FOOD] = food
"Puedes comer $food en: " + restaurantsByCousine[cousine]?.joinToString()
} else {
"Aún no conozco restaurantes que cocinen $food. Lo siento"
}
}
}
return input.responseBuilder
.withSpeech(text)
.withShouldEndSession(false)
.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment