Skip to content

Commit

Permalink
Add webhooks_ms_teams function to send notifications to Microsoft Tea…
Browse files Browse the repository at this point in the history
…ms channel
  • Loading branch information
saradindusengupta committed Feb 15, 2024
1 parent 102b1e6 commit 1886904
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/mlops_flair/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests
from os import path
import json
import yaml


def webhooks_ms_teams(config, webhookJsonFile):
url = config['webhooks']['ms_teams']
if path.exists(webhookJsonFile):
with open(webhookJsonFile) as webhookJson:
jsonPayload = json.load(webhookJson)
response = requests.post(
url, json=jsonPayload, headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
isNotified = 1
else:
print("ERROR: Unable to send webhook to Teams General Channel")
else:
print("ERROR: Webhook json payload file not found")

if (__name__ == "__main__"):
working_dir = "/home/saradindu/dev/mlops_pipeline_flair/"
with open(f"{working_dir}/config/config.yaml", 'r') as file:
config = yaml.safe_load(file)
webhookJsonFile = config['webhooks']['webhook_payload']
webhooks_ms_teams(config, webhookJsonFile)

0 comments on commit 1886904

Please sign in to comment.