Use user input while custom action is running

Hello everybody!

I’m new to rasa and currently using version 3.1. I’m trying to figure out a way around this situation.

I’m building a bot that provides users with first aid and safety instructions. The instructions are stored in a JSON file as a list in an object.

Here’s the thing, for each instruction the bot gives I’d like it to check if the user is following or understands. If the user does, the bot proceeds to the next one and if the user doesn’t, it repeats the statement.

I do not know how to implement this.

class FirstAidAction(Action):

    def name(self) -> Text:
        return "action_first_aid"

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

        # Get the user's intent
        intent = tracker.latest_message['intent'].get('name')

        # Load the JSON data
        data_file = 'C:/Users/joysr/anaconda3/envs/ada/Ada_bot/actions/aida_data.json'
        with open(data_file, 'r') as f:
            data = json.load(f)

        # Check if the user's intent matches one of the injuries in the JSON data
        if intent.lower() in data['injuries']:
            injury = data['injuries'][intent.lower()]
            name = injury['name']
            description = injury['description']
            treatment = injury['treatment']

            # Construct the bot's response
            response = f"{name}: {description}\n\nTreatment:\n\n"
            for step in treatment:
                dispatcher.utter_message(step)
                dispatcher.utter_message(response="utter_follow_check")
                dispatcher.utter_message(buttons=[
                    {"title": "yes", "payload": "/affirm"},
                    {"title": "no", "payload": "/deny"},
                ], )
                
            # dispatcher.utter_message(response)
        else:
            dispatcher.utter_message("I'm sorry, I didn't understand. Can you please rephrase?")

        return []

This is my code but it just displays a button after every instruction without waiting for user input.