Reputation: 1415
Hello I'm trying to use cheerio in a Alexa Skill to get data from website and add in skill. The code of intent
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;
});
}
};
I have tested the logic locally and it works ok, by putting it in alexa code editor, in test, return error message, but not a trace ¿Any idea? Thanks
Upvotes: 0
Views: 67
Reputation: 111
If you are using Alexa-hosted Skills, you will have CloudWatch integration already built-in. Simply go to your Amazon Developer Console, navigate to your Skill's Code tab, scroll to the bottom and click the Logs: Amazon CloudWatch link on the bottom left.
Now, every time that you console.log
, it will be sent to CloudWatch. So, in your catch
handler, add console.log(err)
and you should be able to see what's going wrong.
This blog post might also help: https://developer.amazon.com/blogs/alexa/post/71ac4c05-9e33-41d2-abbf-472ba66126cb/3-tips-to-troubleshoot-your-custom-alexa-skill-s-back-end
Upvotes: 1