How to set value of other slots in slot_mappings

I want to set value of ‘color’ with that of another slot ‘color_suggestion’, when user give affirm intent to earlier suggestion. how to do it?

sample dialog: User: pls suggest the color
## in custom action get a color suggestion. color_suggestion slot is set to Red. bot: Red looks great on you. user: please go ahead. ## on affirmation, I want to set Color slot from color_suggestion

I am trying to set in slot_mappings “color”: [ self.from_entity(entity=“COLR”,intent=“choose_color”), self.from_intent(intent=“affirm”,---- I want to get value of color_suggestion slot and set it to color---- ),]

to do this you’ll have to create your own slot extraction method, so instead of from_entity it’ll be from_affirmation_of_another_slot or something like that. That will look like the from_intent method except take the value from the other slot

Thanks for your reply. It helped me explore more on this issue.

If I had to implement my own slot extraction method, I had to override methods like extract_requested_slot to handle new mapping method type. Instead, I have done the following:

  1. On affirm intent, set slot value as “slot:color_suggestion” :

self.from_intent(intent=“affirm”,value=“slot:color_suggestion”)

  1. Handle this in validate method (validate_color), where I have access to the tracker to fetch the slot value:
 if value.startswith("slot:"):
        slot_name = value.split(':')[1]
        slot_val = tracker.get_slot(slot_name)
        return {"color": slot_val}

This worked perfectly fine for me.

1 Like

that’s a good workaround!

1 Like