본문으로 바로가기

Slack messge Send (files_upload) / WebClient 이용

category selenium 2023. 3. 7. 02:35
728x90

Slack bot을 이용한 첨부파일을 포함한 메세지 보내기

* 참고 : https://api.slack.com/tutorials/uploading-files-with-python

 

Uploading files using the Slack Python SDK | Slack

By Jason WongSlack appsPythonSlack Development Kits This article details how to use the slack-sdk PyPI package to upload files to Slack with some code samples. By the end of article, you will know how to: Upload and delete files in Slack via the Slack Web

api.slack.com

 

1. slack bot 생성

- Scope permission에 files:write 권한이 꼭 필요

 

2. 함수 작성

import ssl
import certifi

def attachfile_withSlack():
        ssl_context = ssl.create_default_context(cafile=certifi.where())
        client = slack.WebClient(token='토큰값', ssl=ssl_context)
        response = client.files_upload(
            channels="채널명",
            title="제목",
            file="파일위치",
            initial_comment="코멘트내용"
        )

아래 에러 발생 시 

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate

설치 필요

pip install certifi