Unable to send slack message directly to user using files.completeUploadExternal
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?
What kind of token (user or bot) are you using when making the file upload API calls? What error are you seeing?
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.
👋 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.
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.
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 😇