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:
When this callback is invoked, the app is expected to:
Consume the details of the search request via the SearchInfo parameter.
Fire the app's search request.
Finally, return the AppState along with 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 set the condition to SUCCESS and return AppState as SEARCH_RESULTS, as shown below:
publicSearchUserJourney.AppStateonSearch(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();returnSearchUserJourney.AppState.SEARCH_RESULTS;}
onSearch:async (searchInfo, searchUserJourney) => {constsearchItem=searchInfo.item.description;// Perform operation using "searchItem"// ...searchUserJourney.setSuccess();returnSearchUserJourney.AppState.SEARCH_RESULTS;},
Sample Utterances that could trigger the search journey
The following are some examples of commands that could trigger this journey
"Bangalore to Chennai"
"Book a ticket to Mumbai"
"Trains from Delhi "
SearchInfo Parameter
The SearchInfo parameter contains the breakdown of the original search request. It's structure is as described below:
Class SearchInfo {publicTravelModegetTravelMode(); //Bus/Train/FlightpublicStationgetSource(); //Details of the travel starting point publicStationgetDestination(); //Details of the travel destination point publicDategetOnwardDate(); //Details of the journey datepublicTimeRangegetOnwardDepartureTimeRange();publicTimeRangegetOnwardArrivalTimeRange();publicTripTypegetTripType();publicDategetReturnDate();publicTimeRangegetReturnDepartureTimeRange();publicTimeRangegetReturnArrivalTimeRange();publicList<FilterInfo>getFilters();publicSortInfogetSortInfo();publicPriceInfogetPriceInfo();publicPassengersInfogetPassengersInfo();} Class Station {publicStringgetId(); //App providedpublicStringgetCode(); //Station code if any.publicStringgetTerminal(); //Stop name if any.publicStringgetCity(); //City namepublicStringgetProvince(); //State namepublicStringgetCountry(); //Country name}Enum TravelMode { UNKNOWN, BUS, TRAIN,FLIGHT}Class TimeRange {publicDategetStartTime();publicDategetEndTime();}Class PriceInfo {publicintgetMinPrice();publicintgetMaxPrice();publicCurrencygetCurrency();}Class FilterInfo {publicStringgetFilterValue();publicStringgetFilterName();}Class SortInfo {publicSortTypegetSortType();publicSortOrdergetSortOrder();}Enum Currency { INR,USD}Enum SortType { PRICE, DEPARTURE_TIME, ARRIVAL_TIME, DURATION, RATING, SEATS_AVAILABLE,}Enum SortOrder { ASCENDING,DESCENDING}Class PassengersInfo {publicintgetCount();publicPassengerTypegetPassengerType();}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>)
Supported AppStates
The following AppStates 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.
Supported Conditions
The following conditions are supported for each of the AppStates supported by the Assistant
App State
Condition
Description
SEARCH_RESULTS
setSuccess()
setRouteNotFound()
setTicketNotAvailable()
setNeedSource()/
setNeedDestination()
setSourceInvalid()/
setDestinationInvalid()
setSourceAmbiguous()/
setDestinationAmbiguous()
setFailure()
The search was successful
The item being searched could not be found
The item being searched is out of stock
The item that needs to be searched has not been specified.
There was a failure while searching
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:
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.