Created
May 13, 2022 10:41
-
-
Save fvztdk/a22483bf7d2e9d4c5dea086a54d91bd8 to your computer and use it in GitHub Desktop.
Read from GCP Pub/Sub and publish to Google Chat webhook (used to send alerts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from json import dumps | |
from httplib2 import Http | |
import base64 | |
def main(event, context): | |
url = os.environ['WEBHOOK_URL'] | |
bot_message = { | |
'text' : base64.b64decode(event['data']).decode('utf-8')} | |
message_headers = {'Content-Type': 'application/json; charset=UTF-8'} | |
http_obj = Http() | |
response = http_obj.request( | |
uri=url, | |
method='POST', | |
headers=message_headers, | |
body=dumps(bot_message), | |
) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment