diff --git a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java index 6c63a47c..e16adc31 100644 --- a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java +++ b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java @@ -74,29 +74,35 @@ public PetStoreAssistantBot(UserState withUserState) { // onTurn processing isn't working with DP, not being used to manage state... @Override public CompletableFuture onTurn(TurnContext turnContext) { - String text = turnContext.getActivity().getText().toLowerCase().trim(); - - LOGGER.info("onTurn incoming text: " + turnContext.getActivity().getText()); + try + { + String text = turnContext.getActivity().getText().toLowerCase().trim(); + LOGGER.info("onTurn incoming text: " + turnContext.getActivity().getText()); - if (isErroneousRequest(text)) { - return null; - } + if (isErroneousRequest(text)) { + return null; + } - AzurePetStoreSessionInfo azurePetStoreSessionInfo = configureSession(turnContext, text); + AzurePetStoreSessionInfo azurePetStoreSessionInfo = configureSession(turnContext, text); - if (azurePetStoreSessionInfo != null && azurePetStoreSessionInfo.getNewText() != null) { - // get the text without the session id and csrf token - text = azurePetStoreSessionInfo.getNewText(); - } + if (azurePetStoreSessionInfo != null && azurePetStoreSessionInfo.getNewText() != null) { + // get the text without the session id and csrf token + text = azurePetStoreSessionInfo.getNewText(); + } - // the client browser initialized - if (text.equals("...")) { - return turnContext.sendActivity( - MessageFactory.text(WELCOME_MESSAGE)).thenApply(sendResult -> null); + // the client browser initialized + if (text.equals("...")) { + return turnContext.sendActivity( + MessageFactory.text(WELCOME_MESSAGE)).thenApply(sendResult -> null); + } } - + catch (Exception e) + { + LOGGER.info("onTurn incoming activity does not exist"); + } + return super.onTurn(turnContext) - .thenCompose(saveResult -> userState.saveChanges(turnContext)); + .thenCompose(saveResult -> userState.saveChanges(turnContext)); } @Override @@ -231,7 +237,32 @@ protected CompletableFuture onMembersAdded( // .collect(CompletableFutures.toFutureList()).thenApply(resourceResponses -> // null); - LOGGER.info("onMembersAdded..."); + try + { + String text = turnContext.getActivity().getText().toLowerCase().trim(); + LOGGER.info("onMembersAdded incoming text: " + turnContext.getActivity().getText()); + + if (isErroneousRequest(text)) { + return null; + } + + AzurePetStoreSessionInfo azurePetStoreSessionInfo = configureSession(turnContext, text); + + if (azurePetStoreSessionInfo != null && azurePetStoreSessionInfo.getNewText() != null) { + // get the text without the session id and csrf token + text = azurePetStoreSessionInfo.getNewText(); + } + + // the client browser initialized + if (text.equals("...")) { + return turnContext.sendActivity( + MessageFactory.text(WELCOME_MESSAGE)).thenApply(sendResult -> null); + } + } + catch (Exception e) + { + LOGGER.info("onMembersAdded incoming activity does not exist"); + } return turnContext.sendActivity( MessageFactory.text("")).thenApply(sendResult -> null);