I'm trying to use Alexa Presentation Language. I want to know how to incorporate dynamic strings (like Output Speech and Title) in node.js (Binding to be specific).
If I use some static strings for outputSpeech and put it in apl_template_export.json, then the skill functions properly and I can see output in Device Display. But when I try to use binding, the skill fails. Although there is no error, but I can't see any output in Device Display either (See Image).

Here is what I've been trying so far:
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: require('./apl_template_export.json'),
dataSources: {
"bodyTemplate1Data": {
"type": "object",
"objectId": "bt1Sample",
"title": urlParams.type,
"textContent": {
"primaryText": {
"type": "PlainText",
"text": outputSpeech
}
}
}
}
})
.speak(outputSpeech)
.getResponse();
apl_template_export.json:
{
"type": "APL",
"version": "1.0",
"import": [
{
"name": "alexa-layouts",
"version": "1.0.0"
}
],
"mainTemplate": {
"parameters": [
"payload"
],
"items": [
{
"type": "Text",
"text": "${dataSources.bodyTemplate1Data.textContent.primaryText.text}"
}
]
}
}
If I replace ${dataSources.bodyTemplate1Data.textContent.primaryText.text} with actual text (like "Hello World"), the skill works as intended.
I took reference from here and here, original repository: https://github.com/alexa-labs/skill-sample-nodejs-level-up-riddles
Can anyone tell me what is going wrong here?
UPDATE
I changed the text variable to this:
"items": [
{
"type": "Text",
"text": "Type: ${type}\nDatasources: ${dataSources != null} \nBodyTemplate: ${dataSources.bodyTemplate1Data != null}"
}
]
And I'm getting this as output:
Type: undefined
Datasources: false
BodyTemplate: false
So the problem is not in rendering the output, instead the template is not able to load the dataSources, that is the actual problem.
It is not even able to load type variable whose value is already defined in the template.
If you're generating a
templatefrom APL Authoring Tool, then here are the points to remember:directiveto yourresponseBuilder, make sure that you add akeynameddatasources.datasourcefrom your template, make sure that you address it aspayload. So yourdatasourceis referenced aspayload.For eg:
If you want to access
valuethen reference it as${payload.text.value}.