nodejs中的搜索列表,用于Alexa技能

时间:2017-08-15 23:37:41

标签: node.js aws-lambda alexa-skills-kit

我正在尝试制作Alexa技能,并且在使用AWS lambda中的后端代码时遇到困难。基本上我有一个城市列表,如果用户说Alexa列表中的一个城市,她应该回应,那个城市是有效的。下面我有我的城市列表以及应该在列表中排序以找到匹配项的方法。

'static

1 个答案:

答案 0 :(得分:0)

所以,只是一个快速的提示,你实际上并没有问一个问题,你只是粘贴了一些代码并说出了你想要实现的目标,这就是为什么有人意味着向你倾诉。

所以你所追求的是Dot符号,假设你拥有的数组是你可以做的列表:

var data = [
    "San Mateo.",
    "San Francisco.",
    "Palo Alto.",
    "Redwood City.",
    "New York.",
    "Boston.",
    "Chicago.",
    "La Jolla.",
    "San Diego.",
    "San Carlos.",
    "San Bruno."
];

exports.handler = function(event, context, callback) {
    var alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

var handlers = {
    'LaunchRequest': function () {
        this.emit('GetNewFactIntent');
    },

    'GetNewFactIntent': function () {
        var cityName = this.event.request.intent.slots.value;

        // this is like doing data['San Mateo.']
        if(typeof data[cityName] !== 'undefined'){

            this.emit(":tell", LYFT_IS_AVALIABLE);

        } else {
            this.emit(":tell", LYFT_NOT_AVALIABLE);
        }
    }
}

您还可以在Lambda中使用console.log(someVariable)并在CloudWatch Logs中检查结果 - 仅供参考。您的城市是否需要'。'最后?