From d6170f7b7d8152aed3c766a4e3e5952820164677 Mon Sep 17 00:00:00 2001 From: manujo-varghese <40620912+manujo-varghese@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:44:12 +1100 Subject: [PATCH] Google Chat expects a JSON payload with a text field. The message format (summary and buffer) remains the same as it was for Slack. --- handler.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/handler.py b/handler.py index 928e148..5a27083 100644 --- a/handler.py +++ b/handler.py @@ -58,7 +58,10 @@ def lambda_handler(event, context): teams_hook_url = os.environ.get('TEAMS_WEBHOOK_URL') if teams_hook_url: publish_teams(teams_hook_url, summary, buffer) - + + google_hook_url = os.environ.get('GOOGLE_WEBHOOK_URL') + if google_hook_url: + publish_google(google_hook_url, summary, buffer) def report_cost(group_by: str = "SERVICE", length: int = 5, cost_aggregation: str = "UnblendedCost", result: dict = None, yesterday: str = None, new_method=True): @@ -241,6 +244,16 @@ def publish_teams(hook_url, summary, buffer): if resp.status_code != 200: print("HTTP %s: %s" % (resp.status_code, resp.text)) +def publish_google(hook_url, summary, buffer): + + message = { + "text": summary + "\n\n```\n" + buffer + "\n```" + } + + resp = requests.post(hook_url, json=message) + + if resp.status_code != 200: + print("HTTP %s: %s" % (resp.status_code, resp.text)) if __name__ == "__main__": # for running locally to test