There are two ways. First you can use Google pub/sub and handle incomming notifications in your AppScrit endpoint. The second is to use the googleapis npm package inside your AppScript code an example here. Hope it helps.
These are the steps:
- made a project on https://console.cloud.google.com/cloudpubsub/topicList?project=testmabs thing?
- made a pubsub topic
- made a subscription to the webhook url
- added that url to the sites i own, i guess? I think I had to do DNS things to confirm i own it, and the error was super vague to figure out that was what i had to do, when trying to add the subscription
- added permission to the topic for "gmail-api-push@system.gserviceaccount.com" as publisher (I also added ....apps.googleusercontent.com and youtrackapiuser.caps@gmail.com but i dont think I needed them)
- created oauth client info and downloaded it in the credentials section of the google console. (oauthtrash.json)