Skip to content

Instantly share code, notes, and snippets.

@kinisoftware
Created April 11, 2021 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinisoftware/ee17e2735c098a751079477e1cfb8271 to your computer and use it in GitHub Desktop.
Save kinisoftware/ee17e2735c098a751079477e1cfb8271 to your computer and use it in GitHub Desktop.
class StartOverIntentHandler : RequestHandler {
override fun canHandle(input: HandlerInput) =
input.matches(Predicates.intentName("AMAZON.StartOverIntent"))
override fun handle(input: HandlerInput): Optional<Response> {
return input.attributesManager.persistentAttributes["lastPlayedAudio"]?.let {
input.playAudio(it.toAudio().url)
} ?: input.emptyResponse()
}
private fun HandlerInput.playAudio(audioUrl: String) = responseBuilder
.addAudioPlayerPlayDirective(
PlayBehavior.REPLACE_ALL,
0L,
null,
"token",
audioUrl
)
.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment