How would you make a bot that can recommend produc...
# 🤝help
s
What would be the best path to take to get the bot to recommend a product that fits criteria of the user. I have a table of product and their name, price, brand, direct url, image url. The user would input the type of produc they're looking for and the budget. The bot would based on those two randomly choose a product and recommend it to the user, also providing the direct url. What's the best path to take here?
b
Hi, if you already have all the products registered in a table with those fields you should only do query depending on the input, remember that there are specific queries in your case just get the query as type of products and a price range, and with that you can place a filter to find a list of products that meet those conditions. Obtaining this result that is a list, you can pass it through a script that chooses two or three randomly.
It's interesting what you want to do, let me make an example and see how we can do it, I'll be back haha.
f
If you have development experience, the best thing would be to check this API: https://shopify.dev/docs/api/ajax/reference/product-recommendations
Otherwise, we can go into it together 🙂
b
Ok @stocky-rocket-41735 I don't know if you are a programmer I will do it with everything possible from Studio in Botpress in the easiest way ok?, if you are a programmer tell me because we can make the thing more interesting haha
First I created a sample table, there are some null fields but it doesn't matter for the moment.
this is the nodes
I will test what it does:
Ok there are a lot of things to do anyway, but this way it works just using AI to abstract the code and that's why botpress is amazing. First we have a Single Choice with all the types of paints we sell. Then we ask for the available budget. With these two values I pass them to the FindRecords card and put this prompt :
Copy code
`search a list whose type field is equal to {{workflow.type}} AND the price field is less than or equal to {{workflow.price}}
. This will generate a list of all products that meet this condition. Then I will use an AI Task to pass it a new prompt where the instructions will be to randomly choose a single record from all the options and in this case the one with the closest price, this is the promtp:
Copy code
`From this list: {{workflow.recommendationList}} choose the record with the price value closest to {{workflow.price}}.`
.
then with the obtained record I prepare a card to show a link, image and product information.
for that are the fields that I have null in the table there must be stored the url of images and product page for you to use them dynamically, for question of time in this example I only place dynamically in the card the price and name of the product, but you must do it with the image and url for the product page ok?
There are still a lot of things to do, especially in terms of validation, but that node there does a good job using AI alone, even I was surprised. I usually code my queries and apply direct array methods with Execute Cards, but this is another level, take advantage of botpress, it really puts it on a "platter, well served".
😉
Look at this image I made a test of the core of the query by removing the end card so you can see. First I chose Semi Gloss as an option and the budget was 19$, if you look at the table according to what I told you about the prompts it should only bring me as a recommendation the option that costs 18$ of the semi gloss not the 20$ one.
and that's what comes back here (I put it raw on a text card for you to see), just that record which I will then look to paint all on a card.
As you will see you have to validate situation like what happens if nothing is returned, as a general rule in an e commerce you should always bring something if it doesn't meet the expectations then bring the closest option above then.
If you don't have anything above, then bring anything, or a group of products in a carousel, etc.
s
@billowy-morning-42410 Thank you so much for taking the time to write all this out, you've helped me a lot 🙏 💪 . I am however having trouble with the action card... how can i put the image and url as variable?
also with the AI task what should the AI Task Input be?
I'm just having trouble with the card i think.. I tried this, but then in the emulator i get "Cannot display this message" @billowy-morning-42410
b
for the example I saved both links in the table for that product,
so following with the same example above, see that it returns an object, I put it in a text card so that before using it you can see its structure.
Here I am using the object in the Card
result
{{workflow.recommendProduct}} is the resulting object, the recommendation. I don't know if you know anything about javascript, it is a very used data type, It is used to store various keyed collections and more complex entities. In this case the key is the names of the column that you placed in your table and the values is the information of that specific record.
So to use any of these values you should refer to it as follows: From the variable containing the object {{workflow.recommendProduct}} I need the name, so you get it by putting {{workflow.recommendProduct.name}}, "name" because it is the name you put in the table ok, you do the same to get price, url, image, type, etc. The image is a URL of an image uploaded in the cloud somewhere ok? it is not the typical image uploaded from the computer as you do it traditionally there on the card, it is a url of an image. And the url is the link to the product page in detail. Note that the price I am using is the price of the recommended product not the budget as you have there in the picture, the budget I just used it to get the best possible recommendation.
This is just one way to start 💪🏻
f
WOW... I don't think I am needed here any more 😄
s
Hmm, @billowy-morning-42410 first of all, thank you so so much for taking the time to help me. I'm sure you've provided me with all the info needed but i'm just kind of lost. Here's my entire workflow screenshotted step-by-step and the first picture is of my table and how it's structured. If you could possibly tell me the exact mistake i am making i'd be very grateful.
that is it
b
Ok first I ask you, the three inputs are capturing their values without problem? and second is it returning values from the table? let's start by knowing if the inputs are being used and the table is returning something.
s
they are getting captured
b
That's an example table? can you afford to export a CSV so I can use it as an example here and replicate everything, only if you can, if you have data you need to hide it doesn't matter we keep going as we come.
s
here you go
b
ok I will create the table here and let you know
s
of coruse, take your time 🙂
any updates?
I'm headed to the gym now Borris, so if you don't see me replying immediately thats why. Thanks again for helping
b
Don't worry, I'm working on it
Ok, first some considerations in the table: It is recommended that when dealing with prices you convert them to cents or remove the float with some approximation if applicable, in this case I create a field called Cost where I have the prices in a format of only integers, this is because I want it to be as similar as possible to the user's input, which will be a simple number. This is just a recommendation:
I know that this is the format as it will be entered by a user
Here I return the CVS with the added cost column so you don't have to do it from scratch
the node looks like this:
The configuration of each input card 👆🏻
Now comes the magic, this time I used an Execute Code:
Which uses a method to search the database for products that meet these three conditions: Equal to the type ($eq), Equal to the gender ($eq) and less than the budget ($lt, actually here it should be $lte). You can find this in this part of the documentation: https://botpress.com/docs/cloud/studio/tables/
Then in the last line of that code I am saying that if you get something in the list, order it by price from highest to lowest and give me the one in the first position. If you get nothing just return null
Here the configuration of the last card 👆🏻
Now I show you an example of the chat working
First import the CVS that i passed to you with the new Cost column and remember to call the table ProductsTable so you can follow my example
There are many validations to take into account, but first I would like to know if all this works for you
s
i get an error message
b
You are having an error in the Execute card, tell me what were you looking for? to do the search here, 8000 budget, male gender, what type of product did you put?
s
how do you mean that? Like what product fits those in the table?
oh i put Watch
f
@billowy-morning-42410 you should make a tutorial out of this!!
b
If it still works fine for me with that example, let's check your log, what does it tell you? Click on Logs and scroll until you see the error colored in red
Of course @famous-jewelry-85388 !
let's review the variables I am using and their types:
Check if they are the same, especially the one with object type (recomProduct).
s
I did not have recomProduct set as "object" however, even after that i get an error. here's a log screenshot
is there a way you can send the code (from the execute code) so that i can copy and paste it? I had to manually enter it and maybe made a mistake
b
Hello @stocky-rocket-41735 , send me a screenshot of the Execute card code, it looks like you have a syntax error there.
Copy code
const typeProduct = workflow.typeProduct
const gender = workflow.gender
const budget = workflow.budget

const filteredList = await ProductsTable.findRecords({
    filter: {"$and": [{ "Gender": { "$eq": gender }},
                      { "Type": { "$eq": typeProduct }},
                      { "Cost": { "$lt": budget }}
                    ]
            }
    
    }).then(list => list)


workflow.recomProduct = filteredList.length > 0 ? filteredList.sort((a,b) => b.Cost - a.Cost)[0] : null
`
Look carefully for the " : " signs to check if they are correct.
s
this? @billowy-morning-42410
ok update: after pasting your code i don't get an error anymore. However, the card isn't considering the variables
big update: I realised i had the wrong title and subtitle in the card details. We're almost there!. For image i put {{workflow.recomProduct.Image}} however the card isn't displaying the image...
b
Nice, yes it looks like you are having problems with some links I was checking. When you copy and paste them into the browser to check there are simply no pictures, check those links that lead to an image.
for example this one:
but you have many there that do not lead to any image
The link for the Rolex you have in the example does not work.
s
@billowy-morning-42410 Yep, i guess everything is working then. I'd jsut have to get updated links to images. Can you tell me, would it be possible to also choose a size but only if the customer would be shopping for sneakers? Would we have to change the execute code a lot?
b
just add one more option to the filter, but in the case of size, looking at your database you should standardize it, for example all values are in "mm", there are many there that have no values, so all that should apply to all products, remember that it is a raw input that the user places and must somehow match recommendably with what you have in that column, in terms of variable type.
Copy code
const filteredList = await ProductsTable.findRecords({
    filter: {"$and": [{ "Gender": { "$eq": gender }},
                      { "Type": { "$eq": typeProduct }},
                      { "Cost": { "$lt": budget }},
                      { "Size": { "$eq": size }}
                    ]
            }
    
    }).then(list => list)
s
i standardized it, only having the sizes for shoes in US size. All other types now dont have a size value anymore
Ok, so i wanted in order to choose the size you'd have to pick sneakers, otherwise you'd continue the process as we did before, so i did this: from the Sneakers option i made a transition to the copy of the Criteria node without the type product. Everything else is the same apart from the execute code (I added the size - hoepfully correctly)
however i'm getting an error
this is how the sizes look in the table
b
you must correct the comma at the end
s
Ok, no error! but it's not giving the actual product details
here are all cards and their info
Gender
Size
Budget
Execute code
Final card
@billowy-morning-42410 I fixed everything and have everything working! I want to thank you so so much for helping how could i possibly repay you?
b
Hey @stocky-rocket-41735 great, thanks we are always here to help you in Botpress, no need to pay me 😄 , just a Thank You is enough for me 🙌🏻
s
Do you drink coffee? Do you have a Starbucks nearby?
f
@crooked-van-25152 great efforts from @billowy-morning-42410 here! got to tag you Sabrina 🙂
c
Agreed wow !!!! What a long thread.
Thanks a lot @billowy-morning-42410 🚀 That's why you're part of the Botbassadors 😉
s
@billowy-morning-42410 please let me at least buy you a starbuck giftcard for a cup of coffee. You've helped me so much
b
Does it's possible with a corousel to have many options?
c
Is this what you're referring to when you say: options? @best-army-74344
8 Views