2
votes

I have built a slack slash command which is up and running and which currently displays an image using an attachment (https://api.slack.com/docs/message-attachments). Instead of an image, I'd like it to have an audio player. It does not need to be my custom audio player, it can be a simple play button but it should be playable within slack. Is there a way to provide the URL to an audio file and let slack show a player (like for images)?

3

3 Answers

1
votes

I contacted the Slack devs support and they confirmed that what I'm trying to do is not possible. They only support playing files within the Slack conversation from some 3rd party service integrations. Too bad :S

1
votes

Another option: Slack will present a play button within slack if you upload it as a file. If you have a URL for an audio file, you could download the file and upload it to slack via the files.upload API (https://api.slack.com/methods/files.upload)

ExampleVideo

0
votes

Slack supports playing audio files from a few popular sites within its platform. I do not have a full list, but two sites that work well are:

So what you can do is to include a direct link to an audio a file from those sites in your message and Slack will automatically unfurl it to show a basic information and a play button to the user. The user can then play the media file within the Slack platform.

However, unfurling in Slack can be tricky. Here are some pointers with regards to your question:

  • Depending on the site you need to enable unfurling for links by setting (unfurl_links to true) in chat.PostMessage. This is required for soundcload files. Youtube files however seam to work with the default settings.
  • Slack will only unfurl a link the first time it appears in a channel.
  • For more details on how unfurling works in Slack, check out the official documentation on the topic.

Here is a full example with Slack Message builder.

Example output in Slack: enter image description here