# Smartest way to make conditonal logic

**URL:** <https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161>\
**Category:** Rasa Open Source\
**Created:** [May 3, 2021, 6:10pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161 "2021-05-03T18:10:53Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 3, 2021, 6:10pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/1 "2021-05-03T18:10:53Z")

</div>

Hello,

I’m making an assistance which can cover a FAQ. Here I would like to make a message saying something like “if there’s anything else you need dont be afraid to ask” after the bot has made the Utter action. The thing is it should only be the first intent.

But I cant seem to wrap my head around how i would create an action which can do this. Does anyone have an idea how to approach this problem?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 5, 2021, 8:12am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/2 "2021-05-05T08:12:26Z")

</div>

Hi @Blaabjerg96! I’m not sure if I understand your question correctly. do you want to do something like this?

```auto
- story: faq
  steps:
  - intent: ask_faq
  - action: utter_faq
  - action: utter_dont_be_afraid_to_ask

```

If this is not what you want, you might want to look into [custom actions](https://rasa.com/docs/rasa/custom-actions) and [follow up events](https://rasa.com/docs/action-server/events/#followup)?

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 5, 2021, 12:54pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/3 "2021-05-05T12:54:51Z")

</div>

I looked into events, but cant seem to find a event that refers to the first intent.

Am I missing something?

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 6, 2021, 7:25am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/4 "2021-05-06T07:25:32Z")

</div>

Hi! I think I don’t understand what you are trying to do - what do you mean by “it should only be the first intent” and refering to the first intent?

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 6, 2021, 3:29pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/5 "2021-05-06T15:29:07Z")

</div>

Thanks for the quick reply,

So the idea was that the user might ask more than one question. But the `Utter_dont_be_afraid_to_ask` should come only after the first time, the bot answers the users message.

I hope that cleared it up

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 7, 2021, 9:10am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/6 "2021-05-07T09:10:19Z")

</div>

I think now I understand what you’re trying to do, thanks for clearing it up!

I can imagine that you can

- create a [slot](https://rasa.com/docs/rasa/domain/#slots) with an initial slot value e.g. `0`
- create a [custom action](https://rasa.com/docs/action-server/sdk-actions) for the `utter_faq` that fetches the slot value by `tracker.get_slot(slot_name)` and dispatch the reply to the faq
- if the slot value is still `0` you can issue a `dispatcher.utter_message(text = "don't be afraid to ask")`
- update the slot by `return [SlotSet("slot1", "value")]` for other than `0`

That should work, but there are probably also other ways to do it. I hope I didn’t miss anything!

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 7, 2021, 4:34pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/7 "2021-05-07T16:34:12Z")

</div>

But if i have more than one intent which share the that action, i would run into a problem right? Have i build my FAQ bot incorrectly if i make an intent for each question type?

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 12, 2021, 8:42am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/8 "2021-05-12T08:42:56Z")

</div>

In general it’s advisable to use [retrieval intents](https://rasa.com/docs/rasa/chitchat-faqs/) to handle FAQs.

Maybe it helps to take a look at how we deal with FAQs and retrieval intents using custom actions in our [rasa demo](https://github.com/RasaHQ/rasa-demo/blob/main/actions/actions.py)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 12, 2021, 4:42pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/9 "2021-05-12T16:42:16Z")

</div>

I can see I have build my bot rather incorrectly haha. But thanks for the tip! I still run into a problem though right?

Cause i cannot say which faq/specific\_intent the user will ask. So how would I be able to check for that?

Or am i missing something?

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 14, 2021, 7:42am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/10 "2021-05-14T07:42:27Z")

</div>

Inside a custom action you can check for the full retrieval intent, which also tells you the specific intent / topic like this (lines copied from [rasa demo](https://github.com/RasaHQ/rasa-demo/blob/a4ee674d7e1c22c1e2ddae6fc94ba6c65e060018/actions/actions.py#L199-L207)):

```
    full_intent = (
        tracker.latest_message.get("response_selector", {})
        .get("faq", {})
        .get("full_retrieval_intent")
    )
    if full_intent:
        topic = full_intent.split("/")[1]
    else:
        topic = None
```

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 18, 2021, 5:46pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/11 "2021-05-18T17:46:36Z")

</div>

Sorry for the late reply.

So if I understand the example correctly: This will retrieve the intent name which is faq, and afterwards get the specific name.

If full\_intent has a value it will fill topic as faq/specific intent name

Is this correct? If so should I make some logic, checking if its the first intent the bot catches or am I missing something?

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 19, 2021, 9:22am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/12 "2021-05-19T09:22:25Z")

</div>

Yes, that’s correct!

To check if it is the first message of that kind you can then use the slot (as explained above)

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 19, 2021, 12:31pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/13 "2021-05-19T12:31:30Z")

</div>

Great thanks! And thanks for the quick reply 😀

If i would like to check if the intent was the first in general how would I do that? Is it also a slot which i can give a true / false value?

---

<div class="post-metadata">

**Author:** ![kalkbrennerei](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kalkbrennerei/32/11609_2.png) [@kalkbrennerei](https://forum.rasa.com/u/kalkbrennerei)\
**Post date:** [May 21, 2021, 8:16am UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/14 "2021-05-21T08:16:07Z")

</div>

Yes! I would use a slot for that

---

<div class="post-metadata">

**Author:** ![Blaabjerg96](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/blaabjerg96/32/14129_2.png) [@Blaabjerg96](https://forum.rasa.com/u/Blaabjerg96)\
**Post date:** [May 21, 2021, 12:24pm UTC](https://forum.rasa.com/t/smartest-way-to-make-conditonal-logic/43161/15 "2021-05-21T12:24:19Z")

</div>

great thanks for all the help!
