[Python] File is not showing the the slack channel

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Node.js, I want to send a file to Slack, I am using getUploadURLExternal and completeUploadExternal functions. My initial message (Incident detected .....) were displaying in the Channel and file also stored successfully as I see url_private in the logs but not displaying file I stored, in the Channel I mentioned, below is my code.

    const messageRes = await web.chat.postMessage({
    channel: "#jr-developers",
    text: " Incident detected! Please check the attached report below.",
    });

    console.log("Message sent:", messageRes.ts);
    // console.log(messageRes);

    // Step 3: Upload file content to the URL using axios
    const fileName = "continent.csv";
    const fileBuffer = fs.readFileSync(fileName);
    const fileLength = fileBuffer.length;

    // Step 2: Get upload URL from Slack
    const uploadURLRes = await web.files.getUploadURLExternal({
    filename: fileName,
    length: fileLength,
    });

    const uploadUrl = uploadURLRes.upload_url;
    const fileId = uploadURLRes.file_id;

    console.log("Received upload URL from Slack.", uploadUrl, fileId);

    await axios.put(uploadUrl, fileBuffer, {
    headers: {
    "Content-Type": "application/octet-stream",
    "Content-Length": fileLength,
    },
    });

    console.log("File uploaded to Slack storage.");
    // console.log(axiosRes);

    // Step 4: Complete the upload and share in thread
    const res = await web.files.completeUploadExternal({
    files: [
    {
    id: fileId,
    title: "slack-test",
    },
    ],
    channel_id: messageRes.channel,
    thread_ts: messageRes.ts,
    });



    console.log("File attached to thread successfully.");


    These are the logs,

    {
    ok: true,
    files: [
    {
    id: 'F0****J3A',
    created: ***,
    timestamp: ***,
    name: 'continent.csv',
    title: 'slack-test',
    mimetype: '',
    filetype: '',
    pretty_type: '',
    user: '***',
    user_team: '***',
    editable: false,
    size: 86,
    mode: 'hosted',
    is_external: false,
    external_type: '',
    is_public: false,
    public_url_shared: false,
    display_as_bot: false,
    username: '',
    url_private: 'https://files.slack.com/files-pri******continent.csv',
    url_private_download: 'https://files.slack.com/files-pri*****download/continent.csv',
    media_display_type: 'unknown',
    permalink: 'https://profitops.slack.com/files****continent.csv',
    permalink_public: 'https://slack-files.com/*****',
    comments_count: 0,
    is_starred: false,
    shares: {},
    channels: [],
    groups: [],
    ims: [],
    has_more_shares: false,
    has_rich_preview: false,
    file_access: 'visible'
    }
    ],
    response_metadata: {
    scopes: [
    'identify', 'channels:history',
    'groups:history', 'im:history',
    'mpim:history', 'channels:read',
    'groups:read', 'im:read',
    'mpim:read', 'users:read',
    'channels:write', 'chat:write',
    'files:write', 'groups:write',
    'im:write', 'mpim:write',
    'identity.basic', 'identity.email',
    'identity.avatar'
    ],
    acceptedScopes: [ 'files:write' ]
    }
    }
    File attached to thread successfully.


    I have checked everything. please help.

    Continue reading...

Compartilhe esta Página