100 Days of Gen AI: Day 33

There’s a feature I’ve wanted in Siri for a long time. The use case is I’m listening to music while driving, or cooking in the kitchen, or doing some other hands-free activity. And then I want to either:

  1. remove the current song from the current playlist, or
  2. add the current song to a specific playlist (I have one main playlist where almost all song additions go)

So I tried coding this up, using ChatGPT as my assistant. Apple has a powerful feature called “Shortcuts” that lets you setup automations, which can then be triggered by voice using Siri. There’s a whole gallery of possible automations, but the perfect one for our use case is called “Get Contents of URL,” which is an automation that just makes a web request. It can request a GET, POST, PUT, etc and can include custom headers and a payload. It looks like this:

Apple shortcuts

Assisted by ChatGPT, I wrote a web server in Go that can handle web requests from the Shortcuts app. This web server then makes a request to the Spotify Web API to get the current playing song. (I haven’t yet gotten to the add/delete functionality.)

The tricky part is that in order to interact with a specific user’s profile, the user must complete the authorization flow where they login to spotify and agree to share certain data with the application. Once authorized, the app gets back a spotify session token valid for 1 hour. I extended the Go web server to handle the various endpoints required to complete this authorization flow (adding /login, /callback, and /setup endpoints).

Once we get back the token, it can be saved in the shortcuts app and passed along as an Authorization header (this works), but it’s only valid for 1 hour, after which point the Siri integration will stop working.

Setup complete screen

After about 3 hours of work, I got to a working state, though the integration stops working once the token reaches the 1 hour expiration.

Handling this token in a long-lived way, and then adding the add/remove functionality are next!