Access Slack files from a slack bot

前端 未结 4 1345
小蘑菇
小蘑菇 2021-02-18 23:28

I need a slack bot that\'s able to receive and save files send from slack chatrooms.

The problem is: slack doesn\'t send file contents, but an array of links pointing to

4条回答
  •  轮回少年
    2021-02-18 23:57

    for those wanting to accomplish this with Bash & cURL, here's a helpful function! It will download the file to the current directory with a filename that uniquely identifies the file, even if the file has the same name as others in your file listing.

    function slack_download {
      URL="$1";
      TOKEN="$2"
      FILENAME=`echo "$URL" | sed -r 's/.*\/(T.+)\/([^\/]+)$/\1-\2/'`; 
      curl -o "$FILENAME" -H "Authorization: Bearer $TOKEN" "$URL"; 
    }
    # Usage: 
    # Downloads as ./TJOLLYDAY-FANGBEARD-NSFW_PIC.jpg
    slack_download "https://files.slack.com/files-pri/TJOLLYDAY-FANGBEARD/NSFW_PIC.jpg" xoxp-12345678901-01234567890-123456789012-abcdef0123456789abcdef0123456789
    

提交回复
热议问题