Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
angelinashepherd opened this issue Sep 29, 2024 · 2 comments
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project

Comments

@angelinashepherd
Copy link

angelinashepherd commented Sep 29, 2024

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 angelinashepherd changed the title Unable to send slack message directly to user with completeUploadExternal Unable to send slack message directly to user using files.completeUploadExternal Sep 29, 2024
@filmaj
Copy link
Contributor

filmaj commented Sep 29, 2024

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

@filmaj filmaj added question M-T: User needs support to use the project needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info and removed untriaged labels Sep 29, 2024
@seratch
Copy link
Member

seratch commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

3 participants