슬랙 채널로 스크린샷을 자동 전송해주는 프로젝트를 진행하게 되었다. 내가 까먹을까봐 정리해두고자한다.
Slack api > Create an App 버튼 클릭
slack api 에 들어가서 우측 초록색 버튼 Create New App을 클릭
From scratch 클릭
앱 이름 & 워크스페이스 선택
앱 이름과 워크스페이스 선택 후 Create App 버튼을 클릭한다.
발급받은 token 을 사용해서 이런식으로 코드를 작성하면 된다.
def send_to_slack(product_name, channel, screenshot_path, message=""):
try:
response = client.files_upload_v2(
channel=SLACK_CHANNEL,
file=screenshot_path,
initial_comment=f"{product_name} ({channel}) - {message}",
)
if response.get("ok"):
print(f"✅ Slack으로 전송 완료: {screenshot_path}")
else:
print(f"⚠️ Slack 전송 실패: {response.get('error')}")
except SlackApiError as e:
print(f"⚠️ Slack API 오류: {e.response['error']}")
호출 방법이다.
capture_screenshot(product_name, channel, url)
이 함수는 스크린샷을 저장한 뒤에 해당 파일을 Slack에 업로드해주는 방법으로 작동한다.