Skip to content

When someone shares Apple Music links on Slack, respond with the corresponding link for Spotify

License

Notifications You must be signed in to change notification settings

adig/SpotifySlackHelper

Repository files navigation

Spotify Slack Helper

Simple nodejs Slack app that listens for links to Apple Music albums, artists or tracks and responds with the corresponding link for Spotify.

How it works

The service listens to the link_shared Slack WebAPI event that matches the configured App Unfurl Domains, in this case itunes.apple.com.

⚠️ links:read Slack App Permission Scope is required for this.

Using the id from the shared URL it fetches information about the track/album/artist using the iTunes API (see https://github.com/fvdm/nodejs-searchitunes)

Using the metadata fetched from iTunes it queries the Spotify API for the equivalent item and shares it in the same channel. See https://github.com/thelinmichael/spotify-web-api-node

⚠️ chat:write:bot Slack App Permission Scope is required for this.

Note: When using link_shared and App Unfurl Domains the classic Slack unfurl isn't displayed anymore. This service simulates the classic unfurl using the Metascraper library.

⚠️ links:write Slack App Permission Scope is required for this to work.

Setup

  1. Clone repo and yarn install

  2. Create a Slack app

    • Enable Events Subscription for your app More
    • Subscribe to the link_shared event
    • Add itunes.apple.com to the App Unfurl Domains
    • Add links:read, links:write and chat:write:bot permission scopes
  3. Create a Spotify App here

  4. Add config as environment variables:

    • SLACK_SIGNIN_SECRET - Signing Secret in App Credentials
    • SLACK_ACCESS_TOKEN - OAuth Access Token
    • SPOTIFY_CLIENT_ID
    • SPOTIFY_CLIENT_SECRET
    • TEST_ACCESS_TOKEN - access token used to authorize requests to test endpoints (see below)
  5. Start the app with yarn start

  6. Add the Request URL in the Events Subscription page for your Slack App. The url will be <EXTERNAL_URL>/client/events. You can use ngrok for local development

Testing

The service provides some urls to test the url processing as well as testing iTunes and Spotify querying without the Slack integration. Parameters ar passed as query parameters.

/test

  • url - AppleMusic url
  • token - access token, must be the same value as TEST_ACCESS_TOKEN env variable for the request to be accepted

/test-itunes

  • id - id of item to query for
  • token - access token, must be the same value as TEST_ACCESS_TOKEN env variable for the request to be accepted

test-spotify

  • query - value to search for as item name
  • type - what items to search for, values can be: album, artist, track
  • market - country code for market where to search for items. Defaults to us
  • token - access token, must be the same value as TEST_ACCESS_TOKEN env variable for the request to be accepted

About

When someone shares Apple Music links on Slack, respond with the corresponding link for Spotify

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •