Search code examples
spotifyslackzapier

Get Spotify links shared in a Slack Channel added to a Spotify playlist using Zapier


I have a Slack group with a bunch of friends and we always share Spotify links. I wanted these links to be added to a big Spotify playlist automatically, so here's the solution I came up with using Zapier to bridge the gap. As I wanted to use just the free tier it required 2 separate Zaps to achieve this. Many of the solutions online offer ways to sync Spotify to Slack, but this offers the opposite.


Solution

  • Zapier is fully capable of handling this particular task in one Zap, the trick is that it exceeds the three action limit of the free tier, so I had to break it into two Zaps, one to handle filtering Spotify links from the #music Slack channel, and the second to parse the URL and extract the Spotify ID of the track and post it to the playlist.

    Filter Spotify Links to Slack Channel

    1. Create a new Slack channel called #spotify-links. I added a description to mine to tell people the purpose of it and to not join this particular channel. This also needs to be public, as Zapier can't see private channels.

    2. In Zapier create a new Zap integration with Slack.

      • Slack Trigger -> New Message Posted to Channel -> Continue
      • Connect the Slack account you want to use -> Continue
      • Channel -> #music (or whatever the channel your group uses for music)
      • Trigger for Bot Messages -> No -> Continue
    3. Add a filter action

    4. Add another action and select Slack

      • Slack Trigger -> Send Channel Message -> Continue
      • Connect the Slack account you want to use -> Continue
      • Select the channel you created in step 1
      • Message Text -> From the dropdown to the right, select New Message Posted To Channel -> Click the arrow to the right and choose the Text field
      • There's a bunch bot settings you can customize if you feel so inclined here as well
      • Broadcast to channel -> no -> Continue

    Slack to Spotify Playlist

    1. Create a new Zap integration with Slack -> Continue

      • Slack Trigger -> New Message Posted to Channel -> Continue
      • Connect the Slack account you want to use -> Continue
      • Channel -> #spotify-links -> Continue
      • Trigger for Bot Messages -> Yes -> Continue
    2. Add a Formatter action -> Continue

      • Text -> Text -> Continue
      • Transform -> Exact pattern
      • Values -> Input -> Select dropdown to the right -> New Message Posted to Channel -> Text
      • I found a regex that would select just the Spotify ID out of the URL, even if there is a query string, as Spotify often adds one to their sharing links.
      • Pattern -> [^\/][\w]+(?=\?) -> Continue

        1. Add a Spotify Action -> Continue
      • Create -> Add Track to Playlist -> Continue
      • Connect Spotify account you want to use -> Continue
      • Playlist -> Choose the playlist you want to add the music to on Spotify. If you haven't created it yet, go to Spotify and create a new public playlist
      • Track -> Use Custom Value(advanced)
      • Custom Value for Track Track ID -> Choose 2 Text from the dropdown -> Continue

    And that should have you rolling. Be sure to test your data and make sure things are pulling properly along the way.