Rasa blocked Async utter_massage

Hello everyone,

I am currently working on a quiz bot using Rasa and I’ve encountered an issue with implementing a timer. After the bot asks a question, I want a timer to start running, and every 20 seconds, the bot should send a message to notify the user about the time passed. However, since I’m expecting user input during this time, the utter_message function seems to be blocked.

I have tried using asynchronous programming and running the timer in the background, but the messages are not being sent to the user. The timer function itself is working fine, as it prints the messages to the console.

My story:

  • story: activate quiz steps:
    • intent: start_quiz
    • action: askQuestion
    • action: action_start_timer
    • intent: answer_input
    • action: check_Answer
    • action: action_stop_timer

my timer: class ActionStartTimer(Action): def name(self) → Text: return “action_start_timer”

async def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[EventType]:
    async def run_timer():
        while True:
            await asyncio.sleep(20)  
            dispatcher.utter_message("20 sec passed")

    asyncio.create_task(run_timer())

   
    dispatcher.utter_message("Timer started")

    return []

See here how to do it

1 Like