Skip to content

Instantly share code, notes, and snippets.

@kinisoftware
Created December 8, 2019 17:42
Show Gist options
  • Select an option

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

Select an option

Save kinisoftware/dbfce96604092d11f76664a4fe25ba49 to your computer and use it in GitHub Desktop.
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