简体   繁体   中英

Alexa Skills use slotValue as array name

if (slotValues.listableThings.ERstatus === 'ER_SUCCESS_MATCH') {
  switch (slotValues.listableThings.resolved) {
    case 'CLASSES':
      {
        lookupArray = sessionAttributes.CLASSES;
      };
      break;
   case 'TONES':
      {
         lookupArray = sessionAttributes.TONES;
      };
      break;
    default:
      break;
  }

Is there a way to do this instead of using a switch to just set lookupArray = sessionAttributes.(slotValues.listableThings.resolved)

everything I can find on javascript says to use alert but alert is not defined in node.js for alexa skills.

You can iterate thought the elements and use the key to assign

 // Emulating var slotValues = { listableThings: { resolved: "CLASSES" } }; var sessionAttributes = { CLASSES: "THESE ARE CLASSES", TONES: "THESE ARE TONES" } let lookupArray = sessionAttributes[slotValues.listableThings.resolved]; console.log(lookupArray); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM