question

newuser-71152f1c-1f31-4057-b9b0-d021d2e003d6 avatar image

how can i send a random text phrase as string to APL render directive datasource to use in a template .text property

I am having a difficult time sending a variable that holds a random text string as a property to an APL template using display directive. how can this be done? it doesn't seem difficult. i cannot find anything or anybody writing about it.i have tried list data and sending {stringval} and "${footerString}" etc. i display it and have alexa speak it before i send it and it is spoken so i know it is stored properly. i have tried let, var, const for the string value in the .js file but all of them only only show the varible name on the display card ${footerString} where the random title should go. my footHint is supposed to show a random string variable that holds a random text string each time someone plays. basically i want to send a randomly selected text string from an array to my render dir to set that string as the text value in the datasource for the text. property.

template...

"type": "Container",

"when": "${@viewportProfile == @hubRoundSmall}",

"items": [

{

"type": "Text",

"style": "textStyleBody",

"paddingLeft": "@marginLeft",

"paddingRight": "@marginRight",

"paddingBottom": "90",

"position": "relative",

"alignSelf": "auto",

"fontWeight": "normal",

"fontSize": "30",

"textAlign": "center",

"textAlignVertical": "auto",

"fontStyle": "normal",

"text": "${launchData.properties.headlinesm}"

}

],

"grow": 1,

"justifyContent": "end"

},

{

"type": "AlexaFooter",

"footerHint": "${launchData.properties.kombatfact}",

"hintText": "${launchData.properties.hintFooter}",

"when": "${viewport.shape != 'round'}"

}

]

}

]

}

},

"datasources": {

"launchData": {

"type": "object",

"properties": {

"background": "https://mortkom.s3.us-east-2.amazonaws.com/subzero/subzeroback.jpg",

"backgroundsm": "https://mortkom.s3.us-east-2.amazonaws.com/subzero/subzerowall2.jpg",

"headericon": "https://mortkom.s3.us-east-2.amazonaws.com/misc_vo/mklogognew2.png",

"headerTitle": "Sub-Zero",

"headerSubtitle": "Grandmaster Sub-Zero",

"hintText": "Try, \"Alexa, Open Test Your Might!\"",

"headline": "This is your headline",

"headlinesm": "Brothers Bi-Han and Kuai-Liang of the Lin-Kuei",

"kombatfact": "${footerString}",

"hintFooter": "Alexa, click here"

}

}

},


my index.js----


const factoid = [

'"Originally an army brat of military service."',

'"Now runs the army."',

'"Kidnapped impending invasion. If only they had listened."'

];


function randomdata(mydata) {

var i = 0;

i = Math.floor(Math.random() * mydata.length);

return(mydata[i]);

}

<tried this way> const $footerString =randomdata(funfact)

<tried this way both hold string> let $footerString=randomdata(funfact)

const speakOutput = 'do you hear this phrase ${footerString}';

console.log($footerString);


if (aplHelper.supportsAPL(handlerInput)) {


handlerInput.responseBuilder.addDirective({

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

version: '1.3',

document: require('./documents/launchScreen.json'),

datasources: {

launchData: {

type: 'object',

properties: {

"background": "https://mortkom.s3.us-east-2.amazonaws.com/subzero/subzeroback.jpg",

"backgroundsm": "https://mortkom.s3.us-east-2.amazonaws.com/subzero/subzerowall2.jpg",

"headericon": "https://mortkom.s3.us-east-2.amazonaws.com/misc_vo/mklogognew2.png",

"headerTitle": "Sub-Zero",

"headerSubtitle": "Grandmaster Sub-Zero",

"hintText": "Try, \"Alexa, Open Test Your Might!\"",

"headline": "hello there",

"headlinesm": "Brothers Bi-Han and Kuai-Liang of the Lin-Kuei",

"kombatfact": "${footerString}",

"hintFooter": ""

},

}

}

}

);

}

apldisplay templates
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

newuser-71152f1c-1f31-4057-b9b0-d021d2e003d6 avatar image
newuser-71152f1c-1f31-4057-b9b0-d021d2e003d6 answered

well i am embarrassed i figured it out. i was always taught and read to use $ and { for variable strings. but when delclaring their values.....use nothing! i tried every incarnation but ...i didn't try nothing.


footerSting=<your random calc>

<your.payload.property>: footerString,

10 |5000

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