How to avoid http_timeout error using async method while connecting to Slack

My Custom action code is connecting to the database & fetching results. As this process takes more than 3 seconds, I get an 'http_time out" error while integrating with slack. In order to avoid this, I am trying an async method like below: Even this also not resolving an issue. Please advise am I missing anything here.

class ActionXDays(Action):

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

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

    intent = tracker.latest_message['intent'].get('name')
    metric = ""
    res = ""
    for e in tracker.latest_message['entities']:
        if e['entity'] == 'metric':
            metric = e['value']

    dispatcher.utter_message("Identified Intent and currently fetching your information...")

    if metric == ‘cny’:
        dispatcher.utter_message("Connecting to data warehouse...")
        data = pd.read_sql_query(sql_cons, conn)
        res = f"{metric} values  is {data[‘re’s][0]}”
        conn.close()

    dispatcher.utter_message(text=res)

    return []

Hi @ranjithjms

I think your problem here is that calling dispatcher.utter_message will not asynchronously send the message to the user, the dispatcher just collects messages that will be sent when the action completes. So you are still getting a timeout because the full run method takes more than 3 seconds.

The solution would be to asynchronously start doing the database query but actually return from the run method after doing utter_message. Then, when the query is complete you can trigger an external event which will send the results to the user.

Does that make sense?