User

In this section, you will learn how to use the Jovo User class to persist user specific data and create contextual experiences for your voice apps.

Introduction to the User Class

The User object offers helpful features to build contextual, user specific experiences into your voice applications.

You can access the user object like this:

Configuration

There are certain configurations that can be changed when dealing with the user object. The following are part of the Jovo default configuration:

saveUserOnResponseEnabled: You can set this to false if you choose not to save any user-specific data.

userDataCol: Specifies the name of the column that the user data is saved to.

userMetaData: Specifies what and how meta data is saved. Learn more about meta data here.

User Data

The User object offers the capability to store and retrieve user specific data, including meta data.

Data is stored using our database integrations, with a file-based db.json structure enabled by default.

Data Persistence

With our Jovo Persistence Layer, you can store user specific data easily to either a database or a local JSON file.

Just specify a key and a value, and you're good to go:

For more information on data persistence, take a look here: Integrations > Databases.

Meta Data

The user object meta data is the first step towards building more contextual experiences with the Jovo Framework. Right now, the following data is automatically stored (by default on the FilePersistence db.json, or DynamoDB if you enable it):

Meta Data Usage Description
createdAt this.user().metaData.createdAt Timestamp: When the user first used your app
lastUsedAt this.user().metaData.lastUsedAt Timestamp: The last time your user interacted with your app
sessionsCount this.user().metaData.sessionsCount Timestamp: How often your user engaged with your app

You can change the type of meta data to store with the Jovo app constructor. This is the default configuration for it:

Context

The user context is used to automatically store data from past interaction pairs (request and response) inside an array. To be able to use this feature, a database integration is required (data is stored in the FilePersistence db.json by default, but for e.g. AWS Lambda it is important to set up DynamoDB.

This works like pagination. The most recent request and response pair are stored at this.user().context.prev[0] and the least recent at this.user().context.prev[this.config.userContext.prev.size - 1].

Right now, the following data can be accessed (with index i):

Category Data Usage Description
Request intent this.user().context.prev[i].request.intent this.user().getPrevIntent(i) String: Intent name
  state this.user().context.prev[i].request.state this.user().getPrevRequestState(i) String: State name
  timestamp this.user().context.prev[i].request.timestamp this.user().getPrevTimestamp(i) String: Timestamp of request
  inputs this.user().context.prev[i].request.inputs this.user().getPrevInputs(i) Object: Contains all the slots (filled & unfilled). Example: You got a slot called city. Access the value with this.user().getPrevInputs(i).city.value.
Response speech this.user().context.prev[i].response.speech this.user().getPrevSpeech(i) String: Primary speech element
  reprompt this.user().context.prev[i].response.reprompt this.user().getPrevReprompt(i) String: Reprompt element
  state this.user().context.prev[i].response.state this.user().getPrevResponseState(i) String: State name

By default, only the last interaction pair is stored. You can freely adjust how many of these pairs should be saved by changing the array size in your app's config to an Integer equal to or bigger than 0.

You can also decide what you want to save and what not. Simply change the value of the unwanted data to false:

The default configuration looks like this:

User ID

Returns user ID on the particular platform, either Alexa Skill User ID or Google Actions User ID:

This is going to return an ID that looks like this:

Locale

Returns the platform's locale:

Account Linking

To implement Account Linking in your voice application, you need two core methods.

The first allows you to prompt the user to link their account, by showing a card in the respective companion app:

The other method returns you the access token, which will be added to every request your skill gets, after the user linked their account:

For more information on Account Linking, check out our blogposts:

Comments and Questions

Any specific questions? Just drop them below. Alternatively, you can also fill out this feedback form. Thank you!

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.