How to build and deploy a simple Facebook Messenger bot with Python and Flask
tsaprailis.com
tsaprailis.com
Here's super rough instructions in a gist, and you can find plenty of great guides on Google of course: https://gist.github.com/mcescalante/5db616b9a826605f1df35f79...
From the top paragraph of http://flask.pocoo.org/docs/0.11/deploying/:
"While lightweight and easy to use, Flask’s built-in server is not suitable for production as it doesn’t scale well and by default serves only one request at a time. Some of the options available for properly running Flask in production are documented here."
In short, the Flask server is not really written or tuned for production, so we use gunicorn or wsgi which are WSGI containers that are production ready :)
Edit: which if course wouldnlet you use any compatible chat app, including Vector.
Bots / webhook listeners do really fit for API Gateway + Lambda use cases.
I'm currently using Modulus and I think it will get pretty expensive if I keep making more bots, so a cheaper way to do it would be nice!
Edit: Found a tutorial: https://medium.com/@igorkhomenko/run-facebook-messenger-chat...
The excellent Serverless framework is pure JS, but you can also deploy jars to Lambda, which lets you use any JVM language. Clojure Lambdas have a more extreme profile: ~500ms for a cold start, <1ms once warm. You could keep it warm with a timer event source, which could do double duty as a watchdog / heartbeat thing.
Once I hit that, I hashed out a scheme where I serialize and queue outgoing requests (SQS), and then execute them from a lambda that is triggered by a 1 second timer. At this point, I was in a crunch for what was supposed to be a fairly simple task, and modern AWS is somewhat of an unfamiliar environment for me, so I just deployed it as a classic Node worker on Heroku.