How to upload files to slack using file.upload and requests

后端 未结 2 431
暗喜
暗喜 2021-02-06 08:59

I\'ve been searching a lot and I haven\'t found an answer to what I\'m looking for.

I\'m trying to upload a file from /tmp to slack using python requests bu

2条回答
  •  借酒劲吻你
    2021-02-06 09:39

    Base on the Slack API file.upload documentation What you need to have are:

    • Token : Authentication token bearing required scopes.
    • Channel ID : Channel to upload the file
    • File : File to upload

    Here is the sample code. I am using WebClient method in @slack/web-api package to upload it in slack channel.

    import { createReadStream } from 'fs';
    import { WebClient } from '@slack/web-api';
    
    const token = 'token'
    const channelId = 'channelID'
    const web = new WebClient(token);
    
    const uploadFileToSlack = async () => {
       await web.files.upload({
         filename: 'fileName',
         file: createReadStream('path/file'),
         channels: channelId,
       });
    }
    

提交回复
热议问题