How to Create a Entity with List Item values from JSON

Hello,

I am getting few values from an API called within a service node. I want to see the options in a entity node based on the data that I get from the API.
How do I achieve this?

I tried to add a Entity with type List Enumerated and within the settings, used the option “List from Context” where I provided the value as context.ServiceNodeName.response.body as this variable gets the response back.

But when I run the bot, I am not able to get any choices back. I have also enabled “Yes, use channel specific standard formatting for default messages and show available list of values to end user.” but I do not get any values for selection to the user.

Can someone help me resolve this please?

@naitik_gada
Did you see the documentation on LOV enumerated entity types?

As long as you have a variable like the below in the context, you can use it in the Entity LoV to populate the values dynamically

context.myLOVEntityValues = [
    {
       "title" : "Option 1",
       "value" : "opt1",
       "synonyms" : ["option 1", "first one"]
    },
    {
       "title" : "Option 2",
       "value" : "opt2",
       "synonyms" : ["option 2", "second one"]
    }
]

Additional configuration

Doesn’t seem like this feature is working for me. Below is my configurations with sample context and resulting output (no enumerated list)

@eng
This is not working as you specified the same set of synonyms for every entry in the list.
Any display name or value you choose will stand ambiguous.
A synonym has to be carefully chosen so that there is no ambiguity with other options when you select the input.
cc: @andy.heydon For your expert guidance if needed.

For this situation it is assumed that the context variable to use, context.session.BotContext.SearchStockResponse is an array of objects where the display name, value and synonyms keys are properties of each object in that array.

Therefore from that definition, the platform would be looking for an array in context.session.BotContext

"SearchStockResponse" : [
     {
          "Code" : "..." ,
          "context.session.BotContext.SearchStockResponse" : [...]
     }
]

So you need to reorganize your JSON so that there is a specific, and single, synonyms property in each of the list’s objects and use that property name in the List of Items configuration. The synonyms value can be an array of strings where each string is a synonym or phrase. So I’m guessing something like:

"SearchStockResponse" : [
     {
          "Code" : "AAPL" ,
          "synonyms" : ["AAPL", "Apple Inc"]
     }
]

BTW, synonyms do not have to be unique if you cater for ambiguity or define the entity as multi-item. Never expect users to be perfect in their language, they might be saying something to remind them and then will “refine/remember” from there. :wink:

How did you setup the things? could you please share the details. :slightly_smiling_face: