Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal Express logging altered with alexa-app? How to show incoming POST requests from Alexa? #338

Open
roschler opened this issue Apr 22, 2018 · 1 comment

Comments

@roschler
Copy link

roschler commented Apr 22, 2018

I've noticed that when I have the alexa-app handlers active, the normal HTTP URL request logging seems to go inactive. That is, whenever I receive an Alexa Skill request, I don't see anything in my IDE Console/Log window describing the request. Normally I expect to see a message like "POST /api/alexa" or similar. Is there some option or setting I need to set to get the POST requests handled by alexa-app shown in the console/log?

Note, the console.log() does work since I have several of those in my alexa-app preRequest and postRequest functions.

DRIVE-BY QUESTION: In the incoming JSON I several instances like this:

sessionId: 'amzn1.echo-api.session.[unique-value-here]'

Is the presence of the [unique-value-here] string due to the fact the Alexa request is originating from the management console and not real Alexa skill origin point like the simulator or a device like an Echo? will I see actual values during real interactions with Alexa when I am handling real requests instead of requests coming from the management console Test facility?

Note, if there is an IRC chat room, gitter room, or other place I should be asking these general question rather than on the Issues forum here, please point me to that venue.

@fremail
Copy link
Contributor

fremail commented Oct 22, 2018

@roschler Every request to your skill goes through preRequest (app.express options) and app.pre callbacks. You can log all required data in one of those places.

So the code for logging will look like that:

var express = require("express");
var Alexa = require("alexa-app");
var express_app = express();
var app = new Alexa.app("my_skill");
app.express({ 
    expressApp: express_app,
    preRequest: function (json, req, resp) {
        // log incoming request here
        console.log(`POST ${req.originalUrl}\n\n${JSON.stringify(json)}`);
    }
});

app.pre = function (request, response, requestType) {
    // or log the request here
    // path is an Alexa app name
    // incoming JSON is stored in `request.data`
    console.log(`POST /${app.name}\n\n${JSON.stringify(request.data)}`);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants