use of com.amazonaws.mobileconnectors.lex.interactionkit.continuations.LexServiceContinuation in project aws-sdk-android by aws-amplify.
the class InteractionClient method processResponse.
/**
* Analyzes response from Amazon Lex service. Returns a {@link Runnable}
* with the next step, which is usually a callback method in the
* {@link InteractionListener} object.
*
* @param handler {@link Handler}, to interact with app components in the
* main thread.
* @param result {@link PostContentResult}, response from the Amazon Lex
* service.
* @param client {@link InteractionClient}, reference to this object.
* @param responseMode {@link ResponseType}, current response type.
*/
private void processResponse(final Handler handler, final PostContentResult result, final InteractionClient client, final ResponseType responseMode, final ResponseType requestMode) {
Runnable response;
try {
setBusyState(NOT_BUSY);
final Response serviceResponse = new Response(result);
if (DialogState.Failed.toString().equals(result.getDialogState())) {
// Amazon Lex service reported an error.
response = new Runnable() {
@Override
public void run() {
interactionListener.onInteractionError(serviceResponse, new DialogFailedException("Failed to fulfill current request."));
}
};
} else if (DialogState.ReadyForFulfillment.toString().equals(result.getDialogState())) {
// The current dialog is ready for fulfillment by the client, no
// further action is required.
response = new Runnable() {
@Override
public void run() {
interactionListener.onReadyForFulfillment(new Response(result));
interactionListener.promptUserToRespond(serviceResponse, null);
}
};
} else if (DialogState.Fulfilled.toString().equals(result.getDialogState())) {
// Request was successfully fulfilled, no further action required.
response = new Runnable() {
@Override
public void run() {
interactionListener.promptUserToRespond(serviceResponse, null);
}
};
} else {
// User's response is required to continue.
final LexServiceContinuation continuation = new LexServiceContinuation(client, responseMode, requestMode);
// set the session attributes on the continuation
continuation.setSessionAttributes(serviceResponse.getSessionAttributes());
response = new Runnable() {
@Override
public void run() {
interactionListener.promptUserToRespond(serviceResponse, continuation);
}
};
}
} catch (final Exception e) {
response = new Runnable() {
@Override
public void run() {
interactionListener.onInteractionError(null, e);
}
};
} finally {
setBusyState(NOT_BUSY);
}
handler.post(response);
}
Aggregations