简体   繁体   中英

Alexa NodeJS failing on speechoutput without a specific error

I'm trying to create an Alexa skill that looks up locations on a web service based on the location of the Alexa Device.

I have all the code working, as I can see the right outputs in the logs, but the one thing I'm struggling with is getting the speech output to work.

Any help would be greatly appreciated. I'm quite new to NodeJS. I have a feeling it's something related to calling the tell within the https.request, but I don't now how to resolve that.

Code:

deviceAddressRequest.then((addressResponse) => {
    switch(addressResponse.statusCode) {
        case 200:
            console.log("Address successfully retrieved, now responding to user.");
            const address = addressResponse.address;
            const postcode = `${address['postalCode']}`;

            // Get JSON response

            console.info("test begin");

            var post_data =
            {
                "postcode":
                "`${address['postalCode']}`"
            };
            console.info ('Users postcode is ' + postcode);
            var post_options = {
                host:  '[redacted]',
                port: '443',
                path: '/alexa/address.php?postcode=' + encodeURI(postcode),
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Content-Length': Buffer.byteLength(JSON.stringify(post_data))
                }
            };
            console.info ('Post options set');
            var post_req = https.request(post_options, function(res) {
                res.setEncoding('utf8');
                var returnData = "";
                res.on('data', function (chunk) {
                    returnData += chunk;
                });
                res.on('end', function () {
                    console.info("Data returned!")
                    console.info('returnData: ' + returnData);
                    var nearBoutique = JSON.parse(returnData).location1;
                    console.info("Nearest location: " + nearLocation);
                    const ADDRESS_MESSAGE = "Your nearest location is: " + nearLocation;
                });
            });
            post_req.write(JSON.stringify(post_data));
            post_req.end();
            console.info(ADDRESS_MESSAGE);
            // I tried it here, and also under the "const ADDRESS_MESSAGE"
            this.emit(":tell", ADDRESS_MESSAGE);
            break;
        case 204:
            console.log("Successfully requested from the device address API, but no address was returned.");
            this.emit(":tell", Messages.NO_ADDRESS);
            break;
        case 403:
            console.log("The consent token we had wasn't authorized to access the user's address.");
            this.emit(":tellWithPermissionCard", Messages.NOTIFY_MISSING_PERMISSIONS, PERMISSIONS);
            break;
        default:
            this.emit(":ask", Messages.LOCATION_FAILURE, Messages.LOCATION_FAILURE);
    }

    console.info("Ending getAddressHandler()");
});

And the Lambda CloudWatch log:

START RequestId: *** Version: $LATEST
Beginning execution for skill with APP_ID=amzn1.ask.skill.***
Starting newSessionRequestHandler()
Starting getAddressHandler()
Creating AlexaAddressClient instance.
Ending newSessionRequestHandler()
Ending execution for skill with APP_ID=amzn1.ask.skill.***
Device Address API responded with a status code of : 200
Address successfully retrieved, now responding to user.
test begin
Users postcode is *** ***
Post options set
Data returned!
returnData: {"location1":"123 Street Name, London, is currently open.","location2":"123 Street Name, London, is currently open.","store3":"123 Street Name, London, is currently open.","postcode":*** ***}
Nearest location: 123 Street Name, London, is currently open.
END RequestId: ***
REPORT RequestId: Duration: 1869.51 ms Billed Duration: 1900 ms Memory Size: 128 MB Max Memory Used: 31 MB
START RequestId:  Version: $LATEST
Beginning execution for skill with APP_ID=amzn1.ask.skill.***
Starting sessionEndedRequestHandler()
Ending sessionEndedRequestHandler()
Ending execution for skill with APP_ID=amzn1.ask.skill.***
END RequestId: 
REPORT RequestId:  Duration: 15.49 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 31 MB

I'm not looking for a direct solution, but a pointer in the right direction would be great please.

Thanks

this关键字在JavaScript中的工作方式似乎是一个问题,您需要从mdn中检查此链接以进一步了解它的工作方式以及关于箭头功能的工作方式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM