How to display the currently playing Spotify track as your Teams status message

Yes, you read that right.

Let’s acknowledge the sheer importance of what you’re about to read.

Think of the cultural, teamwork, and employee benefits. This is possibly the most important thing you can implement as a user, in your Microsoft 365 environment.

No, you’re right… this particular thing is completely and utterly useless.

The Challenge?

I honestly couldn’t think of how in any universe this would benefit a single person – be it you sharing the information, or other people reading it. There are a number of existing social tools and apps that will show what you’re currently playing, but this is the worksplace.

Personally, it just came about as I had been experimenting with a couple of other things in Power Apps & Automate, and one morning while walking the dog I wondered if this was at all possible. (yes, I think of what workflows I can build while walking the dog – don’t you!?)

I thought, maybe let’s put “Current mood is based on: <Spotify track info>” but thought that it wasn’t accurate as sometimes my music choice is driven by the mood as well as the other way around. Plus, how does that make any difference to my colleagues?

Do I have the right to be angry in a call just because I was listening to Sepultura or Fear Factory?

Do I have the right to be crass and joking just because I was listening to The Lonely Island?

The Solution?

Yeah ok, enough faff, on with the “solution”. How can I inform my colleagues what I’m currently listening to on Spotify currently? Because it’s clearly so important to me…

Spotify has publicly available APIs which are well document and clearly laid out. The first challenge was the fact that the only way for Spotify to trigger anything was to use the Web Client SDK, which was well beyond my comfort zone as I am not a coder. So opted for the lazy man’s “trigger” – a workflow that runs on an interval. And because songs have differing track lengths, I opted to have it run every 5 minutes between 9am and 6pm. Yes, yes I did. Because it’s that important.

I followed the instructions in this great blog post that explains how to create a custom connector for Power Platform, which can be used for the GET request: https://thatapiguy.tech/2019/12/08/spotify-custom-connector-for-power-platform/

So now that we have our “trigger” and initial data collection, how do we get this into our Teams status message? No Microsoft Graph required here. Because of the importance of this solution, we’re going to use endpoints that are undocumented and unsupported. And we’re going to use a Power Automate action that is completely unrelated.

You can read about how to use the Send an HTTP request to SharePoint connector to set your Teams status here: https://www.damobird365.com/teams-status-update-via-power-automate/

Here’s what the final workflow looks like:

A couple of the key features of this workflow:

  • The status message is set to expire at the end of the song
  • If Spotify is paused or not running the workflow ends without updating your Teams status message

Breaking down the workflow

Let’s start with our trigger:

From here we initialise some variables and parse the output to help with text cleanup and presentation later:

(see the appendix at the end of the blog post for the JSON schema)

Once we’ve got that, we then need to calculate the time when this status message should expire – ideally the end of the track.

To do that, we take away our current progress from the duration, and because it’s all in milliseconds we divide by 1,000 to give us seconds:

Now we add those seconds to the current time:

Now that we’ve done the maths, let’s get the data out. Firstly – a condition that if the track isn’t currently playing, we should stop the workflow. If it is, continue on and sift through the JSON data to set the artist & track variables:

The reason for the apply to each is because the artist data shows up in both the album and track information. I’m sure that step could’ve been done better, but workflow efficiency wasn’t exactly a priority.

From here we put the two together:

And finally, we post it to Teams:

And then at 4:50pm it changes to:

Summary

Is this important for anyone? No, I’m fairly sure nobody would find this valuable at all.

It was simply a gimmick that I was playing with, and seeing as I figured it out, I thought I may as well share it.

I’m sure the workflow structure and method could be better, but that really wasn’t the priority here. If you’ve got some suggestions for improvements, let me know.

Otherwise, if you want the Flow to install yourself and can’t get it going from the screenshots – let me know.

And yes, this workflow will continue to run while I’m on holidays, at lunch, listening to music in my car or at any time I’m running Spotify during business hours.

Which for the most part is fine as I’m not embarrassed by my musical taste, which is quite eclectic. However, as I have two young daughters and over time have come to enjoy listening to Taylor Swift, The Spice Girls, Katy Perry, The Wiggles, Big Block Singsong, etc. And there’s been a few times where I’ve played them for my own enjoyment, so it’ll be interesting to see if any of my colleagues comment…

Appendix – JSON schema

{
    “type”: “object”,
    “properties”: {
        “timestamp”: {
            “type”: “integer”
        },
        “context”: {
            “type”: “object”,
            “properties”: {
                “external_urls”: {
                    “type”: “object”,
                    “properties”: {
                        “spotify”: {
                            “type”: “string”
                        }
                    }
                },
                “href”: {
                    “type”: “string”
                },
                “type”: {
                    “type”: “string”
                },
                “uri”: {
                    “type”: “string”
                }
            }
        },
        “progress_ms”: {
            “type”: “integer”
        },
        “item”: {
            “type”: “object”,
            “properties”: {
                “album”: {
                    “type”: “object”,
                    “properties”: {
                        “album_type”: {
                            “type”: “string”
                        },
                        “artists”: {
                            “type”: “array”,
                            “items”: {
                                “type”: “object”,
                                “properties”: {
                                    “external_urls”: {
                                        “type”: “object”,
                                        “properties”: {
                                            “spotify”: {
                                                “type”: “string”
                                            }
                                        }
                                    },
                                    “href”: {
                                        “type”: “string”
                                    },
                                    “id”: {
                                        “type”: “string”
                                    },
                                    “name”: {
                                        “type”: “string”
                                    },
                                    “type”: {
                                        “type”: “string”
                                    },
                                    “uri”: {
                                        “type”: “string”
                                    }
                                },
                                “required”: [
                                    “external_urls”,
                                    “href”,
                                    “id”,
                                    “name”,
                                    “type”,
                                    “uri”
                                ]
                            }
                        },
                        “available_markets”: {
                            “type”: “array”,
                            “items”: {
                                “type”: “string”
                            }
                        },
                        “external_urls”: {
                            “type”: “object”,
                            “properties”: {
                                “spotify”: {
                                    “type”: “string”
                                }
                            }
                        },
                        “href”: {
                            “type”: “string”
                        },
                        “id”: {
                            “type”: “string”
                        },
                        “images”: {
                            “type”: “array”,
                            “items”: {
                                “type”: “object”,
                                “properties”: {
                                    “height”: {
                                        “type”: “integer”
                                    },
                                    “url”: {
                                        “type”: “string”
                                    },
                                    “width”: {
                                        “type”: “integer”
                                    }
                                },
                                “required”: [
                                    “height”,
                                    “url”,
                                    “width”
                                ]
                            }
                        },
                        “name”: {
                            “type”: “string”
                        },
                        “release_date”: {
                            “type”: “string”
                        },
                        “release_date_precision”: {
                            “type”: “string”
                        },
                        “total_tracks”: {
                            “type”: “integer”
                        },
                        “type”: {
                            “type”: “string”
                        },
                        “uri”: {
                            “type”: “string”
                        }
                    }
                },
                “artists”: {
                    “type”: “array”,
                    “items”: {
                        “type”: “object”,
                        “properties”: {
                            “external_urls”: {
                                “type”: “object”,
                                “properties”: {
                                    “spotify”: {
                                        “type”: “string”
                                    }
                                }
                            },
                            “href”: {
                                “type”: “string”
                            },
                            “id”: {
                                “type”: “string”
                            },
                            “name”: {
                                “type”: “string”
                            },
                            “type”: {
                                “type”: “string”
                            },
                            “uri”: {
                                “type”: “string”
                            }
                        },
                        “required”: [
                            “external_urls”,
                            “href”,
                            “id”,
                            “name”,
                            “type”,
                            “uri”
                        ]
                    }
                },
                “available_markets”: {
                    “type”: “array”,
                    “items”: {
                        “type”: “string”
                    }
                },
                “disc_number”: {
                    “type”: “integer”
                },
                “duration_ms”: {
                    “type”: “integer”
                },
                “explicit”: {
                    “type”: “boolean”
                },
                “external_ids”: {
                    “type”: “object”,
                    “properties”: {
                        “isrc”: {
                            “type”: “string”
                        }
                    }
                },
                “external_urls”: {
                    “type”: “object”,
                    “properties”: {
                        “spotify”: {
                            “type”: “string”
                        }
                    }
                },
                “href”: {
                    “type”: “string”
                },
                “id”: {
                    “type”: “string”
                },
                “is_local”: {
                    “type”: “boolean”
                },
                “name”: {
                    “type”: “string”
                },
                “popularity”: {
                    “type”: “integer”
                },
                “preview_url”: {
                    “type”: “string”
                },
                “track_number”: {
                    “type”: “integer”
                },
                “type”: {
                    “type”: “string”
                },
                “uri”: {
                    “type”: “string”
                }
            }
        },
        “currently_playing_type”: {
            “type”: “string”
        },
        “actions”: {
            “type”: “object”,
            “properties”: {
                “disallows”: {
                    “type”: “object”,
                    “properties”: {
                        “resuming”: {
                            “type”: “boolean”
                        },
                        “skipping_prev”: {
                            “type”: “boolean”
                        }
                    }
                }
            }
        },
        “is_playing”: {
            “type”: “boolean”
        }
    }
}

Also published on Medium.

25 comments

  1. Enjoyed enormously following this, and getting it to work (only my second Power Automate effort, and I know no coding), only to find out it violates our admin data policy. Ces’t la vie!

  2. Can you elaborate more on the Parse JSON step, as well as how in “Condition” you were offered “is_playing”? I only have “body”

      1. I ran into trouble with hers as well but largely because I’m still new at this. Luise’s connector must be different than the one you created because I didn’t get the option to configure the Body in the one I created using the directions found here – https://thatapiguy.tech/2019/12/08/spotify-custom-connector-for-power-platform/

        Using your method, I got to the Parse JSON part just like Codi and didn’t know what to put in the Schema section …. and thats where it stopped for me.

  3. Thank you Loryan, for sharing with us!
    I was wondering where did you get the endpoint URL to call in your workflow?

    I wanted to build a background service that would update my status message based on my calendar + adding some comments about when I’m going to be back.
    First thing I wanted to check is how the authentication keys/tokens could be issued and then see the endpoints but I didn’t find any documentation using the URL you provided. Is it kind of internal API that wasn’t supposed to be used by public?

    Thank you!

    1. Which endpoint do you mean? The one for actually updating my status, or getting the data from Spotify?
      If the former – it’s not an officially supported endpoint so use it with a grain of salt.

      1. Hello Loryan, sorry for the confusion
        I was talking about the MS API for updating the status message. It makes sense now, thank you for the clarification!

  4. Hi Loran, for me it’s a loved feature. I used to have similar things in the past with Skype-Spotify or Messenger-Spotify. Now I’ll add this feature as soon as I find time to create the flow. Music is important in my life, so thank you so muuuuch!!!

  5. Loran, I loved this. Honestly, much of it a smidge above my current knowledge, but I’m leading a new team at a new company and would love to implement this for culture-building reasons. I would also LOVE to implement for Apple Music. Thoughts? Is there any “download this flow” option to integrate?

    1. Thanks for the feedback Patrick. At one point this was over my head too, which is why I shared it (as silly as it is). Apple Music has an API, so hopefully you can make it work. https://developer.apple.com/documentation/applemusicapi
      In terms of downloading the flow, I can share the exported version, but you’d still have to build the custom connector manually and probably modify other chunks too.
      I know of several people that have never built a flow before this one, so while I can appreciate that it would seem daunting – it’s certainly possible. Plus it might make for a good group activity. 🙂

      1. Well done, very brave of you to take it on with no prior Power Automate experience. Kudos to you!

  6. Hi there, Loryan! I DO find this so valuable, interesting and useful. I’ll tell you how it works for me as soon as I can try this trick. Thanks for sharing! 🙂

Leave a Reply to Jose Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: