Order Management
Details about the Order Management user journey
The onOrderManagement callback
onOrderManagement callbackWhen the Assistant detects that the user is trying to view or cancel their orders, it invokes the callback associated with the order management user journey. The callback looks like this:
OrderManagementAppState onOrderManagement(OrderInfo orderInfo, OrderManagementUserJourney userJourney);onOrderManagement: async (orderInfo, orderMangementUserJourney)onManageOrder: async (orderInfo, orderMangementUserJourney)OrderManagementUserJourney.AppState onOrderManagement(OrderInfo orderInfo, OrderManagementUserJourney userJourney);When this callback is invoked, the app is expected to:
- Use the - OrderInfoparameter to check if the user is interested to view or cancel their past orders
- Open the corresponding order page using the index field in the - OrderInfoparameter
- Return the appropriate App State and pass the relevant condition to it 
For  example, for a given onOrderManagement callback invocation, if the user asked for viewing a specific order,  and if that order did not exist, the app return OrderViewAppState and pass the  condition ORDER_NOT_FOUND to it. 
public OrderManagementAppState onOrderManagement(OrderInfo orderInfo, OrderManagementUserJourney userJourney) {
   int orderIndex = orderInfo.getOrderIndex();
   
   if (!checkOrder(orderIndex)) { // Order does not exist
      return new OrderViewAppState(ORDER_NOT_FOUND, orderIndex);
   } else {
      return new OrderViewAppState(SUCCESS);   
   }
}onOrderManagement: async (orderInfo, orderMangementUserJourney) => {
  var orderIndex = orderInfo.orderIndex;
   
  if (!checkOrder(orderIndex)) { // Order does not exist
    userJourney.setViewOrderNotFound(orderIndex);
  } else {   
    userJourney.setViewSuccess();
  }
  return OrderManagementUserJourney.AppState.VIEW_ORDER;
},onManageOrder: async (orderInfo, orderMangementUserJourney) => {
  const orderIndex = orderInfo.orderIndex;
   
  if (!checkOrder(orderIndex)) { // Order does not exist
    userJourney.setOrderNotFound(orderIndex);
  } else {   
    userJourney.setViewSuccess();
  }
  return OrderManagementUserJourney.AppStates.VIEW_ORDER;
},public OrderManagementUserJourney.AppState onOrderManagement(OrderInfo orderInfo, OrderManagementUserJourney userJourney) {
   int orderIndex = orderInfo.getOrderIndex();
   
   if (!checkOrder(orderIndex)) { // Order does not exist
      userJourney.setViewOrderNotFound(orderIndex);
   } else {   
      userJourney.setViewSuccess();
   }
   return OrderManagementUserJourney.AppState.VIEW_ORDER;
}Sample Utterances that could trigger Order Management
The following are some examples of commands that could trigger this user journey
- "show my orders" 
- "where is my last order" 
- "cancel my first order" 
OrderInfo Parameter
OrderInfo ParameterThe parameterOrderInfo contains the breakdown of the original order request. It has the following structure:
Class OrderInfo {
	int getOrderIndex(); // The index of the order
	OrderAction getOrderAction();
	ConfirmationStatus getCancelConfirmationStatus();
	enum OrderAction {
		VIEW,
		CANCEL
	},
	
	enum ConfirmationStatus {
	  UNKNOWN,    // When the user requested for cancelation, initially the confirmation status would be UNKNOWN
	  CONFIRMED,  // When the user has explicitly confirmed the cancellation, 
	  DENIED      // When the user has explicitly denied the cancellation 
	}
}{
  "action": <string value>,             // One of "VIEW, CANCEL"
  "confirmationStatus": <string value>, // One of "UNKNOWN, CONFIRMED, DENIED"
  "index": <int>                        // one of -1, 0,...
}{
  "action": <string value>,             // One of "VIEW, CANCEL"
  "confirmationStatus": <string value>, // One of "UNKNOWN, CONFIRMED, DENIED"
  "index": <int>                        // one of -1, 0,...
}So when the user speaks "show my last order",
- Index=- -1
- OrderAction=- VIEW
When the user speaks "cancel my order"
- Index=- 0
- OrderAction=- CANCEL
- ConfirmationStatus=- UNKNOWN
Supported AppStates
AppStatesThe following AppStates are supported:
- ORDER_VIEW ( - OrderViewAppState): To be returned when the app handles the order request and transitions to the orders page.
- ORDER_CANCEL ( - OrderCancelAppState): To be returned when the app handles the cancel request and navigates to the cancel orders page
- UNSUPPORTED ( - UnsupportedAppState): To be returned when the app is not ready to handle orders yet. The Assistant will speak out an appropriate prompt to the user.
Supported Conditions
ConditionsThe following Conditions are supported for each of the AppStates supported by the Assistant
App State
Condition
ORDER_VIEW (OrderViewAppState)
- SUCCESS - The order could be shown successfully 
- ORDER_HISTORY_EMPTY - There are no orders to show 
- ORDER_NOT_FOUND (index) - The specified order was not found 
- FAILURE - There was a failure while showing orders 
ORDER_CANCEL (OrderCancelAppState)
- SUCCESS - The order has been canceled successfully 
- ORDER_CANCEL_CONFIRMATION_REQUIRED - The app wants the user to confirm the cancellation request 
- ORDER_CANCEL_USER_CONFIRMED - The user has confirmed the cancellation and the app was able to cancel the order 
- ORDER_CANCEL_USER_DENIED - The user has denied the cancellation and the app is not going to cancel the order 
- ORDER_NOT_FOUND (index) - The specified order was not found 
- FAILURE - The order could not be canceled 
Handling cancellations effectively
When the user is trying to cancel an order, the ideal workflow is that the app would want the user to confirm before actually canceling the order. Typically this would be done in a multi-modal fashion, i.e. the app would inform the Assistant to ask for confirmation via voice, while the app also shows a dialog box for the user to visually confirm the same.
Alternately, the app could choose to not show any confirmation and just directly cancel the order (if the order could be found)
Handling cancel confirmations
When the user initially requests for a cancellation, the Assistant sets the ConfirmationStatus (inside the OrderInfo parameter) to UNKNOWN. The app could then do the following:
- If - ConfirmationStatus==- UNKNOWN, return OrderCancelAppState(- ORDER_CANCEL_CONFIRMATION_REQUIRED)- The Assistant will then ask the user to confirm the cancellation of the order and the same user journey callback will be invoked again (with the - ConfirmationStatusset to- CONFIRMEDor- DENIED)
 
- If the - ConfirmationStatus==- CONFIRMED, the app should attempt to cancel the order and if that was:- Successful: return OrderCancelAppState - (ORDER_CANCEL_USER_CONFIRMED)
- Failure: return OrderCancelAppState( - FAILURE)
 
- If the - ConfirmationStatus==- DENIED, return OrderCancelAppState- (ORDER_CANCEL_USER_DENIED)
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.
Last updated
Was this helpful?
