question

newuser-02ca8f03-8510-43c6-8ccc-33875181e8b4 avatar image

Web service invocation problem

Hello,


I have a web application which is returning response as string. I have the following code


const HelloWorldIntentHandler = {

canHandle(handlerInput) {

return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'

&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent';

},

handle(handlerInput) {

var speakOutput;

request('http://8ccdee84.ngrok.io', function (error, response, body) {

console.log('error:', error); // Print the error if one occurred

console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received

console.log('body:', body); // Print the body

speakOutput = body;

});

return handlerInput.responseBuilder

.speak(speakOutput)

.reprompt(speakOutput)

.getResponse();

}

};


The 'body' of the request has the string data and i could see the string value get printed in the console log. However the speakOutput on .speak is empty and getting the following response.


{

"body": {

"version": "1.0",

"response": {

"outputSpeech": {

"type": "SSML",

"ssml": "<speak></speak>"

},

"reprompt": {

"outputSpeech": {

"type": "SSML",

"ssml": "<speak></speak>"

}

},

"shouldEndSession": false,

"type": "_DEFAULT_RESPONSE"

},

"sessionAttributes": {},

"userAgent": "ask-node/2.7.0 Node/v8.10.0"

}

}


Anyone help me what is the issue in the code and please explain me why i'm getting the string value in the console and not on the speak output.

alexa skills kitapi
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers