Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chtrembl committed Jan 5, 2024
1 parent 9a39355 commit 383f7e1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
dpResponse.setDpResponseText(responseText);
}

if(dpResponse.isImageContentCard())
{
return PetStoreAssistantUtilities.getImageCard(turnContext, dpResponse);
}
return turnContext.sendActivity(
MessageFactory.text(dpResponse.getDpResponseText())).thenApply(sendResult -> null);
}
Expand Down Expand Up @@ -251,7 +255,7 @@ else if(azurePetStoreSessionInfo != null)
}

private CompletableFuture<Void> getDebug(TurnContext turnContext, String text, AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
if (text.contains("debug"))
if (text.equals("debug"))
{
if(azurePetStoreSessionInfo != null && azurePetStoreSessionInfo.getNewText() != null)
{
Expand All @@ -263,7 +267,7 @@ private CompletableFuture<Void> getDebug(TurnContext turnContext, String text, A
MessageFactory.text("azurePetStoreSessionInfo was null, cache size: "+cache.estimatedSize())).thenApply(sendResult -> null);
}
}
if (text.contains("card")) {
if (text.equals("button card")) {
if(azurePetStoreSessionInfo != null && azurePetStoreSessionInfo.getNewText() != null)
{
text = azurePetStoreSessionInfo.getNewText();
Expand All @@ -281,7 +285,7 @@ private CompletableFuture<Void> getDebug(TurnContext turnContext, String text, A
.thenApply(sendResult -> null);
}

if (text.contains("ball"))
if (text.equals("image card"))
{
String jsonString = "{\"type\":\"image\",\"id\":\"image-ball\",\"data\":{\"url\": \"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-toys/ball.jpg?raw=true\",\"alt\": \"This is a pretty ball\",\"caption\": \"ball blah blah blah\"}}";
Attachment attachment = new Attachment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class DPResponse {
private boolean updateCart = false;
private boolean completeCart = false;
private String aoaiResponse = null;

private boolean imageContentCard = false;

public DPResponse() {
super();
}
Expand Down Expand Up @@ -56,4 +57,10 @@ public String getAoaiResponse() {
public void setAoaiResponse(String aoaiResponse) {
this.aoaiResponse = aoaiResponse;
}
public boolean isImageContentCard() {
return imageContentCard;
}
public void setImageContentCard(boolean imageContentCard) {
this.imageContentCard = imageContentCard;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public DPResponse search(String text, Classification classification) {
DPResponse dpResponse = new DPResponse();
dpResponse.setClassification(classification);

String dpResponseText = "I found some information on our products. We have some a ";
String dpResponseText = "I found some information on our products. We have a ";

String filter = "";

Expand Down Expand Up @@ -263,7 +263,9 @@ public DPResponse search(String text, Classification classification) {
// this should become a content card with a carousel of product(s) for now just display description if there is 1 product and override the stuff above
if(products.size() == 1 || classification.equals(Classification.MORE_PRODUCT_INFORMATION))
{
dpResponseText = "I found some information on our products. Here is a description of the " + products.get(0).getName() + ". " + products.get(0).getDescription();
dpResponse.setImageContentCard(true);
dpResponseText = "Check out this product of ours, the " + products.get(0).getName();

dpResponse.setDpResponseText(dpResponseText);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.chtrembl.petstoreassistant.utility;

import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.chtrembl.petstoreassistant.model.AzurePetStoreSessionInfo;
import com.chtrembl.petstoreassistant.model.DPResponse;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.microsoft.bot.builder.MessageFactory;
import com.microsoft.bot.builder.TurnContext;
import com.microsoft.bot.schema.Attachment;

public class PetStoreAssistantUtilities {
private static final Logger LOGGER = LoggerFactory.getLogger(PetStoreAssistantUtilities.class);
Expand All @@ -33,4 +40,17 @@ public static AzurePetStoreSessionInfo getAzurePetStoreSessionInfo(String text)

return azurePetStoreSessionInfo;
}

public static CompletableFuture<Void> getImageCard(TurnContext turnContext, DPResponse dpResponse) {
String jsonString = "{\"type\":\"image\",\"id\":\"image-product\",\"data\":{\"url\": \""+dpResponse.getProducts().get(0).getPhotoURL()+"\",\"alt\": \""+dpResponse.getProducts().get(0).getDescription()+"\",\"caption\": \""+dpResponse.getProducts().get(0).getDescription()+"\"}}";
Attachment attachment = new Attachment();
attachment.setContentType("application/json");

attachment.setContent(new Gson().fromJson(jsonString, JsonObject.class));
attachment.setName("public-image-product");

return turnContext.sendActivity(
MessageFactory.attachment(attachment, dpResponse.getDpResponseText() + " @showcards(image-product)"))
.thenApply(sendResult -> null);
}
}

0 comments on commit 383f7e1

Please sign in to comment.