Steps to integrate the retail assistant into your app
Slang’s Android retail assistant (aka SlangRetailAssistant) is a fully trained voice assistant specialized for Android apps in the Retail domain. By integrating with this assistant, apps can help their users perform the following user journey through voice:
Search for the grocery retail items
The following guide describes the steps that apps need to take in order to integrate with the assistant.
Integration Details
Step 1: Update Gradle dependencies (mandatory)
Update the app’s build.gradle files to include the following repository
Step 2: Register actions to be performed (mandatory)
Firstly, you will need to register action methods that will be called by the assistant on behalf of the end-users to service their requirements as shown below.
MainActivity.javaSlangRetailAssistant.setAction(new SlangRetailAssistant.Action() { @OverridepublicSearchResultonSearch(SearchInfo searchInfo,AssistantSession session) {// @param SearchInfo - Contains the search details. Refer 'SearchInfo' section below for details.// @param AssistantSession - Assistant session object that corresponds to current conversation. // @return SearchResult - Status of the onSearch action. Refer the below section for the details.
} publicvoidonAssistantError(AssistantError error) { // @param AssistantError - Contains the details of the error. }});
onSearch action handler is called once the assistant collects the details of the search from the user. It passes SearchInfo and AssistantSession objects are parameter and the handler is expected to return SearchResult once taking necessary action.
SearchInfo: Contains the details about the search made by the user. RetailItem is the key member of this object that contains the details about the item being searched. RetailItem provides below APIs to get granular details of the item being searched.
RetailItem.java
public String getBrand() {
//Returns the brand name of the item if specified.
//Eg: Britannia, Head and shoulders, Tide, etc.
}
public String getProductType() {
//Returns the item name
//Eg: rice, shampoo, juice, etc.
}
public String[] getVariants() {
//returns the array of variants of the item.
//Eg: cool menthol, blue, organic, etc.
}
public Quantity getQuantity() {
//Returns if any quantity is mentioned in the query.
//Eg: 10 packs, 5 bottles, etc.
}
public Size getSize() {
//Returns the size details if mentioned in the query.
//Eg: 2 kg, 500 ml, etc.
}
public Price getPrice() {
//Returns the price details if mentioned in the query.
//Eg: 2 rupees (sachet), 10 ruppes (bar), etc.
}
public String getDescription() {
//Utility method that returns the item description that is ready to be used in the search.
//This is typically done by appending brand, variants and item name.
//If the needs of the app isn't fulfilled with this, you should be using the individual API (mentioned above) and generate your own search string.
}