I try get text from hosted text file into skill handler, but when I test skill show an error "SpeechletResponse was null"

90 Views Asked by At

I develop Alexa Skill in Alexa developer, I begin to learn about this, my skill try get text from a promise connects to hosted text file, the request is succesfully. But skills shows an error.

I need help to resolve this error on alexa skill. Share my code This is my handler

const InformacionIntentHandler = {
canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'InformacionIntent';
},


 async  handle(handlerInput) {
    const response = await 
 reader.readFile('res.cloudinary.com','/fdgdfg/raw/upload/v1656032273/fofo_mbbjr0.txt');

console.log(response);

    return handlerInput.responseBuilder
            .speak("Okay. Here is what I got back from my request. " + response)
            .reprompt("What would you like?")
            .getResponse();
  },
};

the async function into handler is:

const https = require('https');
var text = '';
module.exports = {
    readFile: (host,path) => {
       return new Promise(((resolve, reject) => {
           var options = {
               host: host,
               path: path,
               method: 'GET',
            };
            const request = https.request(options, (response) => {
                response.setEncoding('utf8');
                 response.on('data', (chunk) => {
                   text += chunk;
                 });
                response.on('end', () => {
                    //let lr = new LineByLineReader(response);
                 // lr.on('error', function (err) {
                  return text;
                });
              
               
                response.on('error', (error) => {
                    reject(error);
                });
            });
            request.end();
        }));
    }
};
  

And this is error response:

{
    "type": "SessionEndedRequest",
    "requestId": "amzn1.echo-api.request.13227b68-28b0-49d1-b29e-3ac7324093df",
    "timestamp": "2022-06-24T06:22:07Z",
    "locale": "es-MX",
    "reason": "ERROR",
    "error": {
        "type": "INVALID_RESPONSE",
        "message": "SpeechletResponse was null"
    }
}

The async function doesn't trigger the error, because log show response.

1

There are 1 best solutions below

0
LootingLentils On

Couple of things to check.

  1. Make sure that handler is getting invoked. A sample request JSON would help. Also perhaps add a console.log('InformacionIntentHandler') line in your handle function so you can verify in your logs.

  2. How long is it taking for the async operation to complete? You only have a few (~8) seconds before the request to your skill times out. If using a Lambda function, you may also need to increase the timeout configured there.