Run form once at the Beginning

I am somehow confused or maybe I am over-thinking it too much. How can I run a form at the beginning of the conversation. For example, I have the activate form rule:

- rule: Activate form (when Greet)
  steps:
  - intent: greet
  - action: utter_greet
  - action: general_info_form
  - active_loop: general_info_form

I would like to only activate this form general_info_form for the first greet, and so I can save user information (name, phone, etc) which I only need to ask once. Once this form is filled I would like to answer in a different way to the user (i.e. utter_greet rather than activating the form again).

Should this go in a story? But I don’t know how to manage the case that this should only be triggered once. Thanks in advance :slight_smile:

You can change “utter_greet” for a custom action and write something like this:

from rasa_sdk.events import FollowupAction, ActiveLoop
.
.
.
class ActionGreet(Action):
    def name(self):
        return "action_greet"

    def run(self, dispatcher, tracker, domain):
        .
        .
        .
        dispatcher.utter_message(text = "Hello")
        if <I already have the general info>:
            return []
        else:
            return[FollowupAction("general_info_form"), ActiveLoop("general_info_form")]
2 Likes

Thanks for the answer :slight_smile: Two brief questions:

  1. Returning emptying list [] means to listen?
  2. Is there a function to determine all slots for a given form are filled for the first condition?
  1. In this case is like having 2 rules, one with the events and one without it. At the end your bot execute action_listen.

  2. I’m not sure. You can get the slots from the tracker and check if all are filled.

2 Likes

I am also working on something like this.

Problem at there is I can’t create a rule that executed at start of conservation and independent from user’s intent.

Let me try to explain scenario that I think in my head.

Conservation start → User types something (Not necessary) → Form activated and chatbot will explain “new user” situation to user and ask some personal information.

In @andrejankas, if user says anything but not greet, general info form will never activated (as I understand)

I am not sure how to handle this situation.

You can send the greet intent (or any other one of course) secretly from the user in your frontend application. This way, it will seem like the bot is the one that started the conversation.

1 Like

@ChrisRahme Thanks for helping. I saw these type of solutions at forum about that topic. I am trying to create a more “deterministic” chatbot for my company which is independent than frontend side but it seems like that it isn’t possible for now. :slightly_smiling_face:

This is possible with the help of ActionSessionStart. Even user says something unknown you know that session has been started so you can do anything when it starts even starting a form by returning FollowupAction(“form_name”)

1 Like

Thanks a lot. It works for now. I need to gain more experience about custom actions. :slightly_smiling_face:

1 Like

Yeah, try using in-built rasa functions too. Please add my response as solution so anyone can find it useful quickly

Hi!

I tried with this, but it’s not working :frowning: Would you please help me?

Hi, did you add this action name in domain.yml?

1 Like

I added it and now it works! Thank you so much!