# Using custom action to set slot value

**URL:** <https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192>\
**Category:** Rasa Open Source\
**Created:** [October 22, 2019, 4:16pm UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192 "2019-10-22T16:16:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaravo](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jaravo](https://forum.rasa.com/u/jaravo)\
**Post date:** [October 22, 2019, 4:16pm UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192/1 "2019-10-22T16:16:05Z")

</div>

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`:

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

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

```

`actions.py`:

```python
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`:

```markdown
## happy path
* greet
    - action_check_result

```

---

<div class="post-metadata">

**Author:** ![Gehova](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Gehova](https://forum.rasa.com/u/Gehova)\
**Post date:** [October 22, 2019, 5:17pm UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192/2 "2019-10-22T17:17:06Z")

</div>

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:

```auto
return [SlotSet("result", result)]

```

---

<div class="post-metadata">

**Author:** ![jaravo](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jaravo](https://forum.rasa.com/u/jaravo)\
**Post date:** [October 22, 2019, 5:42pm UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192/3 "2019-10-22T17:42:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gehova](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Gehova](https://forum.rasa.com/u/Gehova)\
**Post date:** [October 22, 2019, 6:08pm UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192/4 "2019-10-22T18:08:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jaravo](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jaravo](https://forum.rasa.com/u/jaravo)\
**Post date:** [October 22, 2019, 6:13pm UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192/5 "2019-10-22T18:13:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jaravo](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jaravo](https://forum.rasa.com/u/jaravo)\
**Post date:** [October 25, 2019, 7:01am UTC](https://forum.rasa.com/t/using-custom-action-to-set-slot-value/20192/6 "2019-10-25T07:01:12Z")

</div>

finally solved this after coming back to it.

The slot type for `result` should be `type: unfeaturized`

Looking back [at the documentation for slots](https://rasa.com/docs/rasa/core/slots/#what-are-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.
