How to add delay time with custom action in action process rasa?

I’m implementing the RASA demo with my webhook API.

Problem Function run() in custom action process can not be active when having delay time within function occur, How to solve this problem?

def run():
      time.sleep(2)
      dispatcher.utter_message(text=message)
      return []

Thank you

I assume time sleep as my process in function run before dispatch will return a response.


time.sleep(2)
dispatcher.utter_message(text=message)

or I should move my delay process to the RASA core process part.

this is the last error message in the RASA custom action.

Exception occurred during execution of request <Request: POST /webhook>
sanic.exceptions.ServiceUnavailable: Cancelled

I solved my problem. I move my process to the RASA core part in the output part then can work well.