Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Progressive Response in Java
sendProgressiveResponseMessage("Please wait!", handlerInput);
public static void sendProgressiveResponseMessage(final String message,
final HandlerInput handlerInput){
final SpeakDirective speakDirective = SpeakDirective.builder()
.withSpeech(message)
.build();
final String requestId = handlerInput.getRequestEnvelope().getRequest().getRequestId();
final SendDirectiveRequest sendDirectiveRequest = SendDirectiveRequest.builder()
.withDirective(speakDirective)
.withHeader(Header.builder().withRequestId(requestId).build())
.build();
handlerInput.getServiceClientFactory().getDirectiveService().enqueue(sendDirectiveRequest);
}
}
@kinisoftware

This comment has been minimized.

Copy link

kinisoftware commented Jun 28, 2019

This is my code, quite similar but in Kotlin:

private fun enqueueMessage(message: String) {
        val requestId = input.requestEnvelope.request.requestId
        val sendDirectiveRequest = SendDirectiveRequest.builder()
                .withDirective(SpeakDirective.builder()
                        .withSpeech("${getRandomOkSpeech()}, $message")
                        .build())
                .withHeader(Header.builder()
                        .withRequestId(requestId)
                        .build())
                .build()
        input.serviceClientFactory.directiveService.enqueue(sendDirectiveRequest)
    }

Now the challenge is to make the logic await till the progressive response is done before returning the final response :) Working on it!

@germanviscuso

This comment has been minimized.

Copy link
Owner Author

germanviscuso commented Jun 28, 2019

Nice!! Yes, it's basically the same. Let me know if you manage to "await" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.