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
Web
1
SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney userJourney);
Copied!
1
onSearch: async (searchInfo, searchUserJourney)
Copied!
1
onSearch: async (searchInfo, searchUserJourney)
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 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:
Android Native
React Native
Web
1
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
2
String sourceCity = searchInfo.getSrcCity().getName()
3
String destinationCity = searchInfo.getDestCity().getName()
4
Date travelDate = searchInfo.getItem().getDescription();
5
6
// Launch SearchResultsActivity using "searchItem"
7
// ...
8
9
userJourney.setSuccess();
10
return SearchUserJourney.AppState.SEARCH_RESULTS;
11
}
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
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 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:
Android Native
React Native
Web
1
Class SearchInfo {
2
public TravelMode getTravelMode(); //Bus/Train/Flight
3
public Station getSource(); //Details of the travel starting point
4
public Station getDestination(); //Details of the travel destination point
5
public Date getOnwardDate(); //Details of the journey date
6
public TimeRange getOnwardDepartureTimeRange();
7
public TimeRange getOnwardArrivalTimeRange();
8
public TripType getTripType();
9
public Date getReturnDate();
10
public TimeRange getReturnDepartureTimeRange();
11
public TimeRange getReturnArrivalTimeRange();
12
public List<FilterInfo> getFilters();
13
public SortInfo getSortInfo();
14
public PriceInfo getPriceInfo();
15
public PassengersInfo getPassengersInfo();
16
}
17
18
Class Station {
19
public String getId(); //App provided
20
public String getCode(); //Station code if any.
21
public String getTerminal(); //Stop name if any.
22
public String getCity(); //City name
23
public String getProvince(); //State name
24
public String getCountry(); //Country name
25
}
26
27
Enum TravelMode {
28
UNKNOWN,
29
BUS,
30
TRAIN,
31
FLIGHT
32
}
33
34
Class TimeRange {
35
public Date getStartTime();
36
public Date getEndTime();
37
}
38
39
Class PriceInfo {
40
public int getMinPrice();
41
public int getMaxPrice();
42
public Currency getCurrency();
43
}
44
45
Class FilterInfo {
46
public String getFilterValue();
47
public String getFilterName();
48
}
49
50
Class SortInfo {
51
public SortType getSortType();
52
public SortOrder getSortOrder();
53
}
54
55
Enum Currency {
56
INR,
57
USD
58
}
59
60
Enum SortType {
61
PRICE,
62
DEPARTURE_TIME,
63
ARRIVAL_TIME,
64
DURATION,
65
RATING,
66
SEATS_AVAILABLE,
67
}
68
69
Enum SortOrder {
70
ASCENDING,
71
DESCENDING
72
}
73
74
Class PassengersInfo {
75
public int getCount();
76
public PassengerType getPassengerType();
77
}
78
79
Enum PassengerType {
80
ADULT,
81
CHILD,
82
INFANT
83
}
Copied!
1
N/A
Copied!
1
N/A
Copied!
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:
Android Native
React Native
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
userJourney.setRouteNotFound();
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.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!

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.