-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added missing dependency, missing api key placeholder, updated docs * Apply black formatting and validate bot token functionality * acknowledging black formatting * added the validation to update tokens as well * Made the token validation errors looks nicer * getting rif of duplicate dependency
- Loading branch information
1 parent
c9e0d77
commit 880c42a
Showing
5 changed files
with
62 additions
and
4 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
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,43 @@ | ||
import requests | ||
from fastapi import HTTPException | ||
|
||
SLACK_API_URL = "https://slack.com/api/auth.test" | ||
SLACK_CONNECTIONS_OPEN_URL = "https://slack.com/api/apps.connections.open" | ||
|
||
|
||
def validate_bot_token(bot_token: str) -> bool: | ||
headers = {"Authorization": f"Bearer {bot_token}"} | ||
response = requests.post(SLACK_API_URL, headers=headers) | ||
|
||
if response.status_code != 200: | ||
raise HTTPException( | ||
status_code=500, detail="Error communicating with Slack API." | ||
) | ||
|
||
data = response.json() | ||
if not data.get("ok", False): | ||
raise HTTPException( | ||
status_code=400, | ||
detail=f"Invalid bot token: {data.get('error', 'Unknown error')}", | ||
) | ||
|
||
return True | ||
|
||
|
||
def validate_app_token(app_token: str) -> bool: | ||
headers = {"Authorization": f"Bearer {app_token}"} | ||
response = requests.post(SLACK_CONNECTIONS_OPEN_URL, headers=headers) | ||
|
||
if response.status_code != 200: | ||
raise HTTPException( | ||
status_code=500, detail="Error communicating with Slack API." | ||
) | ||
|
||
data = response.json() | ||
if not data.get("ok", False): | ||
raise HTTPException( | ||
status_code=400, | ||
detail=f"Invalid app token: {data.get('error', 'Unknown error')}", | ||
) | ||
|
||
return True |
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