Deploying a Bot Python Script to Cloud Functions

Hello, this is my first time trying to use a cloud service to host my own project and I'm having some trouble with handling the deploying and having my code work properly. 

Context: I build a simple messaging Bot (T*l*gram) that uses AI to handle incoming messages. I had the bot working on my development machine where I was able to interact with it in the T*l*gram client. I decided to move it to the Cloud to handle the 24/7 hosting that I want for this application. I've pinpointed Cloud Functions as the service I'd like to use from Google Cloud. I walked through the Quickstart to get an idea of how it works, thankfully it's not too complicated. I'm encountering a problem with the final deployment that comes after a successful build. 

Source Code:

@bot.message_handler(func=lambda m: True)
def echo_all(message😞
print("Sending to mistral ......")
mistral_response = client.chat(
model="mistral-small-latest",
messages=[ChatMessage(role="user", content=str(message.text))]
)
bot.reply_to(message, mistral_response.choices[0].message.content)

bot.infinity_polling()

Now, I need to define an entry point for Cloud Functions and uncovered that I would need to add that to my code with the use of the flask and functions_framework libraries like so,

@functions_framework.http
def hello(request: flask.Request) -> flask.typing.ResponseReturnValue:

return "Hello, world!"

So as you can my bot is originally polling in order to wait for requests and forward those to the single handler. I think this is where my deployment is getting stuck because the build succeeds but past that the deployment fails as it seems to be hanging for a prolonged period of time. I tried local testing the deployment like so,

functions-framework --target hello --source ./main.py --debug

and from here I see that the text that would pop up in the console to confirm that the server has started as one would see when starting up a flask server -- doesn't show up because the bot is already polling.

I've tried hacking something where I stick the polling function inside the entry point route but that doesn't work. Any help is greatly appreciated, and if this seems like a noob question, you're probably right.

0 0 31