sgrdswl
sgrdswl

Reputation: 11

Trouble executing python flask-assistant code in cloud function

I'm trying to run flask-assistant code in cloud function. The code works fine in my local machine , but it is not working as a cloud function. I'm using the http trigger. The function crashes every time it is triggered.

from flask import Flask
from flask_assistant import Assistant, ask, tell

app = Flask(__name__)
assist = Assistant(app, route='/')


@assist.action('TotalSales')
def greet_and_start(request):
    app.run
    speech = "Hey! 1500?"
    return ask(speech)

if __name__ == '__main__':
    app.run(debug=True)

Upvotes: 0

Views: 168

Answers (1)

Kolban
Kolban

Reputation: 15276

When you write a Google Cloud Function in Python, all you need write is the function that handles the request. For example:

def hello_get(request)
  return 'Hello World!'

Cloud Functions handles all the work to create the Flask environment and handle the incoming request. All you need to do is provide the handler to handle the processing. This is the core behind Cloud Functions which provides "Serverless" infrastructure. The number and existence of actual running servers is removed from your world and you can concentrate only on what you want your logic to do. It is not surprising that your example program doesn't work as it is trying to do too much. Here is a link to a Google Cloud Functions tutorial for Python that illustrates a simple sample.

https://cloud.google.com/functions/docs/tutorials/http

Let me recommend that you study this and related documentation on Cloud Functions found here:

https://cloud.google.com/functions/docs/

Other good references include:

Upvotes: 1

Related Questions