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:
Let's say the user says "onions"
The Assistant invokes the
onSearch callback and passes the
SearchInfo object with "onions" as the value for the
productType field. All other fields in the object will be empty.
Now let's say the user says "show me organic ones"
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:
var category = SearchUserJourney.context.getItemCategory();SearchUserJourney.context.setItemCategory("grocery");
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