Using custom action to set slot value

I’m having a few problems getting a custom action to work and add the result as a slot.

It looks like the action is being called, but SlotSet() doesn’t seem to update the required slot (the required string is returned from the api and . No error messages apparent. I’ve written other actions for filling in forms that have worked ok.

I want to update a slot called result with some string information that comes back from an api call. I’

The key aspects are as follows:

Grateful for any help with troubleshooting, as I’m out of ideas.

I’m using rasa==1.3.9 but have tried 1.4.0 too.

in domain.yml:

entities:
  result
slots:
  result:
    type:text
templates:
  utter_result:

- text: Result - {result}
  actions:
- action_check_result

actions.py:

from typing import Dict, Text, Any, List, Union, Optional
from rasa_sdk import Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction
from rasa_sdk import Action
from rasa_sdk.events import SlotSet

class ActionCheckResult(Action):
    def name(self) -> Text:
        return "action_check_result"

    def run(self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        curr_dict = tracker.slots
        curr_json = json.dumps(curr_dict)
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        r = requests.post(RES_URL, data=json, headers=headers)
        result = r.text
        #tried setting slot in code and returning it, neither works.
        #SlotSet("result", str(result))
        dispatcher.utter_template('utter_result', tracker)
        return [SlotSet("result", result)]

stories.md:

## happy path
* greet
    - action_check_result

In your stories.md file you have action_check_diagnosis, but in the rest of the code you have action_check_result. Also, the return of the run method should be a list:

return [SlotSet("result", result)]

Thanks, I’ve tried with the result as a list, but still not working.

When I debug the code the return [SlotSet("result", result)] line seems to just get skipped over?

the action_check_result was just a mistake in my example, have amended now - good spot.

That’s weird. Maybe you have an error obtaining the result. Try a placeholder value.

I’ve tried just setting result = "placeholder", but still get the same behavior.

In debugging, the api was definitely returning a string value too.

Are from rasa_sdk import Action from rasa_sdk.events import SlotSet the correct imports? I’ve found it difficult to find an up to date tutorial on custom actions

finally solved this after coming back to it.

The slot type for result should be type: unfeaturized

Looking back at the documentation for slots - type: text :

Results in the feature of the slot being set to 1 if any value is set. Otherwise the feature will be set to 0 (no value is set).

unfeaturized allows the actual text for result to be stored.