Search…
Asynchronous Action Handling
This section applies only to Android, ReactNative, and Flutter platforms
While handling a user journey, the app might not be able to identify the state or the condition of the journey in a synchronous way. For example, the app could open a new activity (or page) which could then fire up a search to the back-end and show the results. So the callback itself would not be aware of the result unless it blocks till the entire activity is loaded. This is not desirable and leads to poor UX.
To solve this problem, the Slang Assistant programming model provides ways for the app to asynchronously signal the Assistant about the app state changes and conditions.
This can be done by using the "wait" and "notify" semantics. The process is quite straightforward. In order to deal with asynchronous operations within the callback:
  • The app must return the AppState WAITING to inform the Assistant that it's not yet ready to identify the state or the condition of the app. The Assistant goes into a "waiting" state without blocking the UI or other threads and continues to wait for further notification from the app.
  • When the app has completed the asynchronous operation, it can then call notifyAppState to notify the Assistant to proceed further.

Returning WAITING AppState

The app should return WAITING from the user journey callback. This would keep the Assistant in a "processing" (which is what it would have been when it invoked the callback).
Android Native
React Native
Flutter
1
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
2
// Fire an async search request
3
// ...
4
return SearchUserJourney.AppState.WAITING;
5
}
Copied!
1
onSearch: async (searchInfo, searchUserJourney) => {
2
// Fire an async search request
3
// ...
4
5
return SlangRetailAssistant.SearchAppState.WAITING;
6
},
Copied!
1
SearchAppState onSearch(
2
SearchInfo searchInfo, SearchUserJourney searchUserJourney) {
3
// Fire an async search request
4
// ...
5
return SearchAppState.WAITING;
6
}
Copied!

Notifying the Assistant

Once the Assistant is asked to wait, it will continue to remain in the "processing" state until the app notifies it to stop waiting, or the user cancels the operation through the UI. For best results, the app should ensure that every path that returns WAITING has an accompanying call to notify the Assistant.
To notify the Assistant with the AppState, the app needs access to the UserJourney object that was passed to the callback. This can be accessed via a global helper method getLastSearchUserJourney and then call notifyAppState on that object.
Android Native
React Native
Flutter
1
SearchUserJourney userJourney = SlangRetailAssistant.getLastSearchUserJourney();
2
3
userJourney.setSearchSuccess();
4
userJourney.notifyAppState(SearchUserJourney.AppState.SEARCH_RESULTS);
Copied!
1
SearchUserJourney userJourney = SlangRetailAssistant.getLastSearchUserJourney();
2
3
userJourney.setSearchSuccess();
4
userJourney.notifyAppState(SearchUserJourney.AppState.SEARCH_RESULTS);
Copied!
1
SearchUserJourney userJourney = SlangRetailAssistant.getLastSearchUserJourney();
2
3
userJourney.setSuccess();
4
userJourney.notifyAppState(SearchAppState.SEARCH_RESULTS);
Copied!

Last modified 5mo ago