jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.67k stars 310 forks source link

Feature Request: Support Multi-Valued Slots directly in Jovo #1411

Open palle-k opened 1 year ago

palle-k commented 1 year ago

Amazon Lex V2, Alexa and potentially some other NLU systems support multi-valued slots, which are - as the name suggests - slots that can have a list of values.

Instead of having to go into the native interpretation, it should be possible to access lists of entities directly.

Example: Given the phrase "Turn on {Lights}" with the slot Lights being multi valued, the utterance "Turn on the Desk Lamp, the Ceiling Lights and the Outdoor Lights" would match Lights as being ["Desk Lamp", "Ceiling Lights", "Outdoor Lights"]

Current Behavior

The only way to get the list of matched entities is to use jovo.$entities[entityName].native. When multiple values are matched through Lex, the Entity contains a natural language concatenation of the options (like Desk Lamp, Ceiling Lights and Outdoor Lights)

Expected Behavior

It should be possible to get the list of matched entities without accessing the native interpretation.

Proposed Solution

Ideally, the type EntityMap would allow for lists of entities

export interface EntityMap<ENTITY_TYPE extends Entity = Entity> {
    [key: string]: ENTITY_TYPE | ENTITY_TYPE[] | undefined;
}

However, this would be a breaking change.

A non-breaking, alternative way to achieve this could be the following:

export interface SingleEntity {
    id?: string;
    resolved?: string;
    value?: any;
    native?: any;
}

export interface Entity extends SingleEntity {
    multipleValues?: SingleEntity[]
}
jankoenig commented 1 year ago

Thank you @palle-k, this is a great idea!

I really like your non-breaking solution with multipleValues