Search
Details about the Search user journey
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
Web
SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney userJourney);
onSearch: async (searchInfo, searchUserJourney)
onSearch: async (searchInfo, searchUserJourney)
When this callback is invoked, the app is expected to:
- 1.Consume the details of the search request via the
SearchInfo
parameter. - 2.Fire the app's search request.
- 3.Finally, return the
AppState
along withCondition
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 set the condition to SUCCESS and return AppState
as SEARCH_RESULTS, as shown below: Android Native
React Native
Web
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
String sourceCity = searchInfo.getSrcCity().getName()
String destinationCity = searchInfo.getDestCity().getName()
Date travelDate = searchInfo.getItem().getDescription();
// Launch SearchResultsActivity using "searchItem"
// ...
userJourney.setSuccess();
return SearchUserJourney.AppState.SEARCH_RESULTS;
}
onSearch: async (searchInfo, searchUserJourney) => {
var searchItem = searchInfo.item.description;
// Perform UI operation using "searchItem"
// ...
searchUserJourney.setSuccess();
return SearchUserJourney.AppState.SEARCH_RESULTS;
},
onSearch: async (searchInfo, searchUserJourney) => {
const searchItem = searchInfo.item.description;
// Perform operation using "searchItem"
// ...
searchUserJourney.setSuccess();
return SearchUserJourney.AppState.SEARCH_RESULTS;
},
The following are some examples of commands that could trigger this journey
- "Bangalore to Chennai"
- "Book a ticket to Mumbai"
- "Trains from Delhi "
The
SearchInfo
parameter contains the breakdown of the original search request. It's structure is as described below: Android Native
React Native
Web
Class SearchInfo {
public TravelMode getTravelMode(); //Bus/Train/Flight
public Station getSource(); //Details of the travel starting point
public Station getDestination(); //Details of the travel destination point
public Date getOnwardDate(); //Details of the journey date
public TimeRange getOnwardDepartureTimeRange();
public TimeRange getOnwardArrivalTimeRange();
public TripType getTripType();
public Date getReturnDate();
public TimeRange getReturnDepartureTimeRange();
public TimeRange getReturnArrivalTimeRange();
public List<FilterInfo> getFilters();
public SortInfo getSortInfo();
public PriceInfo getPriceInfo();
public PassengersInfo getPassengersInfo();
}
Class Station {
public String getId(); //App provided
public String getCode(); //Station code if any.
public String getTerminal(); //Stop name if any.
public String getCity(); //City name
public String getProvince(); //State name
public String getCountry(); //Country name
}
Enum TravelMode {
UNKNOWN,
BUS,
TRAIN,
FLIGHT
}
Class TimeRange {
public Date getStartTime();
public Date getEndTime();
}
Class PriceInfo {
public int getMinPrice();
public int getMaxPrice();
public Currency getCurrency();
}
Class FilterInfo {
public String getFilterValue();
public String getFilterName();
}
Class SortInfo {
public SortType getSortType();
public SortOrder getSortOrder();
}
Enum Currency {
INR,
USD
}
Enum SortType {
PRICE,
DEPARTURE_TIME,
ARRIVAL_TIME,
DURATION,
RATING,
SEATS_AVAILABLE,
}
Enum SortOrder {
ASCENDING,
DESCENDING
}
Class PassengersInfo {
public int getCount();
public PassengerType getPassengerType();
}
Enum PassengerType {
ADULT,
CHILD,
INFANT
}
N/A
N/A
To illustrate, when the user says "Book a bus from Banglaore to chennai tomorrow ", the following will be set in the
SearchInfo
object - getTravelMode() = TravelMode.BUS
- getSource().getCity() = "bangalore"
- getDestination().getCity() = "chennai"
- getOnwardDate() = Date(<next day>)
The following
AppState
s are supported:- SEARCH_RESULTS : 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.
- UNSUPPORTED : 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 Travel Assistant provides a special
AppState
called WAITING
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.The following conditions are supported for each of the
AppState
s supported by the AssistantApp State | Condition | Description |
SEARCH_RESULTS |
|
|
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
Web
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
String searchItem = searchInfo.getItem().getDescription();
// Launch SearchResultsActivity using "searchItem"
// ...
userJourney.setRouteNotFound();
return SearchUserJourney.AppState.SEARCH_RESULTS;
}
onSearch: async (searchInfo, searchUserJourney) => {
var searchItem = searchInfo.item.description;
// Perform UI operation using "searchItem"
// ...
searchUserJourney.setSuccess();
return SearchUserJourney.AppState.SEARCH_RESULTS;
},
onSearch: async (searchInfo, searchUserJourney) => {
var searchItem = searchInfo.item.description;
// Perform UI operation using "searchItem"
// ...
searchUserJourney.setSuccess();
return SearchUserJourney.AppStates.SEARCH_RESULTS;
},
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.
Last modified 1yr ago