question

Dustin avatar image
Dustin asked

Progressive Response in NodeJS SDK v2

It's amazing what you did with the new NodeJS SDK v2 but it seems like there's documentation missing.

Is there a simple way of sending a progressive response using the new APIs? The documentation only states the obvious device address calls and music directives, but northing about progressive responses.

Do we really have to send the plain POST request ourselves or is there some functions I have not discovered yet?

The sdk-model seems to at least define VoicePlayer.Speak but no idea how to easily send this via the new SDK. Thanks!

alexa skills kitnodejsdocumentationsdk v2progressiveresponse
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dustin avatar image
Dustin answered

You can use this helper to send a progressive response using v2 of the nodejs SDK:

function callDirectiveService(handlerInput, speech) {
  const { requestEnvelope } = handlerInput
  const directiveServiceClient = handlerInput.serviceClientFactory.getDirectiveServiceClient()
  
  const directive = {
    header: {
      requestId: requestEnvelope.request.requestId
    },
    directive: {
      type: 'VoicePlayer.Speak',
      speech: speech
    }
  }
  return directiveServiceClient.enqueue(directive, requestEnvelope.context.System.apiEndpoint, requestEnvelope.context.System.apiAccessToken)
}
1 comment
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you Dustin - exactly what was needed: a minimal, complete example. Only with your example in hand could I make sense of the documentation.

2 Likes 2 ·
roy-1 avatar image
roy-1 answered

Hi Dustin,

Please see the following post on our Alexa Developer Blog for steps and code samples to create a helper function to utilize the progressive response API in your Skill, using the VoicePlayer speak directive that you mentioned:

Alexa Skill Recipe: Improving the Perceived Latency of API Calls Using the Progressive Response API

If you'd like to see a more streamlined option in the SDK, please feel free to submit a feature request on our uservoice page here:

alexa.uservoice.com

2 comments
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

The example given is for V1.

Dustin is asking for an example using the Version 2 of the SDK.

I'm also looking for it and I can't find it anywhere.

0 Likes 0 ·

Hi Rod!

If you'd like to see this example added to the tech docs, feel free to open an issue within the ASK SDK GitHub repository here:

https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues

0 Likes 0 ·
roy-1 avatar image
roy-1 answered

Hello,

I've reached out to the team for additional information, and wanted to pass along the following:

A DirectiveServiceClient is provided through ServiceClientFactory, similarly to what is documented here:

https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/wiki/Alexa-Service-Clients

You can retrieve the service client using the following line:

const directiveServiceClient = handlerInput.serviceClientFactory.getDirectiveServiceClient();

The DirectiveServiceClient provides an "enqueue" function that allows you to pass in the SendDirectiveRequest, which the SDK then wraps in a POST call to the Progressive response API service.

I hope this helps. Please let me know if this answers your question.

1 comment
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks for your help. Unfortunately the new documentation of the v2 SDK still does not include a proper example or even the call you mentioned, which is why I have provided my own answer with an actual code snipped to send the whole response.

0 Likes 0 ·
Eureka avatar image
Eureka answered

Brilliant answer from Dustin. What we needed was that complete example, starting from taking the handlerInput, and requiring nothing else, and delivering the required speech enqueued. Thank you Dustin!

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

D. Young avatar image
D. Young answered

Dustin posted a helpful snippet above, but audio files look like they won't work. @Roy@amazon & @Dustin - Do you have any insight about setting up a progressive response using the v2 SDK and delivering audio content of an mp3? Based on Anand's answer, "You can't call VoicePlayer.Speak from audio directives if you want to add audio then create speechOutput with ssml with audio tags like <audio src="<url link>></audio> "

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.