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")


def run(self, dispatcher, tracker, domain):
   tracker._set_slot("make", "honda")

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



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 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.