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 NextIntentHandler : RequestHandler { | |
override fun canHandle(input: HandlerInput) = input.matches( | |
intentName("AMAZON.NextIntent") | |
.or(Predicates.requestType(NextCommandIssuedRequest::class.java)) | |
) | |
override fun handle(input: HandlerInput): Optional<Response> {...} | |
} |
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
fun HandlerInput.buildPlayResponse(audioStream: AudioStream): Optional<Response> { | |
val stream = Stream.builder() | |
.withOffsetInMilliseconds(audioStream.offsetInMilliseconds) | |
.withExpectedPreviousToken(null) | |
.withToken(audioStream.streamToken) | |
.withUrl(audioStream.file) | |
.build() | |
val audioItem = AudioItem.builder() | |
.withMetadata( | |
AudioItemMetadata.builder() |
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
{ | |
"type": "AudioPlayer.Play", | |
"playBehavior": "valid playBehavior value such as ENQUEUE", | |
"audioItem": { | |
"stream": { | |
"url": "https://cdn.example.com/url-of-the-stream-to-play", | |
"token": "opaque token representing this stream", | |
"expectedPreviousToken": "opaque token representing the previous stream", | |
"offsetInMilliseconds": 0, | |
"caption": { |
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 NextIntentHandler : RequestHandler { | |
override fun canHandle(input: HandlerInput) = input.matches(intentName("AMAZON.NextIntent")) | |
override fun handle(input: HandlerInput) = | |
input.attributesManager.persistentAttributes["lastPlayedAudio"]?.let { | |
PlayAudioResponseBuilder.buildNewsResponse( | |
input, | |
Audio(it.toAudio().getNextDate()) | |
) |
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 NextAndPreviousIntentHandler : RequestHandler { | |
override fun canHandle(input: HandlerInput) = input.matches( | |
Predicates.intentName("AMAZON.NextIntent") | |
.or(Predicates.intentName("AMAZON.PreviousIntent")) | |
) | |
override fun handle(input: HandlerInput) = input.responseBuilder | |
.withSpeech(Translations.getMessage(input.getLanguage(), Translations.TranslationKey.NO_FEATURE)) | |
.addAudioPlayerStopDirective() |
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 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() | |
} |
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
private fun HandlerInput.enqueuAudio(audioUrl: String) = responseBuilder | |
.addAudioPlayerPlayDirective( | |
PlayBehavior.ENQUEUE, | |
0L, | |
null, | |
"token", | |
audioUrl | |
) | |
.build() |
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
private fun HandlerInput.buildResponse(audioUrl: String, offsetInMillis: Long? = 0L) = responseBuilder | |
.addAudioPlayerPlayDirective( | |
PlayBehavior.REPLACE_ALL, | |
offsetInMillis, | |
null, | |
"token", | |
audioUrl | |
) | |
.build() |
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 PlaybackStoppedHandler : RequestHandler { | |
override fun canHandle(input: HandlerInput) = | |
input.matches(Predicates.requestType(PlaybackStoppedRequest::class.java)) | |
override fun handle(input: HandlerInput): Optional<Response> { | |
val request = input.requestEnvelope.request | |
val intentRequest = request as PlaybackStoppedRequest | |
val lastPlayedAudio = JacksonSerializer().deserialize( |
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 CancelAndStopIntentHandler : RequestHandler { | |
override fun canHandle(input: HandlerInput) = | |
input.matches( | |
intentName("AMAZON.StopIntent") | |
.or(intentName("AMAZON.CancelIntent")) | |
.or(intentName("AMAZON.PauseIntent")) | |
) | |
override fun handle(input: HandlerInput) = input.responseBuilder |
NewerOlder