Accessing and Setting User Journey Context

Programmatically setting and accessing journey specific context

When the user journey callbacks are called, the Assistant passes details of the command via the Info parameter. But when users trigger the same user journey multiple times, the Assistant preserves the context of the previous invocation and reuses it. For example:

  1. Let's say the user says "onions"

  2. The Assistant invokes the onSearch callback and passes the SearchInfo object with "onions" as the value for theproductType field. All other fields in the object will be empty.

  3. Now let's say the user says "show me organic ones"

  4. The Assistant now invokes the onSearch callback again and this time passes the SearchInfo object with two fields set: variant with "organic" as the value and also productTypewith "onions" as the value. This way, it preserves the context between multiple invocations.

Sometimes the app might want to access or set the context outside the scope of the callbacks.

The Assistant is built to be used in a multi-modal environment, where the users might use the UI to perform certain operations and voice to perform others. It's quite natural for the user to be searching for an item by typing it and then switch to voice to provide additional filters. In such cases, the app can pass data to the Assistant explicitly via the appropriate user journey context APIs, as below:

SearchUserJourney.getContext().getProductType();
SearchUserJourney.getContext().setProductType("onions");

Sometimes, it could be important to not preserve context automatically. For example, if the user has cleared the results and started a new search, then this may need to be treated as a fresh search rather than as a continuation of the previous search.

In such cases, the app can easily clear the context as shown below

SearchUserJourney.getContext().clear();

Last updated