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

Allow user file upload to work #967

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ node {

This feature requires [botUser](#bot-user-mode) mode.

##### File upload to a user channel

You can upload files to a user channel by messaging the user first and then using the channel ID from the message response:

```groovy
node {
sh "echo hey > blah.txt"
def slackResponse = slackSend channel: '$userId', message: 'Hey', sendAsText: true
slackUploadFile filePath: "*.txt", channel: slackResponse.channelId
}
```

#### Threads Support

You can send a message and create a thread on that message using the pipeline step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,11 @@ protected Void run() throws IOException, InterruptedException, ExecutionExceptio

String channelId;
try {
channelId = SlackChannelIdCache.getChannelId(populatedToken, cleanChannelName(channel));
String channelName = cleanChannelName(channel);
channelId = SlackChannelIdCache.getChannelId(populatedToken, channelName);
if (channelId == null) {
String message = "Failed uploading file to slack, channel not found: " + channel;
if (step.failOnError) {
throw new AbortException(message);
} else {
listener.error(message);
return null;
}
// possibly a user ID which won't be found in the channel ID cache
channelId = channelName;
}
} catch (CompletionException | SlackChannelIdCache.HttpStatusCodeException e) {
throw new AbortException("Failed uploading file to slack, channel not found: " + channel + ", error: " + e.getMessage());
Expand Down