https://discord.gg/botpress logo
#🤝help
How to select specific variable to reply to the user with
# 🤝help
s

square-beach-57324

07/21/2023, 8:25 AM
Hey guys, would be super grateful if someone could help me out here. I am asking the bot to dtermine which service the client should be referred to, but with this current method, it does select the appopioate variable but then types back all the variables not used as it is part of a text card. I kinda need to deploy this asap so any help would be really appreciated! I am sure there is a simple fix, I am just still learning!

https://cdn.discordapp.com/attachments/1131864480607916104/1131864480805040189/screencapture-studio-botpress-cloud-c9249635-c2cc-4456-931b-517f9fb6f101-flows-wf-main-2023-07-21-09_10_28.png

a

acceptable-kangaroo-64719

07/21/2023, 12:27 PM
Hey @square-beach-57324, you could use a short bit of code to drop the empty variables and keep the ones that have a value in them.
Copy code
js
const variables = [workflow.forPhisio, workflow.forCounselling,... ]; //Put all your vars here

// Use lodash to filter non-blank variables and append them to a new variable
const finalMsg = _.reduce(variables, (acc, val) => {
  if (_.trim(val) !== '') {
    acc += val + ' ';
  }
  return acc;
}, '');

workflow.finalMsg = finalMsg.trim();
Then instead of putting all your vars in the text card, you can just put
@finalMsg
instead
s

square-beach-57324

07/25/2023, 6:52 AM
Hey man, only seeing this now as I have spent a few days with family. Thank you v much!