[See post #4 for a working solution]
Short #FridayFun this week inspired by Mr. White. Not the character in Reservoir Dogs, but the slightly less lethal dude here at Sangoma, @mwhite. This started out with him providing this link and asking how to pause Spotify audio when the phone rings: Pause Playback | Spotify for Developers
Which as it turns out is not all that difficult. If you have Spotify premium, you can step thru the process to get an API token, grant privileges for controlling audio, and the end result is a crazy long curl expression that looks something like this:
curl -X "PUT" "https://api.spotify.com/v1/me/player/pause" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer Long_Random_Token_String" -H "content-length: 0"
The linked page above documents this, but I ended up having to add the content-length header to make it work correctly. Translating to dialplan, the following placed in extensions_custom.conf
[from-internal-custom]
exten => 4508,1,Set(token=Long_Random_Token_String) ;edit to use actual token
exten => 4508,n,System(curl -X "PUT" "https://api.spotify.com/v1/me/player/pause" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer ${token}" -H "content-length: 0")
exten => 4508,n,Hangup
So now you have a sequence of digits (4508, edit to suit) that won’t answer the channel, such that whenever they get dialed, it will pause audio for that specific Spotify user. You can add this dial string to ring groups, queues or FMFM settings on the extension such then whenever something causes a phone to ring, the pause API call is sent. For testing, you just dial 4508 directly. I don’t see an API for unpause, which is just as well, the dialplan to make that work would add considerable complexity.
As an aside, I tried to translate the above system curl to a proper Asterisk Curl Application, but I don’t know how (or if) one can do a PUT using Asterisk Curl. Would love for someone to educate me if that’s possible.
This would be trivially easy to add to a Superfecta Send-to module. I don’t think it would have broad appeal, but would eliminate the necessity of custom dialplan. There is already one for pausing media player, the name of which escapes me at the moment.