If you are using the lambda as your skill endpoint, you are only responsible for providing the response body in order for Alexa to respond to a customer request. The documentation on the JSON structure of the response body can be found here.
A response body may contains the following properties:
ASK SDK v2 for Node.js helps filling the version and sessionAttributes so you can focus on building the response instead of writing boilerplate code.
ResponseBuilder includes helper methods for constructing the response. A
Response may contain multiple elements, and the helper methods aid in generating responses, reducing the need to initialize and set the elements of each response.
ResponseBuilder is available to handlers via the
HandlerInput container object. The detailed description of
ResponseBuilder can be found in the TypeDoc
speak(speechOutput: string): this; reprompt(repromptSpeechOutput: string): this; withSimpleCard(cardTitle: string, cardContent: string): this; withStandardCard(cardTitle: string, cardContent: string, smallImageUrl?: string, largeImageUrl?: string): this; withLinkAccountCard(): this; withAskForPermissionsConsentCard(permissionArray: string): this; withCanFulfillIntent(canFulfillIntent : CanFulfillIntent) : this; addDelegateDirective(updatedIntent?: Intent): this; addElicitSlotDirective(slotToElicit: string, updatedIntent?: Intent): this; addConfirmSlotDirective(slotToConfirm: string, updatedIntent?: Intent): this; addConfirmIntentDirective(updatedIntent?: Intent): this; addAudioPlayerPlayDirective(playBehavior: interfaces.audioplayer.PlayBehavior, url: string, token: string, offsetInMilliseconds: number, expectedPreviousToken?: string, audioItemMetadata? : AudioItemMetadata): this; addAudioPlayerStopDirective(): this; addAudioPlayerClearQueueDirective(clearBehavior: interfaces.audioplayer.ClearBehavior): this; addRenderTemplateDirective(template: interfaces.display.Template): this; addHintDirective(text: string): this; addVideoAppLaunchDirective(source: string, title?: string, subtitle?: string): this; withShouldEndSession(val: boolean): this; addDirective(directive: Directive): this; getResponse(): Response;
The following example shows how to construct a response using
ResponseBuilder helper methods.
The contents of the speak and reprompt values get wrapped in SSML tags. This means that any special XML characters within the value need to be escape coded. For example,
handlerInput.responseBuilder.speak("I like M&M's") will cause a failure because the
& character needs to be encoded as
&. Other characters that need to be encoded include: