- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 Alexa 创建一项技能,根据我选择的 tg 类别重现 .mp3 文件。我声明我从未使用过 node.js
并且我看过一门关于如何创建 alexa 技能的类(class)。到目前为止,我已经创建了该技能的框架,并创建了一个 database.json
文件,其中包含带有附加链接的各种新闻类别。
INDEX.JS
const Alexa = require('ask-sdk-core');
const database = require('./database');
function getCategoryStreamUrl(name) {
let category = database.find(e => e.name === name);
if (category !== null && category !== undefined) {
return category.StreamUrl;
} else {
return "";
}
}
function getCategoryUpdateDate(name) {
let category = database.find(e => e.name === name);
if (category !== null && category !== undefined) {
return category.UpdateDate;
} else {
return "";
}
}
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'Welcome, with this skill you can listen to our TG. You can choose a category or say Help.';
const repromptOutput = 'You can choose a category or say Help. What do you want to do?'
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(repromptOutput)
.getResponse();
}
};
const ScegliCategoriaIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'ScegliCategoriaIntent';
},
handle(handlerInput) {
const speakOutput = 'The TGs available are: Political, Lazio, Environment, Health, School, Pediatrics, Rehabilitation, Agriculture, Psychology and Youth. Which do you want to hear?'
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(repromptOutput)
.getResponse();
}
};
const CategoriaIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'CategoriaIntent';
},
handle(handlerInput) {
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
console.log("CategoriaIntentHandler >>>>>>>>>>>>>>>>");
console.log(slotValues);
const categoryName = slotValues["category"].synonym
const categoryStreamUrl = getCategoryStreamUrl(categoryName);
const categoryUpdateDate = getCategoryUpdateDate(categoryName);
var speakOutput = "";
if (categoryStreamUrl !== "") {
speakOutput = "You have chosen the TG " + categoryName + ". The TG was updated on " + categoryUpdateDate + ". " + categoryStreamUrl + ". If you want to hear other news, name another TG or you can say STOP to close this skill.";
} else {
speakOutput = "I'm sorry, the selected TG is not available. You can say the name of another TG or 'categories' to hear the list of available categories. What do you want to do?";
}
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt("If you want to hear more news, say the name of another TG. You can say 'categories' to listen to the list of available categories or you can say STOP to close this skill. What do you want to do?")
.getResponse();
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speakOutput = "You can say 'categories' to listen to the list of available categories or you can say STOP to close this skill. What do you want to do?";
const repromptOutput = "If you want to stop listening, say STOP."
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(repromptOutput)
.getResponse();
}
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent'
|| Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const speakOutput = "Goodbye!";
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
},
handle(handlerInput) {
// Any cleanup logic goes here.
return handlerInput.responseBuilder.getResponse();
}
};
// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
const IntentReflectorHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest';
},
handle(handlerInput) {
const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
const speakOutput = `You just triggered ${intentName}`;
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`~~~~ Error handled: ${error.stack}`);
const speakOutput = `I'm sorry I did not understand. Say 'Help' to know the available commands.`;
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
function getSlotValues (filledSlots) {
let slotValues = {}; //
console.log('The filled slots: ' + JSON.stringify(filledSlots));
Object.keys(filledSlots).forEach(function(item) {
var name = filledSlots[item].name;
if(filledSlots[item]&&
filledSlots[item].resolutions &&
filledSlots[item].resolutions.resolutionsPerAuthority[0] &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code ) {
switch (filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
case "ER_SUCCESS_MATCH":
slotValues[name] = {
"synonym": filledSlots[item].value,
"resolved": filledSlots[item].resolutions.resolutionsPerAuthority[0].values[0].value.name,
"isValidated": true
};
break;
case "ER_SUCCESS_NO_MATCH":
slotValues[name] = {
"synonym": filledSlots[item].value,
"resolved": filledSlots[item].value,
"isValidated":false
};
break;
}
} else {
slotValues[name] = {
"synonym": filledSlots[item].value,
"resolved": filledSlots[item].value,
"isValidated": false
};
}
},this);
return slotValues;
}
// The SkillBuilder acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
ScegliCategoriaIntentHandler,
CategoriaIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
)
.addErrorHandlers(
ErrorHandler,
)
.lambda();
数据库.JSON
[
{
"uid":"ID",
"updateDate": "DATA",
"name": "NAME SLOT",
"titleText": "TG 01",
"mainText":"",
"streamUrl":"https://www.mysite.it/tg.mp3",
"redirectionUrl":"https://www.mysite.it/category/tg"
},
{
etc_01
},
{
etc_02
},
{
etc_03
},
]
问题是现在它不起作用,事实上当我让 alexa 告诉我 TG 01 她告诉我:
"You have chosen the TG 01. The TG was updated on undefinied. Undefinied. another TG or you can say STOP to close this skill. "
简而言之,它不识别categoryUpdateDate
或categoryStreamUrl
。
我该怎么做才能修复它?
最佳答案
您在两个函数中都返回了错误的数据:
它们应该是:category.updateDate
和 category.streamUrl
,因为您正在读取 JSON 文件。 (也许阅读 this guide 以更好地理解如何读取和访问 JSON 属性等。)
function getCategoryStreamUrl(name) {
let category = database.find(e => e.name === name);
if (category !== null && category !== undefined) {
return category.streamUrl;
} else {
return "";
}
}
function getCategoryUpdateDate(name) {
let category = database.find(e => e.name === name);
if (category !== null && category !== undefined) {
return category.updateDate;
} else {
return "";
}
}
关于javascript - 来自 Alexa 开发人员控制台的 Alexa 技能 : is it possible to have Alexa play a . mp3 - Alexa 托管?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59160994/
我有一个包含需要排序的不同项目的列表。但还有一个额外的问题:某些元素只允许出现在列表中的特定位置。 示例(请查看 http://jsfiddle.net/pYL32/2/ ):有一个包含元素 foo、
关于https://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained据解释,guava(以及后来的 java 8
我有一个名为 say CalculationOutcome 的类(class)和 FileHashOutcome .他们的构造函数有 (ActualResult, Throwable)参数,并在 Co
我正在使用pycharm,我的代码在分屏上。当我运行调试时,会弹出调试/运行窗口,它非常分散注意力并且限制了我在调试时可以查看的代码量......但我想保持它,因为我来回走动;另外,我想要调试变量的完
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: javascript object, access variable property name? 我确信这是可以完
if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {
在将实体存储在 redis 中作为序列化二进制 blob 的应用程序中工作。我有多个客户端处理同一个数据集,我希望使用乐观并发。 我的要求是: 在一次往返中读取特定键的序列化实体 将修改后的实体写回r
这个问题是指 C/x86 上使用的 IEEE 标准浮点数。 是否可以将任何数字(即不包括 NaN 之类的特殊值)浮点数或 double 数表示为十进制字符串,以便将该字符串转换回浮点数/ double
我的团队目前正在与 Lua 合作,创建一个 android 游戏。我们遇到的一件事是表面上无法创建重载构造函数。 我习惯于使用默认值设置一个对象,然后在需要时使其过载。 前任: apples() {
如何在 Scene Kit 中使用 SCNCamera 获得像鱼眼镜头那样的失真? 类似于这种图像的“鞠躬”: //正如 Rickster 指出的那样,这种失真被称为“桶形失真”。 从文档中,这是让我
我想问是否有一种方法可以多次评估 javascript 术语,而不需要一遍又一遍地解析一个术语。 说,您想要评估 var1/var2+Math.sqrt(var3) 每秒 20 次。 使用时这可能会出
我想知道在技术上是否可以在 java applet 中创建代理。 那么是否可以通过这个 java applet 代理路由所有进一步的浏览器请求? 例如,如果用户要浏览 google.com,默认行为是
我有以下代码,我想返回一个 bool 值或一个元组。 (函数 isvariable 和 dont_care 都返回 bool 值,仅供引用) let match_element (a, b) = if
这个问题困扰我很久了。我想要一个二叉树(或类似的嵌套结构)上的迭代器,它高效、简单且Pythonic。例如,对于这样的用法: for value in values(root): do_som
目前我有以下 MySQL 查询: SELECT COUNT(*) AS `count`, `v`.`value` FROM `client_entity_int` AS `v` INN
我正在使用 Angular 开发应用程序,客户端是 100% JS。我即将替换使用 ExtJS 制作的旧应用程序,但我不会更改服务器端。只有客户端从头开始重新编码。 我想在任何地方和任何机器上处理这个
有没有办法在运行时检索实例的声明类?例如: public class Caller { private JFrame frame = new JFrame("Test"); priva
我目前正在请求 MySQL 数据库使用 PDO 计算一些计数和总和。这个过程可能需要一段时间,如果用户突然想浏览另一个页面,他可能会停留在浏览器前面。 我试图弄清楚是否可以使用 PDO 启动 MySQ
想知道它是不是这样工作的: $result .= mysqli_query($query1); $result .= mysqli_query($query2); $result 会是查询 1 和 2
所以我有这样的挑战: body 背景上的图像,背景大小,覆盖以适合整个屏幕。在背景图像上是一些元素(建筑物)。所以我想将鼠标悬停在建筑物上,他们会更改颜色或添加阴影等。问题在于屏幕调整大小,当我调整屏
我是一名优秀的程序员,十分优秀!