I'm trying to create a simple bot that whenever I get a message on Gmail, it write the content on a file, for now I only have a cron scheduler that get the messages within a interval of 2 minutes, but the best choice would be to get the message as I said, when I receive them in real time.
I didn't find much on the googleapis for gmail tho. For what I know I should create a websocket and then after that, how could I have the messages I just received
You can use Push Notification using the Cloud Pub/Sub API in order to create a webhook for your notifications.
You can follow this guide to do a proper set up.