https://discord.gg/botpress logo
#🤝help
I need to implement Dynamic dropdown for my flow.
# 🤝help
r

ripe-pilot-83749

07/19/2023, 9:47 AM
In our bot, we have compliant registration, which contains the categories which are come from api call, Based on the categories selection getting the respective sub-categories both we need to show case in the dropdown format, so please tell me how to use dynamic dropdown in my bot.
a

acceptable-kangaroo-64719

07/19/2023, 11:27 AM
hey @ripe-pilot-83749 try building an array of your options like:
Copy code
js
workflow.ddOptions = [ 
 {
  label: 'Option 1',
  value: `https://en.wikipedia.org`
},{
  label: 'Option 2',
  value: 'https://google.com
]
Then you can pass that variable into the choice skill like this
r

rough-smartphone-28502

07/19/2023, 5:24 PM
I'm trying to achieve the same, can u explain post this how to divert the nodes?
r

ripe-pilot-83749

07/20/2023, 4:18 AM
thanks your response, can you please tell me where we integrate in my flow, please help me
a

acceptable-kangaroo-64719

07/20/2023, 10:30 AM
You would put that code in after you receive your API call response. Take a look at the recipe bot template for an example. First we call the API:
Copy code
js
const url = 'https://api.spoonacular.com/recipes/complexSearch'
const params = {
  query: workflow.baseQuery,
  diet: workflow.dietType,
  apiKey: env.apiKey,
  number: '3',
  ignorePantry: 'false',
  sort: 'popularity',
  sortDirection: 'asc',
  addRecipeInformation: 'true',
  addRecipeNutrition: 'false'
}

try {
  const response = await axios.get(url, { params })
  if (response.status === 200) {
    workflow.recipeInfo = response.data.results
  }
} catch (error) {
  console.error(error)
}
Then we take the results (stored in
workflow.recipeInfo
) and re-format them in a way that is acceptable for carousels. You would just skip all the bits about images/titles/subtitles and just focus on an array of buttons.
Copy code
js
workflow.recipes = []
const myCards = workflow.recipeInfo.map((recipe) => {
  workflow.recipes.push({
    title: recipe.title,
    vegetarian: recipe.vegetarian,
    vegan: recipe.vegan,
    glutenFree: recipe.glutenFree,
    dairyFree: recipe.dairyFree,
    veryHealthy: recipe.veryHealthy,
    cheap: recipe.cheap,
    veryPopular: recipe.veryPopular,
    readyInMinutes: recipe.readyInMinutes,
    servings: recipe.servings,
    summary: recipe.summary
  })
  // create the card object
  return {
    type: 'card',
    title: {
      dynamicValue: `${recipe.title}`,
      valueType: 'dynamic'
    },
    subtitle: {
      dynamicValue: '',
      valueType: 'dynamic'
    },
    imageUrl: {
      dynamicValue: `${recipe.image}`,
      valueType: 'dynamic'
    },
    actions: [
      {
        action: 'url',
        label: 'View Recipe',
        value: `${recipe.sourceUrl}`
      }
    ]
  }
})
workflow.cards = []
for (var card of myCards) {
  workflow.cards.push({
    //in order to render a card, we only need these three fields
    title: card.title,
    imageUrl: card.imageUrl,
    actions: card.actions[0]
  })
}
r

ripe-pilot-83749

07/20/2023, 12:53 PM
hi all, I am using on-premises bot, Is their any limitation for messages for both incoming and outgoing?
4 Views