Coverage for app / backend / src / couchers / slack.py: 88%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-11 01:51 +0000

1import logging 

2 

3import requests 

4 

5from couchers.config import config 

6 

7logger = logging.getLogger(__name__) 

8 

9 

10def send_slack_message(channel: str, markdown: str) -> None: 

11 if not config["SLACK_ENABLED"]: 

12 logger.info(f"Slack disabled, would have sent to {channel}: {markdown}") 

13 return 

14 

15 response = requests.post( 

16 "https://slack.com/api/chat.postMessage", 

17 headers={"Authorization": f"Bearer {config['SLACK_BOT_TOKEN']}"}, 

18 json={"channel": channel, "markdown_text": markdown}, 

19 timeout=10, 

20 ) 

21 response.raise_for_status() 

22 data = response.json() 

23 if not data.get("ok"): 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true

24 raise Exception(f"Slack API error: {data.get('error')}")