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 a2e80da commit 8a994ac
Showing 1 changed file with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
.getAzurePetStoreSessionInfo(text);
if (azurePetStoreSessionInfo != null) {
text = azurePetStoreSessionInfo.getNewText();
this.sessionCache.put(turnContext.getActivity().getRecipient().getId(), azurePetStoreSessionInfo);
//turnContext.getActivity().getId() is unique per browser over the broken recipient for some reason
this.sessionCache.put(turnContext.getActivity().getId(), azurePetStoreSessionInfo);
}
else{
azurePetStoreSessionInfo = this.sessionCache.get(turnContext.getActivity().getRecipient().getId());
azurePetStoreSessionInfo = this.sessionCache.get(turnContext.getActivity().getId());
}

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

//DEBUG ONLY
if (text.contains("session"))
{
return turnContext.sendActivity(
MessageFactory.text("id:"+turnContext.getActivity().getRecipient().getId())).thenApply(sendResult -> null);
MessageFactory.text("id:"+turnContext.getActivity().getId())).thenApply(sendResult -> null);
//return turnContext.sendActivity(
// MessageFactory.text("sender: "+turnContext.getActivity().getFrom())).thenApply(sendResult -> null);
//Set<String> keys = turnContext.getActivity().getRecipient().getProperties().keySet();
Expand All @@ -116,17 +117,6 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
// MessageFactory.text("recipient id:"+turnContext.getActivity().getRecipient().getId()+ " recipient keys: "+keystring)).thenApply(sendResult -> null);
}

if (text.contains("session1"))
{
Set<String> keys = turnContext.getActivity().getRecipient().getProperties().keySet();
String keystring = "";
for(String key: keys){
keystring += key+" ";
}
return turnContext.sendActivity(
MessageFactory.text("recipient id:"+turnContext.getActivity().getRecipient().getId()+ " recipient keys: "+keystring)).thenApply(sendResult -> null);
}

if (text.contains("card")) {
if(azurePetStoreSessionInfo != null && azurePetStoreSessionInfo.getNewText() != null)
{
Expand Down Expand Up @@ -234,19 +224,12 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
MessageFactory.text(dpResponse.getDpResponseText())).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)
@Override
protected CompletableFuture<Void> onMembersAdded(
List<ChannelAccount> membersAdded,
TurnContext turnContext) {

String message = "";
String id = turnContext.getActivity().getRecipient().getId();

if(this.sessionCache.get(id) == null)
{
this.sessionCache.put(id, null);
message = this.WELCOME_MESSAGE + " " + id;
}
// return membersAdded.stream()
// .filter(
// member -> !StringUtils
Expand All @@ -258,7 +241,7 @@ protected CompletableFuture<Void> onMembersAdded(


return turnContext.sendActivity(
MessageFactory.text(message)).thenApply(sendResult -> null);
MessageFactory.text("")).thenApply(sendResult -> null);
}

}

0 comments on commit 8a994ac

Please sign in to comment.