You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the upload method I'm using, to upload and post PDF files to Slack. The files are generated via a script on on google cloud run and uploaded directly to slack, they're not hosted on Google cloud run, it's serverless.
def upload_file(
self,
channel_id: str,
user_id: str,
file_bytes: bytes,
filename: str,
title: str,
initial_comment: str = "",
) -> dict:
"""
Uploads a file to Slack using the external file upload workflow and posts
an ephemeral message (visible only to the specified user) with an attachment
referencing the uploaded file.
"""
# Step 1: Get the upload URL from Slack.
file_length = len(file_bytes)
upload_url_resp = self.client.files_getUploadURLExternal(
filename=filename, length=file_length
)
if not upload_url_resp.get("ok"):
raise ValueError(f"Failed to get upload URL: {upload_url_resp}")
upload_url = upload_url_resp["upload_url"]
file_id = upload_url_resp["file_id"]
# Step 2: Upload the file bytes using an HTTP POST.
payload = {
"filename": filename,
"token": self.token,
}
post_response = requests.post(upload_url, params=payload, data=file_bytes)
if post_response.status_code != 200:
raise ValueError(
f"File upload failed (status {post_response.status_code}): {post_response.text}"
)
# Step 3: Complete the external upload so the file appears in Slack.
complete_resp = self.client.files_completeUploadExternal(
files=[{"id": file_id, "title": title}],
channel_id=channel_id,
initial_comment=initial_comment,
thread_ts=None,
)
if not complete_resp.get("ok"):
raise ValueError(f"Failed to complete file upload: {complete_resp}")
# Step 4: Post an ephemeral message with an attachment referencing the file.
attachment = {
"title": title,
"image_url": upload_url,
}
post_msg_resp = self.client.chat_postEphemeral(
channel=channel_id,
user=user_id,
text=initial_comment or f"File uploaded: {title}",
attachments=[attachment],
)
return post_msg_resp
I want to share files in a ephermal way, this method shares files publicly only.
so I must remove the channel_id and then grab the link and use chat_postEphemeral to send the URL to the user. Therefore files_completeUploadExternal can no longer post files directly to Slack.
I'm unable to show the PDF as an embeddable attachment, the way that files_completeUploadExternal shows the file
I'm unable to use files_completeUploadExternal to post to a channel privately (ephermal) or to send the PDF via DM
I don't want to make the permalinks shareable publicly, and then send the links via chat_postEphemeral because the data is sensitive and belongs to my company.
If I make the data public, I'd have to create another service that deletes the data every few days and use database to keep track of the visible files. It's a whole other project.
The text was updated successfully, but these errors were encountered:
elieobeid7
changed the title
How to share files in a ephermal way?
How to share files in a ephermal way to a user in a channel or DM?
Feb 4, 2025
elieobeid7
changed the title
How to share files in a ephermal way to a user in a channel or DM?
How to share files in a ephermal way to a user in a channel or DM without making the files publicly available on the internet?
Feb 4, 2025
Unfortunately, the ephemeral message is not suitable for your use case because the mechanism does not allow file previews for you.
As a workaround, please consider sending a DM to the user by calling chat.postMessage API along with user_id (or conversations.open API then pass the DM ID to chat.postMessage) instead. If you still prefer informing the user via an ephemeral message in the same channel, it's possible to include the permalink of the DM message in the ephemeral message (you can get the permalink by calling chat.getPermalink API).
Okay but that means making the PDF permalink shareable publicly, otherwise the user can't click on it, right?
That's what I'm trying to avoid, I don't want to make the PDF link shareable publicly on the internet, I want to keep it within slack, otherwise I would have to create a separate cronjob to delete permalinks every week or so.
No, it isn't. chat.getPermalink returns the URL that points to a specific message. I meant if you want to navigate a user to DM smoothly from an ephemeral message, you can use the message permalink. The visibility of the attached file depends on where you share the file. When you share a file only within a DM, the file is visible only for the people in the DM. Of course, if any of them reshares the file somewhere within the Slack workspace, more people will be able to see the file. But this does not mean the file is publicly visible. It's visible within the workspace.
This is the upload method I'm using, to upload and post PDF files to Slack. The files are generated via a script on on google cloud run and uploaded directly to slack, they're not hosted on Google cloud run, it's serverless.
I want to share files in a ephermal way, this method shares files publicly only.
so I must remove the
channel_id
and then grab the link and usechat_postEphemeral
to send the URL to the user. Thereforefiles_completeUploadExternal
can no longer post files directly to Slack.files_completeUploadExternal
shows the filefiles_completeUploadExternal
to post to a channel privately (ephermal) or to send the PDF via DMchat_postEphemeral
because the data is sensitive and belongs to my company.If I make the data public, I'd have to create another service that deletes the data every few days and use database to keep track of the visible files. It's a whole other project.
The text was updated successfully, but these errors were encountered: