jovo.getRequestObject is not a function in onRequest event


#1

Hello,

I am trying to use onRequest event to inject some data to the request data, but it seems that it doesn’t exist in the event. Also, the example you give in the docs doesn’t work, because apparently jovo object doesn’t have getRequestObject method.

What I did is just created a new skill using cli and just added an event handler as described in the docs:

app.onRequest(function (jovo) {
    console.log(jovo.getRequestObject());
})

Any ideas what’s up? Also is it possible to access request data in the event? I found, that only app data is accessible there. If there is any different, I am using JS.

Thanks.


#2

Hey!

Looks like Jovo v1 code in the docs.

Try

app.onRequest((handleRequest) => {
    console.log(handleRequest.host.getRequestObject());
});

Or a little cleaner:

app.onRequest(({host}) => {
    console.log(host.getRequestObject());
});

#3

Thanks, seems to be working.

I have one more question. What is the best way to access session attributes in these events? I have built this monstrosity:
jovo.host.req.body.session.attributes

Maybe there is some sort of helper method or shortcut to do that, that I am not aware of?


#4

What’s your use case?

You could use a later stage of the middleware hooks.

app.hook('after.platform.init', (error, host, jovo) => {
    console.log(jovo.$session.$data)
});

This will be called after the platform and the jovo object has been initialized.


#5

Thanks, this is exactly what I needed. I wanted to manipulate some session attributes and inject some stuff before handler execution.