Search…
Search
Details about the Search user journey

The onSearch callback

Whenever the Assistant detects that the user is searching for items in the app, it will try to break down the search request into its basic components and invoke the onSearch callback associated with the search user journey. The callback looks like this:
Android Native
React Native
Flutter
Web
Android (Deprecated)
1
SearchAppState onSearch(SearchInfo searchInfo, SearchUserJourney userJourney);
Copied!
1
onSearch: async (searchInfo, searchUserJourney)
Copied!
1
SearchAppState onSearch(SearchInfo searchInfo, SearchUserJourney searchUserJourney)
Copied!
1
onSearch: async (searchInfo, searchUserJourney)
Copied!
1
// This is deprecated and is kept here for reference only
2
3
SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney userJourney);
Copied!
When this callback is invoked, the app is expected to:
  1. 1.
    Consume the details of the search request via the SearchInfo parameter.
  2. 2.
    Fire the app's search request.
  3. 3.
    Finally, return the AppState along with the appropriate Condition corresponding to the state that the app transitioned into
For example, for a given onSearch callback invocation, if the search completes successfully and the app transitions to a screen showing search results, the app would return theAppState as SEARCH_RESULTS along with condition SUCCESS , as shown below:
Android Native
React Native
Flutter
Web
1
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
2
String searchItem = searchInfo.getItem().getDescription();
3
4
// Launch SearchResultsActivity using "searchItem"
5
// ...
6
7
return new SearchResultsAppState(SUCCESS);
8
}
Copied!
1
onSearch: async (searchInfo, searchUserJourney) => {
2
var searchItem = searchInfo.item.description;
3
4
// Perform UI operation using "searchItem"
5
// ...
6
7
searchUserJourney.setSuccess();
8
return SearchUserJourney.AppState.SEARCH_RESULTS;
9
},
Copied!
1
@override
2
SearchAppState onSearch(SearchInfo searchInfo, SearchUserJourney searchUserJourney) {
3
String searchItem = searchInfo.item.description
4
5
// Update SearchResultsWidget using "searchItem"
6
// ...
7
8
searchUserJourney.setSearchSuccess();
9
return SearchUserJourney.AppState.SEARCH_RESULTS;
10
}
Copied!
1
onSearch: async (searchInfo, searchUserJourney) => {
2
const searchItem = searchInfo.item.description;
3
4
// Perform operation using "searchItem"
5
// ...
6
7
searchUserJourney.setSuccess();
8
return SearchUserJourney.AppState.SEARCH_RESULTS;
9
},
Copied!

Sample Utterances that could trigger the search

The following are some examples of commands that could trigger this journey
  • "Onions"
  • "Show me onions"
  • "3 kgs of organic onions"
  • "Looking for fresho organic onions"
  • "Searching for Maggi Instant noodles in grocery"
  • "2 rs head and shoulders shampoo"

SearchInfo Parameter

The parameterSearchInfo contains the breakdown of the original search request. Its structure is as described below:
Android Native
React Native
Flutter
Web
1
Class SearchInfo {
2
public Item getItem();
3
public List<FilterInfo> getFilters();
4
public SortingInfo getSorting();
5
public Boolean isAddToCart();
6
}
7
8
Class Item {
9
public String getId(); // The ID of the item if set by the app or if Slang
10
// was trained with it
11
public String getCategory(); // The category that the user specified,
12
// eg "pharmacy" or "grocery"
13
public String getBrand(); // The brand name identified by Slang from what the
14
// user spoke
15
public String getProductType(); // The product type if any as identified by Slang
16
public String[] getVariants(); // The variants (like "organic") if any
17
public String getDescrption(); // The helper method to get back a fully
18
// constructed search string from what the
19
// user spoke
20
public Quantity getQuantity(); // The quantity if any is spoken by the user
21
public Size getSize(); // The size if any is spoken by the user
22
public Price getPrice(); // The price value if any spoken by the user
23
}
Copied!
1
// When the user searches for something like
2
// 4 fresho organic onions 2 rupees 3kg in grocery
3
// This is how the SearchInfo parameter would be populated
4
5
{
6
"filterInfoList": [],
7
"item": {
8
"brand": "fresho organic",
9
"category": "grocery",
10
"description": "fresho organic onions",
11
"id": null,
12
"price": {
13
"currency": "INR",
14
"maxAmount": 2,
15
"minAmount": 2
16
},
17
"productType": null,
18
"quantity": {
19
"amount": 3,
20
"unit": "KG"
21
},
22
"size": {
23
"count": 4
24
},
25
"variants": [
26
"onions"
27
]
28
},
29
"isAddToCart": false,
30
"sortingInfo": {}
31
}
Copied!
1
class SearchInfo {
2
Item item;
3
bool isAddToCart;
4
SortingInfo sortingInfo;
5
List<FilterInfo> filterInfoList;
6
}
7
8
class Item {
9
String id; // The ID of the item if set by the app or if Slang was trained with it
10
String category; // The category that the user specified, eg "pharmacy" or "grocery"
11
String brand; // The brand name identified by Slang from what the user spoke
12
String productType; // The product type if any as identified by Slang
13
List<String> variants; // The variants (like "organic") if any
14
String description; // The helper method to get back a fully constructed search string from what the user spoke
15
Quantity quantity; // The quantity if any is spoken by the user
16
Size size; // The size if any is spoken by the user
17
Price price; // The price value if any spoken by the user
18
}
19
Copied!
1
// When the user searches for something like
2
// 3 fresho organic onions 2 rupees 3kg in grocery
3
// This is how the SearchInfo parameter would be populated
4
5
{
6
"filterInfoList": [],
7
"item": {
8
"brand": "fresho organic",
9
"category": "grocery",
10
"description": "fresho organic onions",
11
"id": null,
12
"price": {
13
"currency": "INR",
14
"maxAmount": 3,
15
"minAmount": 3
16
},
17
"productType": null,
18
"quantity": {
19
"amount": 2,
20
"unit": "UNKNOWN"
21
},
22
"size": {},
23
"variants": [
24
"onions"
25
]
26
},
27
"isAddToCart": false,
28
"sortingInfo": {}
29
}
Copied!
To illustrate, when the user says "Search for fresho organic onions in grocery", the following will be set in the Item object
  • id = null
  • category = null
  • quantity = null
  • size = null
  • price = null
  • brand = "fresho"
  • product type = "onion"
  • variants = ["organic"]
  • isAddedToCart = false
  • description = "fresho organic onion"

Supported AppStates

The following AppStates are supported:
  • SEARCH_RESULTS (SearchResultsAppState): To be returned when the app performs a search and navigates to the search results screen. To indicate whether the search was successful or not, with a greater level of detail, please use the appropriate conditions.
  • ADD_TO_CART (AddToCartAppState): To be returned when the app performs an add-to-cart action. To indicate whether the add to cart was successful or not, with a greater level of detail, please use the appropriate conditions.
  • UNSUPPORTED (UnsupportedAppState): To be returned when the app is not ready to handle search yet. The Assistant will let the user know that the search is not yet supported by the app.
The Slang Retail Assistant provides a special AppStateWAITING that is common across all UserJourney types for completing asynchronous operations within the callback. Refer to the Asynchronous Action Handling section for details of how to deal with asynchronous operations.

Supported Conditions

The following conditions are supported for each of the AppStates supported by the Assistant
App State
App State Condition
SEARCH_RESULTS
(SearchResultsAppState)
TERMINAL CONDITIONS
SUCCESS
The search was successful
ITEM_NOT_FOUND
The item being searched could not be
found
ITEM_OUT_OF_STOCK
The item being searched is out of stock
FAILURE
There was a failure while searching
NON-TERMINAL CONDITIONS
ITEM_NOT_SPECIFIED
The item that needs to be searched has
not been specified.
App State
App State Condition
ADD_TO_CART
(AddToCartAppState)
TERMINAL CONDITIONS
SUCCESS
The search was successful
ITEM_NOT_FOUND
The item being searched could not be
found
ITEM_OUT_OF_STOCK
The item being searched is out of stock
FAILURE
There was a failure while searching
NON-TERMINAL CONDITIONS
ITEM_NOT_SPECIFIED
The item that needs to be searched has
not been specified.
ITEM_AMBIGUOUS
There are multiple items available for
the current searched item and has to be
disambiguated.
ITEM_AMBIGUOUS_FORCE_UI
Stop the voice disambiguation process
and choose the item via the UI/Touch
interface.
ITEM_QUANTITY_REQUIRED
Quantity for the current item has to be
specified.
For example, to indicate to the Assistant that the particular item being searched was not found by the app, the app should do the following:
Android Native
React Native
Flutter
Web
Android (Deprecated)
1
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
2
String searchItem = searchInfo.getItem().getDescription();
3
4
// Launch SearchResultsActivity using "searchItem"
5
// ...
6
7
return new SearchResultsAppState(ITEM_NOT_FOUND);
8
}
Copied!
1
onSearch: async (searchInfo, searchUserJourney) => {
2
var searchItem = searchInfo.item.description;
3
4
// Perform UI operation using "searchItem"
5
// ...
6
7
searchUserJourney.setSuccess();
8
return SearchUserJourney.AppState.SEARCH_RESULTS;
9
},
Copied!
1
SearchAppState onSearch(SearchInfo searchInfo, SearchUserJourney searchUserJourney) {
2
String searchItem = searchInfo.item.description
3
4
// Update SearchResultsWidget using "searchItem"
5
// ...
6
7
searchUserJourney.setSuccess();
8
return SearchUserJourney.AppState.SEARCH_RESULTS;
9
}
Copied!
1
onSearch: async (searchInfo, searchUserJourney) => {
2
var searchItem = searchInfo.item.description;
3
4
// Perform UI operation using "searchItem"
5
// ...
6
7
searchUserJourney.setSuccess();
8
return SearchUserJourney.AppStates.SEARCH_RESULTS;
9
},
Copied!
1
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
2
String searchItem = searchInfo.getItem().getDescription();
3
4
// Launch SearchResultsActivity using "searchItem"
5
// ...
6
7
userJourney.setItemNotFound();
8
return SearchUserJourney.AppState.SEARCH_RESULTS;
9
}
Copied!

Assistant Prompts

Based on the App State and the Condition that was set, the Assistant will speak out an appropriate message to the user. You can examine the default set of prompts configured for the Assistant through the Console and also customize it to your needs. Refer to the Customizing the Assistant section for details.