How can we increase delay in Action Listening

Hi , I am facing issue at the time when i am fetching data using API inside Action.py file and want to use this as bot response to user (dispatcher.utter_message(f"{string_data}"))

But here there is delay in fetching data inside action.py file which is used as bot response.

Due to this delay, Bot is not responding.

Please support how to control this.

Rasa Version      :         2.8.2
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.3
Rasa X Version    :         None
Python Version    :         3.6.8
Operating System  :         Linux-3.10.0-1062.el7.x86_64-x86_64-with-centos-7.9.2009-Core

action_py_code

If you have a long running action, you’ll need to process this asynchronously and use an external event to respond to the user when the action completes. So, the action should respond immediately with a message like We'll get back to you when we've looked up the information. Then, send the external event when the action completes.

1 Like

@stephens , can you please explain with a piece of code how can we achieve this?

The reminderbot is a working example with code that is similar to your use case.

Hi @stephens i am proceeding my action asynchronously and also try to set 30 seconds but during API response inside my Action, its takes 30 sec for API response and during this i am getting below error . Here i am using python 3.6.Should i be using python 3.7+ version for asynchronous response?

Story.Yaml is below>>

Action.py>>> class ActionSetReminder(Action): “”“Schedules a reminder, supplied with the last message’s entities.”“”

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

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

    dispatcher.utter_message("I will remind you in 5 seconds.")
    date = datetime.datetime.now() + datetime.timedelta(seconds=30)
    ServiceReference= AuthAPI.PostData(SubSerReq,Discription_Slot, f"{SubSerName} related query ",CatK , SubCatK, email)
    

    reminder = ReminderScheduled(
        "EXTERNAL_reminder",
        trigger_date_time=date,
        name="my_reminder",
        kill_on_user_message=False,
    )

    return [reminder]

class ActionShowRef(Action):

def name(self) -> Text:

    return "action_show_reference"

async def run(

    self,

    dispatcher: CollectingDispatcher,

    tracker: Tracker,

    domain: Dict[Text, Any],

) -> List[Dict]:

    global SerRef

    dispatcher.utter_message(SerRef)

You cannot have an action that runs 30 seconds without responding. You need to respond immediately as I indicated above and spawn a separate process that handles the long running task.

@stephens thanks. I will check and work on your suggestion…