gpt4 book ai didi

javascript - Alexa Skills 使用 slotValue 作为数组名称

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:37 25 4
gpt4 key购买 nike

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;
}

有没有办法做到这一点,而不是使用开关来设置lookupArray = sessionAttributes.(slotValues.listableThings.resolved)

我在 JavaScript 上能找到的所有内容都说要使用警报,但 Node.js 中并未为 Alexa 技能定义警报。

最佳答案

您可以迭代元素并使用键进行分配

// 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);

关于javascript - Alexa Skills 使用 slotValue 作为数组名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54949516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com