slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.74k stars 394 forks source link

Unable to send slack message directly to user using files.completeUploadExternal #2275

Open angelinashepherd opened 13 hours ago

angelinashepherd commented 13 hours ago

I am trying to upload a file to Slack and then send a direct message to a user, instead of to a channel. I'm using the node Slack SDK

const { ok, upload_url, file_id } = await slackClient.files.getUploadURLExternal({
    filename: fileName,
    length: fileLength,
  });

  if (!ok || isNil(file_id)) {
    throw new Error(`Failed to initiate uploading file ${fileName} to Slack channel ${slackChannelId}`);

  }

  const response = await axios({
    method: methods.POST,
    url: upload_url,
    responseType: 'arraybuffer',
    data: fileContent,
  });

  if (response.status !== StatusCodes.OK) {
    throw new Error(`Failed to upload file ${fileName} to Slack channel ${slackChannelId}`);
  }

  await slackClient.files.completeUploadExternal({
    files: [{ id: file_id, title: fileName }],
    channel_id: 'DXXXXXXXXXXXX',   // my own Slack 
    initial_comment: 'file was uploaded successfully!',
  });

Am I not able to do so?

filmaj commented 9 hours ago

What kind of token (user or bot) are you using when making the file upload API calls? What error are you seeing?