Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chtrembl committed Jan 31, 2024
1 parent 691500a commit 053eef6
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,12 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
this.cosmosDB.storePrompt(this.cache.getIfPresent(azurePetStoreSessionInfo.getId()));
}

if (dpResponse.isImageContentCard()) {
return PetStoreAssistantUtilities.getImageCard(turnContext, dpResponse);
if (dpResponse.isContentCard()) {
if(dpResponse.getClassification().equals(Classification.MORE_PRODUCT_INFORMATION)
{
return PetStoreAssistantUtilities.getImageCard(turnContext, dpResponse);
}
return PetStoreAssistantUtilities.getProductCarouselContentCard(turnContext, dpResponse);
}

LOGGER.info("classification on text: " + text + " is: " + dpResponse.getClassification());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@ public class DPResponse {
private boolean updateCart = false;
private boolean completeCart = false;
private String aoaiResponse = null;
private boolean imageContentCard = false;
private boolean contentCard = false;

public DPResponse() {
super();
}

public Classification getClassification() {
return classification;
return this.classification;
}

public void setClassification(Classification classification) {
this.classification = classification;
}

public String getDpResponseText() {
return dpResponseText;
return this.dpResponseText;
}
public void setDpResponseText(String dpResponseText) {
this.dpResponseText = dpResponseText;
}

public List<Product> getProducts() {
return products;
return this.products;
}
public void setProducts(List<Product> products) {
this.products = products;
}

public boolean isUpdateCart() {
return updateCart;
return this.updateCart;
}
public void setUpdateCart(boolean updateCart) {
this.updateCart = updateCart;
}
public boolean isCompleteCart() {
return completeCart;
return this.completeCart;
}
public void setCompleteCart(boolean completeCart) {
this.completeCart = completeCart;
}
public String getAoaiResponse() {
return aoaiResponse;
return this.aoaiResponse;
}
public void setAoaiResponse(String aoaiResponse) {
this.aoaiResponse = aoaiResponse;
}
public boolean isImageContentCard() {
return imageContentCard;
public boolean isContentCard() {
return this.contentCard;
}
public void setImageContentCard(boolean imageContentCard) {
this.imageContentCard = imageContentCard;
public void setContentCard(boolean contentCard) {
this.contentCard = contentCard;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;

public class Product implements Serializable{
private String productId = null;

@JsonProperty("category.name")
private String category = null;

@SerializedName("title")
private String name = null;
private String description = null;

@SerializedName("imageUrl")
private String photoURL = null;

private String description = null;

private String imageAltText = "";

private String buttonText = "Add to cart";

private int searchScore = 0;

public Product() {
Expand Down Expand Up @@ -64,4 +74,16 @@ public int getSearchScore() {
public void setSearchScore(int searchScore) {
this.searchScore = searchScore;
}
public String getImageAltText() {
return imageAltText;
}
public void setImageAltText(String imageAltText) {
this.imageAltText = imageAltText;
}
public String getButtonText() {
return buttonText;
}
public void setButtonText(String buttonText) {
this.buttonText = buttonText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,27 @@ public DPResponse search(String text, Classification classification) {
switch (dpResponse.getClassification()) {
case SEARCH_FOR_DOG_FOOD:
category = "Dog Food";
dpResponse.setContentCard(true);
break;
case SEARCH_FOR_DOG_TOYS:
category = "Dog Toy";
dpResponse.setContentCard(true);
break;
case SEARCH_FOR_CAT_FOOD:
category = "Cat Food";
dpResponse.setContentCard(true);
break;
case SEARCH_FOR_CAT_TOYS:
category = "Cat Toy";
dpResponse.setContentCard(true);
break;
case SEARCH_FOR_FISH_FOOD:
category = "Fish Food";
dpResponse.setContentCard(true);
break;
case SEARCH_FOR_FISH_TOYS:
category = "Fish Toy";
dpResponse.setContentCard(true);
break;
}

Expand Down Expand Up @@ -262,12 +268,15 @@ 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))
if(products.size() == 1 && (classification.equals(Classification.MORE_PRODUCT_INFORMATION) || dpResponse.isContentCard()))
{
dpResponse.setImageContentCard(true);
dpResponseText = "Check out this product, the " + products.get(0).getName();

dpResponse.setDpResponseText(dpResponseText);
dpResponse.setContentCard(true);
dpResponse.setDpResponseText("Check out this product, the " + products.get(0).getName());
}
else if (products.size() > 0 && dpResponse.isContentCard())
{
dpResponseText = "Check out these products below";
dpResponse.setDpResponseText(dpResponseText);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,21 @@ public static CompletableFuture<Void> getImageCard(TurnContext turnContext, DPRe
MessageFactory.attachment(attachment, dpResponse.getDpResponseText() + " @showcards(image-product)"))
.thenApply(sendResult -> null);
}

public static CompletableFuture<Void> getProductCarouselContentCard(TurnContext turnContext, DPResponse dpResponse) {
String jsonString = "{\"type\":\"buttonCarousel\",\"id\":\"buttonCarousel\",\"data\":{\"buttonCards\":%s}}";
jsonString = String.format(jsonString, new Gson().toJson(dpResponse.getProducts()));

LOGGER.info("getProductCarouselContentCard() jsonString: " + jsonString);

Attachment attachment = new Attachment();
attachment.setContentType("application/json");

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

return turnContext.sendActivity(
MessageFactory.attachment(attachment, dpResponse.getDpResponseText() + " @showcards(buttonCarousel)"))
.thenApply(sendResult -> null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type":"buttonCarousel",
"id":"buttonCarousel",
"data":
{
"buttonCards": %s
}
}

0 comments on commit 053eef6

Please sign in to comment.