Created
February 22, 2020 11:18
-
-
Save kinisoftware/c932c797d8ee9b9b04b260bb1267e1b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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