How can I set a slot value in story itself

Hi there,

Is it possible to set a slot value directly in story. I mean can we inject extra data which is not available from NLU but required in the custom action.

I am trying something like:

apply_leave_vacation

  • ApplyLeave{“leaveParam”: “vacation”}
    • slot(“execute”: True)
    • action_apply_leave
    • slot{“leaveParam”: “vacation”}

apply_leave_illness

  • ApplyLeave{“leaveParam”: “illness”}
    • slot(“execute”: True)
    • action_apply_leave
    • slot{“leaveParam”: “Illness”}

can anybody help me to solve this?

@akelad @souvikg10

Regards

1 Like

Yes thats possible. Just return it with your customaction as a list

class CustomAction(Action):
	"""
	Perform ...
	"""
	def name(self):
		return 'action_name'

	def run(self, dispatcher, tracker, domain):
                # whatever
		return [ SlotSet('no', str(1210)), 
		         SlotSet('name', 'raghavendrav')
			   ]

Cheers, Henry

You can’t do it directly from the story, but you can create a custom action to set one or multiple slots at the same time. That custom action can be called from the story.

Thanks :slight_smile:

Thanks :slight_smile:

I dont think thats true

Just type - slot{“execute”: True} in the stories before you call your action and it will be set in stories itself.

Try debugging and you will see that the slot changes!

So if the user sends a message without an entity, you can set the default value for your slot

  • my_name_is
    • slot{“name”: “human”}
    • utter_hello

But its better to do it with a custom action so you can set your logic, like changing the conversation flow based on the slot. Eg in restaurant bot if there are no seats you can utter “Too many people” else perform action

#story_1
* book_for{"number": "20"}
  -slot{"number":20}
  - action_check_seats
  - slot{"available":"No"}
  - utter_sorry_no_seat

#story_2
* book_for{"number": "20"}
  -slot{"number":20}
  - action_check_seats
  - slot{"available":"Yes"}
  - action_book_seat