Slack Bolt.JS upload files for block

Viewed 14

I am trying to create a slack bot that will upload one of my local files to slack and posting it in a block message.

I am uploading the image with app.client.files.upload() and trying to make it public with app.client.files.sharedPublicURL() but when i do i get the error not_allowed_token_type. Does anyone know what the problem could be or how i could achieve this? I am unable to host the images publicly on my own, they need to be uploaded to slack.

This is my code:

    //Upload image to slack and include it in a postMessage
        const result = await app.client.files.upload({
            token: SLACK_BOT_TOKEN,
            file: fs.createReadStream('/Users/linusromland/Pictures/48645689.jpg')
        });
        console.log(result);

        const results2 = await app.client.files.sharedPublicURL({
            token: SLACK_BOT_TOKEN,
            file: result.file.id
        });
        console.log(results2);

        // Post a message to the channel with the image
        await app.client.chat.postMessage({
            token: SLACK_BOT_TOKEN,
            channel: linus.slackId,
            text: 'Hello world!',
            blocks: [
                {
                    type: 'image',
                    image_url: results2.file.permalink_public,
                    alt_text: 'Linus'
                }
            ]
        });
1 Answers

I realised the problem. It was the wrong token (needed user token) and also my workspace did not have Slack Pro.

Related