Custom action set slot

Hi, a simple question here: is the only way to set a slot value in a custom action is at the return?

def run(self, dispatcher, tracker, domain): return [SlotSet(“make”, “honda”)]

Can I not set the slot value in the body of the run() method?

def run(self, dispatcher, tracker, domain):
   SlotSet("make", "honda")
   dispatcher.utter_message("OK") 
   return[]

or:

def run(self, dispatcher, tracker, domain):
   tracker._set_slot("make", "honda")
   dispatcher.utter_message("OK") 
   return[]

In both of these code examples, the value of the “make” slot in any later utterances is ‘None’

Thanks!

2 Likes

Hi @reedsch,

Thanks for your post! I take it you are using an action endpoint for this? Because the line tracker._set_slot("make", "honda") will set the tracker’s slot on the action endpoint side only. The “real” tracker on core’s side only gets updated by the events which are passed back from the action.run() call (see the processor code)

I like your curiosity though

To both of you (Tom and the OP) : would it work if you set the slot in the tracker in the action endpoint, and then type

dispatcher.utter_template(“utter_example_template”, tracker)

if the example template I put there has a slot in its string? (I am referring to when a string is something like “Hey there, {name}!” and there is a slot & entity called “name”)

Would the same work with utter_message instead of utter_template?

dispatcher.utter_message(“Hey there, {name}!”, tracker)

Although I would agree that the second version is not that useful since you can extract the slot from the current tracker, but… always good to know :slight_smile:

@reedsch, have you found any answer. i am slso facing same situation.

i also have the same issue

Hi @reedsch

doesn’t your first code chunk works? It should! See https://stackoverflow.com/a/57471253/1786393

Giorgio

If you want to interact with the slots you set on the Action server side, you actually need to return them back to the Rasa server. There are two ways to do this

def run(self, dispatcher, tracker, domain):
   dispatcher.utter_message("OK") 
   return[ {"make", "honda"} ]
def run(self, dispatcher, tracker, domain):
   dispatcher.utter_message("OK") 
   return[ SlotSet("make", "honda") ]
2 Likes

This may help you :