question

Shan avatar image
Shan asked

Can you please share the sample code to perform OpenURL using APL

Hi,

Can you please let know a sample code to perform OpenURL using APL.

I am doing like this, but it is not running....

return handlerInput.responseBuilder

.speak(speechText)

.reprompt("Sorry, I did not understand that. Please say again")

.addDirective({

type: 'Alexa.Presentation.APL.ExecuteCommands',

token: 'launchPagerToken',

commands: [

{

"type": "OpenURL",

"source": "https://www.amazon.com/",

"onFail": {

"type": "SetValue",

"componentId": "pagerComponentId",

"property": "text",

"value": "Unable to open Amazon.com (${event.source.value})"

}

}

],

})

.getResponse();

alexa skills kitapl
10 |5000

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

1 Answer

Sheng avatar image
Sheng answered

First of all, according to the document: https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/understand-apl.html#skill-directives-and-requests


"You send the Alexa.Presentation.APL.ExecuteCommands directive to send commands to the device. These commands typically reference specific parts of the document. For example, the SpeakItem command tells the device to speak the text defined with a particular component (such as a Text component)."


This seems to indicate (please correct me if I am wrong) that you cannot simply execute a command to open a web page from the very first voice intent, e.g. "ask <skill> to do X" cannot execute the OpenURL command.


If you have a document displayed, then you can execute the OpenURL command, say when a button is clicked:


Use the example APL from here: https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/use-apl-with-ask-sdk.html#handle-a-userevent-request


Then replace the AlexaButton code with the following to execute OpenURL

{

"type": "AlexaButton",

"alignSelf": "center",

"id": "fadeHelloTextButton",

"buttonText": "This is a button",

"primaryAction": [

{

"type": "OpenURL",

"source": "https://www.amazon.com",

"onFail": {

"type": "SetValue",

"componentId": "errorText",

"property": "text",

"value": "Unable to open Amazon.com (${event.source.value})"

}

}

]

}


Your code looks about right if your document matches the same token per https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/use-apl-with-ask-sdk.html#return-executecommands-in-a-request-handler-response


Hope this helps!

10 |5000

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