Simple nodejs Slack app that listens for links to Apple Music albums, artists or tracks and responds with the corresponding link for Spotify.
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.
-
Clone repo and
yarn install -
- Enable Events Subscription for your app More
- Subscribe to the
link_sharedevent - Add
itunes.apple.comto the App Unfurl Domains - Add
links:read,links:writeandchat:write:botpermission scopes
-
Create a Spotify App here
-
Add config as environment variables:
SLACK_SIGNIN_SECRET- Signing Secret in App CredentialsSLACK_ACCESS_TOKEN- OAuth Access TokenSPOTIFY_CLIENT_IDSPOTIFY_CLIENT_SECRETTEST_ACCESS_TOKEN- access token used to authorize requests to test endpoints (see below)
-
Start the app with
yarn start -
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
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.
url- AppleMusic urltoken- access token, must be the same value asTEST_ACCESS_TOKENenv variable for the request to be accepted
id- id of item to query fortoken- access token, must be the same value asTEST_ACCESS_TOKENenv variable for the request to be accepted
query- value to search for as item nametype- what items to search for, values can be:album,artist,trackmarket- country code for market where to search for items. Defaults toustoken- access token, must be the same value asTEST_ACCESS_TOKENenv variable for the request to be accepted