Using code to determine content of email
# 🤝help
w
Hi all, Really loving this botpress journey, would like to say a big thanks to the team in order for the content and community support thats provided So im working on a bot currently and to make the flows a bit more efficient i guess you could say I've overused variables (not a bad thing) So in summary, a variable is captured called interestedProduct which can vary from 20+ products. This flow eventually sends the user to an option where they can request a product brochure (pdf) Is it possible to use the value of workflow.interestedProduct to determine which file is sent to the user? if so, how can i learn how to do this TIA!
b
hey!
glad to hear you've been enjoying Botpress 🙂
this is absolutely possible - what you would do is use an expression flow logic card
then, the condition of the transition would be "if the variable interestedProduct is equal to [Product Value]"

https://cdn.discordapp.com/attachments/1140755534631415951/1140764213162283078/Screenshot_2023-08-14_at_5.49.23_PM.png

and your setup might look something like this

https://cdn.discordapp.com/attachments/1140755534631415951/1140764605451358378/Screenshot_2023-08-14_at_5.51.10_PM.png

w
Hi Robert, thats really helpful. Thanks for sharing! Thanks for the youtube content too!
r
Comment so i can follow this topic
m
Yes make sense!
But it is not really programming
\
as a talented developer, I can help you
b
it's a good question! but unfortunately you're right - at the moment, you'd be setting up transitions for each product based on that logic
so your bot checks if variable X is equal to product Y and then moves along
b
Is it possible to use the value of workflow.interestedProduct to determine which file is sent to the user? if so, how can i learn how to do this
On this, you can try out below example: Step 1: Create a workflow variable with type as
Object
. And add your default values. (in form of productname: pdf URL) Step 2: Create a workflow variable with type as
Array
Step 3: Add an Execute Card, and write
workflow.menu=Object.keys(workflow.orders)
This is to store all the product names in the array variable. Step 4: Add a Single Choice Capture Card, store result in a string variable, in choices, click on
{x}
for super input and add
@workflow.menu
Step 5: Add a File Card, again click on
{x}
and write
{{workflow.orders[workflow.interestedProduct]}}
This expression will find the pdf of the selected choice and use it as a file In Title, add
@workflow.interestedProduct
to display the selected Product Name as title of the file.

https://cdn.discordapp.com/attachments/1140755534631415951/1141893185757528105/image.png

https://cdn.discordapp.com/attachments/1140755534631415951/1141893186072088596/image.png

https://cdn.discordapp.com/attachments/1140755534631415951/1141893186369892362/image.png

https://cdn.discordapp.com/attachments/1140755534631415951/1141893186667692042/Screenshot_2023-08-18_at_6.03.40_AM.png

https://cdn.discordapp.com/attachments/1140755534631415951/1141893186885783652/Screenshot_2023-08-18_at_6.05.38_AM.png

@wide-london-14130
w
Hi @bright-magazine-792 will give this a try, thanks for taking the time to put that together. Will update if i have any luck!
2 Views