event.payload.value
# 🤝help
c
Hello fellow Botmakers, I have a single capture card that has 3 options with detailed sentences. Instead of checking these long sentences wed like to check if the choice is either 1, 2 or 3. From my research it seems we need to access the "event.paypload.value". Is the code below the correct way of fetching our desired data ?
Copy code
// Inside the "userChoice" node logic
const userChoice = event.payload.value;
let result = "";

switch (userChoice) {
  case "1":
    result = "Liefde";
    break;
  case "2":
    result = "Lust";
    break;
  default:
    result = "Leven";
    break;
}

// Store the 'result' in a flow variable
workflow.result = result;

https://cdn.discordapp.com/attachments/1136266393847873598/1136266394003046532/brave_2023-08-02_13-56-30.jpg

c
The message sent by the user is contain inside the
event.preview
variable but I would recommend using the variable you set in your choice option instead
workflow.mychoice
. This is will be more precise, the
event.preview
variable could contain a random message that the user sent to your bot. 🙂
c
Hi Mike, thanks for thinking along. I am familiar with the method you described but were encountering an issue where if the list of choices is very big ( and contains allot of text ) it becomes increasingely more work for the coder to check for answers. Wouldn't it be much more helpful if choice 1 outputs the number 1 (or 0) and choice 2 outputs 2 etc. ? Let me give you an example:

https://cdn.discordapp.com/attachments/1136266393847873598/1136368364214829189/brave_2023-08-02_20-42-00.jpg

since we have allot of text in our input cards it can become quite messy in the code e.g. if chicken === ""Summon a dancing chicken" - Sentence: "Watch in awe as a chicken with killer dance moves busts a move right in front of you!"" (dance); ` Could become
if chicken === 1 (dance);
c
Oh! I get it. I will get back to you with a better solution. I see what I can do to allow you to define a text for your question and a value associated with it. You could also use the transition on every choice directly. I hope this helps.
c
oh that would be amazing ! @colossal-egg-20510
270 Views