Skip to content

Instantly share code, notes, and snippets.

@fvztdk
Created May 13, 2022 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvztdk/a22483bf7d2e9d4c5dea086a54d91bd8 to your computer and use it in GitHub Desktop.
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)
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