Search music and play to Spotify from Telegram.

This workflow is a simple demonstration on accessing a message model from Telegram, making searching for songs an easy task even if you can’t remember the artist or song name.

An OpenAI message model tries to figure out the song and sends it to an active Spotify device.

Use case
Imagine an office where you play music in the background and the employees can control the music without having to log in to the playing account.

How it works
1. You describe the song in Telegram.
2. The Telegram bot sends the text to n8n.
3. An OpenAI message model tries to find the song.
4. Spotify gets the search query string.
5. The first match is then added to the queue.
– If there is no match, a message is sent to Telegram and the process ends.
6. We change to the next track in the list.
7. We make sure the song starts playing by trying to resume.
8. We fetch the currently playing track.
9. We return “now playing” information to Telegram: Song Name – Artist Name – Album Name.

Error handling
Every Spotify step has its own error handler under settings where we output the error. The message parser receives the error and sends it to Telegram.

Requirements
– Active workflow
– OpenAI API key
– Telegram bot
– Spotify account and Oauth2 API
– Spotify active on a device

The Telegram trigger is activated only if this workflow is active. You can, however, TEST the workflow in the editor by clicking “Test step” and then it waits for the Telegram event. When the event is received, just step through all steps or click “Test step” on the “Fetch Now Playing” node.

You must have a Spotify device active when trying to communicate with a device. Open Spotify and play something — not it is active.