Smartest way to make conditonal logic


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

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

- story: faq
  - 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 and follow up events?

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

Am I missing something?

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?

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

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 with an initial slot value e.g. 0
  • create a custom action 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!

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?

In general it’s advisable to use retrieval intents 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

Hope this helps!

1 Like

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?

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

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

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?

Yes, that’s correct!

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

Great thanks! And thanks for the quick reply :grinning:

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?

Yes! I would use a slot for that

great thanks for all the help!

1 Like