-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add slack notifications for error messages
- Loading branch information
nikhilleo10
committed
Nov 22, 2023
1 parent
3f8fef9
commit 6ad2bbc
Showing
6 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ DB_PORT= | |
DB_NAME= | ||
OPENAI_API_KEY_GPT4= | ||
OPENAI_API_KEY_WEDNESDAY= | ||
YOUR_SECRET_KEY= | ||
REDIS_URL= | ||
SLACK_WEBHOOK_URL= |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import requests | ||
import json | ||
from dotenv import load_dotenv | ||
from fastapi import HTTPException | ||
|
||
load_dotenv() | ||
|
||
def send_slack_message(payload): | ||
"""Send a Slack message to a channel via a webhook. | ||
Args: | ||
payload (dict): Dictionary containing Slack message, i.e. {"text": "This is a test"} | ||
Returns: | ||
HTTP response code, i.e., <Response [503]> | ||
""" | ||
webhook_url = os.environ.get('SLACK_WEBHOOK_URL') # Use get to avoid KeyError | ||
|
||
if not webhook_url: | ||
raise HTTPException(status_code=400, detail="Slack URL not configured.") | ||
|
||
headers = { | ||
'Content-Type': 'application/json', # Specify the content type | ||
} | ||
|
||
response = requests.post(webhook_url, headers=headers, data=json.dumps(payload)) | ||
return response |