Created
December 8, 2019 17:42
-
-
Save kinisoftware/dbfce96604092d11f76664a4fe25ba49 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
| return when { | |
| input.supportAPL() && movies.isNotEmpty() -> { | |
| try { | |
| val mapper = ObjectMapper() | |
| val documentMapType = object : TypeReference<HashMap<String, Any>>() {} | |
| val document = mapper.readValue<Map<String, Any>>(File("upcomingMoviesScreen.json"), documentMapType) | |
| val dataSourceMapType = object : TypeReference<HashMap<String, Any>>() {} | |
| val dataSource = mapper.readValue<Map<String, Any>>(File("upcomingMoviesScreenData.json"), dataSourceMapType) | |
| val newReleases = mapOf("newReleases" to movies) | |
| val documentDirective = RenderDocumentDirective.builder() | |
| .withDocument(document) | |
| .withDatasources(dataSource) | |
| .putDatasourcesItem("movies", newReleases) | |
| .build() | |
| return input.responseBuilder | |
| .withSpeech("Te muestro los próximos estrenos de cine") | |
| .addDirective(documentDirective) | |
| .withShouldEndSession(false) | |
| .build() | |
| } catch (e: IOException) { | |
| throw AskSdkException("Unable to read or deserialize upcoming movies data", e) | |
| } | |
| } | |
| else -> { | |
| val text = if (movies.isEmpty()) { | |
| Translations.getMessage(language, Translations.TranslationKey.UPCOMINGS_NOT_FOUND) + Translations | |
| .getMessage(language, Translations.TranslationKey.ASKING_FOR_NOW_PLAYING) | |
| } else { | |
| "${Translations.getMessage(language, Translations.TranslationKey.UPCOMINGS_RESPONSE)}: " + movies.map { it.getTitle() }.getResponse(language) | |
| } | |
| 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