要获取Alexa请求的supportedInterfaces属性的所有可能值,可以通过Alexa Skill开发工具包提供的请求对象(request object)来获取。
以下是使用Node.js开发Alexa Skill的代码示例:
const Alexa = require('ask-sdk-core');
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const supportedInterfaces = Alexa.getSupportedInterfaces(handlerInput.requestEnvelope);
const supportedInterfaceKeys = Object.keys(supportedInterfaces);
// 输出所有支持的接口
console.log(supportedInterfaceKeys);
return handlerInput.responseBuilder
.speak('欢迎使用')
.getResponse();
}
};
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(LaunchRequestHandler)
.lambda();
在以上代码中,我们创建了一个处理LaunchRequest的处理程序(handler)。在处理程序中,我们使用Alexa.getRequestType()函数来检查请求类型是否为LaunchRequest。然后,使用Alexa.getSupportedInterfaces()函数获取supportedInterfaces属性的值,并使用Object.keys()函数获取所有支持的接口的键值。
你可以在控制台的开发者工具中查看输出,以获取所有可能的supportedInterfaces属性值。
上一篇:Alexa测试无声音。