How to wait for the user input without using slots (Synchronous and Asynchronous actions)

Hi i am building a bot in rasa and my issue is that :

I have an intent location and an action behind this intent the action is to build a button and send it via the dispatcher the story goes as follows:

- story: localisation
  steps:
  - intent: localisation
  - action: action_loc_searching

in the actions file i have the following instructions :

       #build the button paload in jsonaa andsend it via the dispatcher to the channel
        dispatcher.utter_message(json_message=jsonaa)
        # await asyncio.sleep(5) 
        message = tracker.latest_message['text']
        print(message)

the button is used to retrieve the user’s location. Once he clicks on it, the location is sent to the bot. Now the problem is that I can retrieve the location sent to the bot beacause the bot continues on the other instructions before the user has pressed the button. So when i print the message i have the last text entered by the user (the on that triggered the action). The actions after the uter_message are executed before the bot receives the location.

It would be great if someone can help !

@M_R_LY interesting use-case can you please share some example in support of the process you have developed like bot/user conversation scenario ?

yeah sure! here is a screenshot

like you see the user : hi the bot : greet the user : ask for location the bot: ask to share and send a button (the button is not visible here)

So like i said Basically the problem is that the execution of the form ends before the location is sent to the bot. if you see the image the other log messages appear. So I would like to wait for the response (the location) before continuing the execution of the form

@nik202

Finally i tried to use the same patterns as @koaning in this video Conversational AI with Rasa: Custom Forms - YouTube

i used an action to ask for the slot and i am able to wait for the user input but the form validation and the action that i have defined in the storie are not runned.

Here is the rule:

- rule: Activate form
  steps:
  - intent: localisation
  - action: loc_form
  - active_loop: loc_form

- rule: submit open loc form
  condition:
  - active_loop: loc_form
  steps:
  - action: loc_form
  - active_loop: null
  - action: action_loc_searching  

the storie :

- story: get location hapy path form
  steps:
  - intent: localisation
  - action: loc_form
  - active_loop: loc_form
  - active_loop: null
  - action: action_loc_searching

the domain : slot definition and form

slots:
  location:
    type: any
    mappings:
      - type: from_text
        intent: localisation
        not_intent: [chitchat,greet,goodbye,affirm,deny,mood_great,mood_unhappy,bot_challenge]
        conditions: 
          - active_loop: loc_form
            requested_slot: location


forms:
  loc_form:
    ignored_intents: [chitchat,greet,goodbye,affirm,deny,mood_great,mood_unhappy,bot_challenge]
    required_slots:
    - location

@koaning can you help please

I’m wondering, why do you need to generate a button? Doesn’t the intent trigger localisation suffice what the user is interested in?

Hello thanks for your reply The button is related to the telegram channel so we don’t have to send our location manually . I saw in the documentation in the custom responses for telegram connector that we have a location button but I don’t know how to use it. Here Telegram

Just so I understand, you’re able to generate a button that automatically collects the information?

If so, why not have two intents and two actions. Something like:

user: give_location_intent
bot: generate_button_action
user: button_click_intent
bot: action_do_something_with_info

the problem is that it will be in a form and i need to keep the value of the location in order to do some calculs so far i have a slot called location like defined here

a form, a slot validation action. i thinkk that oonce the button is clicked it trigger another intent maybe beacause of the format

@koaning i need to specify too, its not an intent here the button generate is not for triggering an intent

Is there a reason why it must be a form? You could also set slots with Custom Actions.

Yes because I am asking for other information after that Yes I have also used (still using) an action to set the slot

class AskForLocationAction(Action):
    def name(self) -> Text:
        return "action_ask_location"

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

        reply_Markup = {"keyboard":[ [{ "text":"Appuyez pour envoyer votre localisation", "request_location":True }] ] , "one_time_keyboard":True }
        jsonaa = {
                "chat_id":"xxxxx",
                "text":"Pouvez vous partagez avec nous votre localisation svp ?",
                "reply_markup": json.dumps(reply_Markup)
                }        
        dispatcher.utter_message(json_message=jsonaa)
        return []

once the button is sent to the user, now he can click on it and its send the location of the user. the bot is waiting for the user’s responses but when he get it, he predict another intent instead of doing the validation. the text that is sent to the user for the location is in this format :

{"lng":-12.345678, "lat":91.23456}

that’s it @koaning

For more details here is the scenario @koaning

user : hi

bot : hey ! how are you

user : localisation

bot : # run the form , ask for the location using this action

the button is sent to the user and he clicks on it like here

And this is where it gets complicated

  • validation is not done
  • the bot predicts another intention

Despite the fact that I have defined the entitie location and I believe that I have correctly defined the slot in the domain

entities:
   - location     

slots:
  location:
    type: any
    mappings:
      - type: from_entity
        entity: location
        intent: [localisation, inform]
        not_intent: [chitchat,greet,goodbye,affirm,deny,mood_great,mood_unhappy,bot_challenge]
        conditions: 
          - active_loop: loc_form
            requested_slot: location

- intent: inform
  examples: |
    - here is my loc [{"lng":-10.123804, "lat":18.45626}](location)
    - [{"lng":-11.658804, "lat":14.45226}](location)

the configuration file is also well defined looking at the tracker, I can’t see anything in the entities so they are not extracted and its weird for me

How is the form triggered? Could you share relevant parts of your stories.yml/rules.yml?

Hello @koaning i have posted it before here is a reminder i seems good to me and i dont know why its not working

@koaning

hello @koaning just a gentle reminder :sob: