# Rasa responding to if-then-else question

**URL:** <https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340>\
**Category:** Rasa Open Source\
**Created:** [August 31, 2021, 3:47pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340 "2021-08-31T15:47:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![InnoOmnia](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/innoomnia/32/17290_2.png) [@InnoOmnia](https://forum.rasa.com/u/InnoOmnia)\
**Post date:** [August 31, 2021, 3:47pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/1 "2021-08-31T15:47:10Z")

</div>

My bot asks question and then user writes a numeric answer. Now bot needs to check if answer is correct or not. I have made custom action functions which check then and then reply if answer is correct or not. But it doesn’t work.

Here is my custom actions

```auto
from typing import Any, Text, Dict, List
from rasa_sdk.events import SlotSet
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict

class kysymyksienTarkistus1(Action):
    def name(self) -> Text:
        return "action_tarkista_kysymys_01"

    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        vastaus = tracker.latest_message["text"]
        # tarkistetaan onko vastaus oikein
        if vastaus == "puolikas":
            dispatcher.utter_message(response = "utter_kysymys01_oikein")
            #dispatcher.utter_message(text=f"vastaus oikein")
            return []
        else:
            dispatcher.utter_message(response = "utter_kysymys01_vaarin")
            #dispatcher.utter_message(text=f"vastaus väärin")
            return []

class kysymyksienTarkistus2(Action):
    def name(self) -> Text:
        return "action_tarkista_kysymys_02"

    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        vastaus = tracker.latest_message["text"]
        # tarkistetaan onko vastaus oikein
        if vastaus == "100":
            dispatcher.utter_message(response = "utter_kysymys02_oikein")
            return []
        else:
            dispatcher.utter_message(response = "utter_kysymys02_vaarin")
            return []

class kysymyksienTarkistus4(Action):
    def name(self) -> Text:
        return "action_tarkista_kysymys_04"

    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        vastaus = tracker.latest_message["text"]
        # tarkistetaan onko vastaus oikein
        if vastaus == "100":
            dispatcher.utter_message(response = "utter_kysymys01_oikein")
            return []
        else:
            dispatcher.utter_message(response = "utter_kysymys04_vaarin")
            return []

class kysymyksienTarkistus5(Action):
    def name(self) -> Text:
        return "action_tarkista_kysymys_04"

    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        vastaus = tracker.latest_message["text"]
        # tarkistetaan onko vastaus oikein
        if vastaus == "100":
            dispatcher.utter_message(response = "utter_kysymys01_oikein")
            return []
        else:
            dispatcher.utter_message(response = "utter_kysymys05_vaarin")
            return []

```

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [August 31, 2021, 3:52pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/2 "2021-08-31T15:52:39Z")

</div>

Hello,

Can you be more specific about what doesn’t work?

Everything looks correct except in the `name` method of class `kysymyksienTarkistus5` you are returning `"action_tarkista_kysymys_04"` instead of `"action_tarkista_kysymys_05"`.

---

<div class="post-metadata">

**Author:** ![InnoOmnia](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/innoomnia/32/17290_2.png) [@InnoOmnia](https://forum.rasa.com/u/InnoOmnia)\
**Post date:** [August 31, 2021, 5:00pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/3 "2021-08-31T17:00:23Z")

</div>

Hi, I corrected the typo but still not working. It just starts and stops. I’m using docker to start it, here is my command

> docker run -v $(pwd)/actions:/app/actions --net action-link --name action-server-prod rasa/rasa-sdk:2.2.0

Here is output

```auto
2021-08-31 16:54:59 INFO rasa_sdk.endpoint - Starting action endpoint server...-net action-link --name action-server-prod rasa/rasa-sdk:2.2.0
2021-08-31 16:54:59 ERROR rasa_sdk.executor - Failed to register package 'actions'.
Traceback (most recent call last):
  File "/app/rasa_sdk/executor.py", line 254, in register_package
    self._import_submodules(package)
  File "/app/rasa_sdk/executor.py", line 217, in _import_submodules
    self._import_module(full_name)
  File "/app/rasa_sdk/executor.py", line 231, in _import_module
    module = importlib.import_module(name)
  File "/usr/local/lib/python3.7/importlib/ __init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/actions/actions.py", line 5, in <module>
    from rasa_sdk.types import DomainDict
  File "/app/rasa_sdk/types.py", line 3, in <module>
    from typing_extensions import TypedDict
ModuleNotFoundError: No module named 'typing_extensions'

```

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [August 31, 2021, 5:03pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/4 "2021-08-31T17:03:38Z")

</div>

> [@InnoOmnia](#):
>
> `No module named 'typing_extensions'`

That’s the error 🙂

You Custom Actions are not wrong.

Try `pip install typing-extensions==3.10.0.0` (inside your virtual environment of course).

---

<div class="post-metadata">

**Author:** ![InnoOmnia](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/innoomnia/32/17290_2.png) [@InnoOmnia](https://forum.rasa.com/u/InnoOmnia)\
**Post date:** [August 31, 2021, 5:13pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/5 "2021-08-31T17:13:20Z")

</div>

> [@ChrisRahme](#):
>
> pip install typing-extensions==3.10.0.

I did it

```auto
pip3 install typing-extensions==3.10.0.
Collecting typing-extensions==3.10.0.
  Using cached https://files.pythonhosted.org/packages/2e/35/6c4fff5ab443b57116cb1aad46421fb719bed2825664e8fe77d66d99bcbc/typing_extensions-3.10.0.0-py3-none-any.whl
Installing collected packages: typing-extensions
Successfully installed typing-extensions-3.10.0.0

```

but still same error

> ModuleNotFoundError: No module named ‘typing\_extensions’

is it because docker environment?

---

<div class="post-metadata">

**Author:** ![InnoOmnia](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/innoomnia/32/17290_2.png) [@InnoOmnia](https://forum.rasa.com/u/InnoOmnia)\
**Post date:** [August 31, 2021, 6:15pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/6 "2021-08-31T18:15:31Z")

</div>

Here is Docker file that I used to create action server

```auto
# Extend the official Rasa SDK image
FROM rasa/rasa-sdk:2.2.0
#COPY * /app/

# Use subdirectory as working directory
WORKDIR /app

# Copy any additional custom requirements, if necessary (uncomment next line)
# COPY actions/requirements-actions.txt ./

# Change back to root user to install dependencies
USER root

# Install extra requirements for actions code, if necessary (uncomment next line)
#RUN pip install -r .requirements-actions.txt
# RUN pip install typing_extensions

# Copy actions folder to working directory
COPY ./actions /app/actions
RUN python -m pip install --upgrade pip
RUN pip install --no-cache-dir typing_extensions

# By best practices, don't run the code with root user
USER 1003

```

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [September 1, 2021, 2:12pm UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/7 "2021-09-01T14:12:15Z")

</div>

> [@InnoOmnia](#):
>
> is it because docker environment?

Ah, you’re in Docker.

Yes, adding it in the Dockerfile should solve the problem then. But it would be safer if you mentioned the version as well:

```auto
RUN pip install --no-cache-dir typing-extensions==3.10.0

```

---

<div class="post-metadata">

**Author:** ![InnoOmnia](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/innoomnia/32/17290_2.png) [@InnoOmnia](https://forum.rasa.com/u/InnoOmnia)\
**Post date:** [September 2, 2021, 11:11am UTC](https://forum.rasa.com/t/rasa-responding-to-if-then-else-question/47340/9 "2021-09-02T11:11:01Z")

</div>

> [@ChrisRahme](#):
>
> `==3.10.0`

Hi,

Thanks I got it working in my testbed (virtualbox Ubuntun 18:04) but not in my production environment (Azure cloud Ubuntu 18:04). I noticed some difference in pip and python versions but finally this solved problem. I compared what docker images it created, in virtualbox

```auto
linttu@linttu-VirtualBox:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rasa-sdk 2.2.0 d759afb1e947 3 hours ago 165MB
rasa/rasa-sdk 2.2.0 f6dfbf329eb3 2 days ago 165MB
rasa/rasa 2.2.0-full a298c0d73278 8 months ago 1.91GB
rasa/rasa-sdk <none> a1c9443b5df6 8 months ago 151MB  

```

and in Azure

```auto
[paulii@vetbot-v4 /pilleribot TUOTANTO]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rasa-sdk 2.2.0 3c7b6ec49eff 40 minutes ago 165MB
rasa/rasa 2.6.0-full 80efe1ff431a 3 months ago 2.03GB
rasa/rasa 2.2.0-full a298c0d73278 8 months ago 1.91GB
rasa/rasa-sdk 2.2.0 a1c9443b5df6 8 months ago 151MB

```

I noticed that rasa/saras-sdk 2.2.0 is 8 months old and rasa-sdk 2.2.0 newer, so I tried this command

> docker run -d -v $(pwd)/actions:/app/actions --net action-link --name action-server-prod **rasa-sdk:2.2.0**

instead of **rasa/rasa-sdk:2.2.0** and it started to work!!  
I don´t know why it creates two versions, maybe someone who understands better can explain.

Thank you very much!!!

- Pauli
