bolt-js icon indicating copy to clipboard operation
bolt-js copied to clipboard

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

Open angelinashepherd opened this issue 1 year ago • 2 comments

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?

angelinashepherd avatar Sep 29 '24 09:09 angelinashepherd

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

filmaj avatar Sep 29 '24 13:09 filmaj

channel_id: 'DXXXXXXXXXXXX', // my own Slack

Another possible cause of the failure your code is facing is that this DM ID might be wrong. The DM must be between your app's bot user and a human user within your Slack workspace. Copying a DM ID from a human user's DM may be a different one. You can use conversations.open API to get a valid DM ID.

seratch avatar Sep 30 '24 00:09 seratch

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar Nov 04 '24 00:11 github-actions[bot]

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

github-actions[bot] avatar Nov 18 '24 00:11 github-actions[bot]

If someone has encountered this issue, please look at the following document. It will save you some time. https://tools.slack.dev/node-slack-sdk/web-api/#upload-a-file

This describes the filesUploadV2 wrapper around the files.getUploadURLExternal and files.completeUploadExternal methods.

PS: I think both methods would deserve a reference for this wrapper. Even better, an example 😇

hervenivon avatar Feb 13 '25 15:02 hervenivon