Modify userId before persisting to User data store


For both Alexa and Google Action, you can persist this.$user.$data values using the user’s ID. Is there a way to dynamically control the userID value so that you can add your own prefix or suffix?

For eample instead of:
"userId": "amzn1.ask.account.d5c062dd-2f06-4bed-a0ee-71ac2c5f368e",

I might want to add a suffix for which platform, so that I can have both platforms in the same data store and easily determine the platform:

"userId": "amzn1.ask.account.d5c062dd-2f06-4bed-a0ee-71ac2c5f368e::alexa",

Or, I might want to be able to generate a unique code for a user and use that instead:
"userId": "my-unique-code",

And find a way to have the same unique code in other platforms linked to a user so that 1 user record can be used by the same user across multiple platforms. I could start a game on Alexa in the car and continue on Google Assistant at home.

@AlexSwe @jan Let me know if you have any questions.


You could use a hook for that:

app.hook('after.request', (error: JovoError, host: Host, jovo: Jovo) => {


How is this done in Dialogflow?

I keep getting DIALOGFLOW-DEFAULT-USER-ID when i use jovo.$request.getUserId() after I did the jovo.$request.setUserId('myID') call.


@dominik-meissner if your are getting DIALOGFLOW-DEFAULT-USER the original detected request (inside the dialogflow request) does not implement the getUserId Method. I assume you are not using a GoogleAction -right?
@AlexSwe I think there is one more problem: for googleAction Requests the setUserId Function is now working because your last commit changed the setUserId Method to access user.userStorage. But the getUserId Method is still accessing user.userId which is not defined. Therefore it will allways return undefined.



Good point. Will investigate and release an update.