Skip to content

Commit

Permalink
Google Chat expects a JSON payload with a text field. The message for…
Browse files Browse the repository at this point in the history
…mat (summary and buffer) remains the same as it was for Slack.
  • Loading branch information
manujo-varghese committed Jan 19, 2024
1 parent 65946b8 commit d6170f7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6170f7

Please sign in to comment.