alexa - Alexa Skill 与 Cheerio
问题描述
您好,我正在尝试在 Alexa Skill 中使用cheerio 从网站获取数据并添加技能。意图代码
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'all_titles';
},
handle(handlerInput) {
//Lógica para speak output
var options = {
uri: 'https://es.pagetest.com/',
transform: function (body) {
return cheerio.load(body);
}
};
rp(options)
.then(function ($) {
var arr_response = []
var titles = $('.ms-short-title');
titles.each((i, a) =>{
if(a.parent.attribs.title !== undefined)arr_response.push(a.parent.attribs.title);
});
const speakOutput = insert_in_string(arr_response);
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
function insert_in_string (arr_titulars){
var string_text = '';
for(var titular of arr_titulars){
string_text += titular + ' Siguiente titular. ';
}
return string_text;
}
})
.catch(function (err) {
return err;
});
}
};
我已经在本地测试了逻辑并且它工作正常,通过将它放在 alexa 代码编辑器中,在测试中,返回错误消息,但没有跟踪¿任何想法?谢谢
解决方案
如果您使用的是 Alexa 托管的技能,您将已经内置 CloudWatch 集成。只需转到您的 Amazon 开发人员控制台,导航到您的技能代码选项卡,滚动到底部并单击左下方的日志:Amazon CloudWatch链接。
现在,每次您发送时console.log
,它都会被发送到 CloudWatch。所以,在你的catch
处理程序中,添加console.log(err)
,你应该能够看到出了什么问题。
推荐阅读
- javascript - 如何在 InfoBubble 中调用外部点击事件 - 这里是 API Javascript 3
- sql-server - SQL Server:在 UPDATE 上使用 ROWLOCK 和 OUTPUT
- php - 亚马逊 AWS - Auto Scaling Wordpress 站点
- c# - 在控制器中有多个存储库如何使用构造函数
- css - 使用@media 查询隐藏和显示响应式代码
- javascript - 用map方法求总数?
- sql - 使用自动增量合并两个 SQL Server 表的数据
- linux - Autosys:最小的 JIL 文件
- c++ - 使用 SetTokenInformation 创建提升的令牌返回错误 87
- gcc - Solaris 8 GCC 安装