티스토리 뷰

공부

[python] slack chat & files

승가비 2022. 8. 31. 15:29
728x90
import logging

from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

logger = logging.getLogger(__name__)


def chat(token, channel, text):
    client = WebClient(token=token)

    try:
        client.chat_postMessage(channel=channel, text=text)
    except SlackApiError as e:
        logger.error(f"[Error] posting message: {e}")

    return {
        "channel": channel,
        "text": text,
    }


def files(token, channel, file):
    client = WebClient(token=token)

    try:
        client.files_upload(
            channels=channel,
            initial_comment=None,
            file=file,
        )
    except SlackApiError as e:
        logger.error("[Error] uploading file: {}".format(e))

    return {
        "channel": channel,
        "file": file,
    }

https://yunwoong.tistory.com/132

 

[ 오류 해결 ] slacker.Error: invalid_auth

Slack의 정책 업데이트로 인해 2021.2.24 이후로 새로 생성된 bot은 slacker 라이브러리를 이용 할 수 없습니다. slacker.Error: invalid_auth 라는 에러가 발생하죠. slack.chat.post_message 을 대신 할 함수를..

yunwoong.tistory.com

https://developerdk.tistory.com/96

 

slacker.Error: invalid_auth 에러 해결방법

안녕하세요 유튜버 조코딩입니다. 제 채널의 크레온 API를 활용한 파이썬 주식 투자 자동화 강의 들으시는 분들 중 slacker를 이용하실 때 2021년2월24일 이후 invalid_auth에러가 떠서 진행이 안되시는

developerdk.tistory.com

https://api.slack.com/methods/chat.postMessage/code

 

chat.postMessage API method

Sends a message to a channel.

api.slack.com

https://api.slack.com/methods/files.upload

 

files.upload API method

Uploads or creates a file.

api.slack.com

 

728x90
댓글