如何从 slackBot 中查看文件

问题描述 投票:0回答:0

我有一个 slack 机器人,它有权查看频道历史记录和读取文件。 但是我的代码得到了类似 html 响应的东西,而不是文件中的内容

我的代码看起来像

from slack_sdk.errors import SlackApiError

SLACK_BOT_TOKEN = "<someToken>"
SLACK_CHANNEL_ID = "<channelId>"

client = WebClient(token=SLACK_BOT_TOKEN)
try:
    # Call the conversations.history method using the client
    # to retrieve the channel's message history
    # Set the limit argument to control the number of messages to retrieve
    # Set the oldest argument to retrieve messages starting from a specific timestamp
    # See the API documentation for more options and details
    response = client.conversations_history(
        channel=SLACK_CHANNEL_ID,
        limit=1
    )

    # Find the file in the response and download it
    for message in response.data["messages"]:
        if "files" in message:
            for file in message["files"]:
                file_url = file["url_private_download"]
                headers = {
                    "Authorization": f"Bearer {SLACK_BOT_TOKEN}"
                }

                response = requests.get(file_url, headers=headers)

                


                # Print the file contents
                print(response.content.decode())

except SlackApiError as e:
    # Print any errors
    print("Error: {}".format(e))'''

What can I do in order to see the file content  ? 
My response looks like :
<!DOCTYPE html><html lang="en-US" class=""><head><script type="text/javascript" crossorigin="anonymous" 
    
slack slack-api
© www.soinside.com 2019 - 2024. All rights reserved.