0

My issue is as follows: I have a link on my home page and when I click it it should take me to another view and after that a function should be invoked automatically. The function communicates with the user interactively using their voice (it's a voice bot). You don't know how the conversation is going and when it'll end.

A line on my homepage:

<a href='/start-bot'>Start the Bot</a>

In the main app code:

@app.route('/start-bot')
def startBot():
  botResult = function_that_starts_the_bot()
  return render_template('display-bot-result.html') # a template just to display the summary of the conversation

I would like the app to behave like this:

def startBot():
  redirect_to_intermediate_view()  # navigate to an intermediate view where I can inform the user that she can speak now to the bot
  
  # automatically run the code below so the bot is invoked without any extra user's action (no buttons etc.)
  botResult = function_that_starts_the_bot()
  return render_template('display-bot-result.html') # a template just to display the summary of the conversation

I tried to run the bot function asynchronously (I followed this python-asyncio TypeError: object dict can't be used in 'await' expression) but couldn't run the app at all (I don't know exactly where to put the code and the app throws 'Working outside of request context' error.)

Jakub Małecki
  • 341
  • 2
  • 11
  • It's not fully a solution for my problem, but it helped me a lot https://stackoverflow.com/questions/50400733/in-flask-can-i-show-one-template-while-a-function-runs-and-redirect-to-another – Jakub Małecki Jan 11 '22 at 14:50

0 Answers0