Skip to content

Commit

Permalink
Update PetStoreAssistantBot.java
Browse files Browse the repository at this point in the history
  • Loading branch information
chtrembl committed Jan 4, 2024
1 parent 8a994ac commit d3845a4
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext) {
@Override
protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
String text = turnContext.getActivity().getText().toLowerCase().trim();

String id = turnContext.getActivity().getId().trim();

LOGGER.info("onMessageActivity: text {} id {} ", text, id);

// strip out session id and csrf token if one was passed from soul machines
// sendTextMessage() function
Expand All @@ -84,10 +88,10 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
if (azurePetStoreSessionInfo != null) {
text = azurePetStoreSessionInfo.getNewText();
//turnContext.getActivity().getId() is unique per browser over the broken recipient for some reason
this.sessionCache.put(turnContext.getActivity().getId(), azurePetStoreSessionInfo);
this.sessionCache.put(id, azurePetStoreSessionInfo);
}
else{
azurePetStoreSessionInfo = this.sessionCache.get(turnContext.getActivity().getId());
azurePetStoreSessionInfo = this.sessionCache.get(id);
}

if(text.isEmpty())
Expand All @@ -98,14 +102,14 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
if(text.equals("..."))
{
return turnContext.sendActivity(
MessageFactory.text(WELCOME_MESSAGE+" "+turnContext.getActivity().getId())).thenApply(sendResult -> null);
MessageFactory.text(WELCOME_MESSAGE+" "+id)).thenApply(sendResult -> null);
}

//DEBUG ONLY
if (text.contains("session"))
{
return turnContext.sendActivity(
MessageFactory.text("id:"+turnContext.getActivity().getId())).thenApply(sendResult -> null);
MessageFactory.text("id:"+id)).thenApply(sendResult -> null);
//return turnContext.sendActivity(
// MessageFactory.text("sender: "+turnContext.getActivity().getFrom())).thenApply(sendResult -> null);
//Set<String> keys = turnContext.getActivity().getRecipient().getProperties().keySet();
Expand Down Expand Up @@ -221,7 +225,7 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
}

return turnContext.sendActivity(
MessageFactory.text(dpResponse.getDpResponseText())).thenApply(sendResult -> null);
MessageFactory.text(dpResponse.getDpResponseText()+" "+id)).thenApply(sendResult -> null);
}

// this method obly gets invoked once, regardless of browser/user, state isnt working right for some reason (DP related, not in issue with emulator)
Expand Down

0 comments on commit d3845a4

Please sign in to comment.