Skip to content

futurice/spotify-hubot

Repository files navigation

Spotify Hubot

This bot listens for all spotify links in Flowdock and adds them to a Spotify playlist.

You need:

  • Heroku account
  • NodeJS 'n stuff
  • Spotify premium account

This bot uses Flowdock adapter. First configure Hubot with its adapters and get it responding to something and then proceed with these instructions:

Copy your Spotify application key to the base of the repository named as spotify_appkey.key. Get application key from here: https://developer.spotify.com/technologies/libspotify/#application-keys (choose binary, not C-code).

Add following environment variables to heroku:

heroku config:add HUBOT_SPOTIFY_APPKEY=`node appkey-to-base64.js`
heroku config:add HUBOT_SPOTIFY_USERNAME=username
heroku config:add HUBOT_SPOTIFY_PASSWORD=password
heroku config:add HUBOT_SPOTIFY_PLAYLIST=spotify:user:myusername:playlist:7sXq7x8V17JIRzYJKw5v9o

Variables explained:

  • HUBOT_SPOTIFY_APPKEY - Spotify application key in base64 format. You can use appkey-to-base64.js tool to convert your key into proper format.
  • HUBOT_SPOTIFY_USERNAME - Spotify username(must be premium account)
  • HUBOT_SPOTIFY_PASSWORD - Spotify password
  • HUBOT_SPOTIFY_PLAYLIST - Spotify playlist URI where all linked tracks are added to.

node-spotify uses libspotify underneath, so you'll need libspotify installed in Heroku. It can be easily added with libspotify buildpack. Also you need nodejs buildback provided by Heroku.

Use this buildpack: https://github.com/ddollar/heroku-buildpack-multi and it will use .buildpacks file to use multiple buildpacks at the same time.

If you want to test locally in OS X, you'll need to install libspotify: brew install libspotify. After that, you can start the bot in local test environment:

export HUBOT_SPOTIFY_APPKEY=`node appkey-to-base64.js`
export HUBOT_SPOTIFY_USERNAME=username
export HUBOT_SPOTIFY_PASSWORD=password
export HUBOT_SPOTIFY_PLAYLIST=spotify:user:myusername:playlist:7sXq7x8V17JIRzYJKw5v9o
./bin/hubot

Hubot in general

This version is designed to be deployed on Heroku. This README was generated for you by hubot to help get you started. Definitely update and improve to talk about your own instance, how to use and deploy, what functionality he has, etc!

Testing Hubot Locally

You can test your hubot by running the following.

% bin/hubot

You'll see some start up output about where your scripts come from and a prompt.

[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading adapter shell
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading scripts from /home/tomb/Development/hubot/scripts
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading scripts from /home/tomb/Development/hubot/src/scripts
Hubot>

Then you can interact with hubot by typing hubot help.

Hubot> hubot help

Hubot> animate me <query> - The same thing as `image me`, except adds a few
convert me <expression> to <units> - Convert expression to given units.
help - Displays all of the help commands that Hubot knows about.
...

Scripting

Take a look at the scripts in the ./scripts folder for examples. Delete any scripts you think are useless or boring. Add whatever functionality you want hubot to have. Read up on what you can do with hubot in the Scripting Guide.

Redis Persistence

If you are going to use the redis-brain.coffee script from hubot-scripts (strongly suggested), you will need to add the Redis to Go addon on Heroku which requires a verified account or you can create an account at Redis to Go and manually set the REDISTOGO_URL variable.

% heroku config:set REDISTOGO_URL="..."

If you don't require any persistence feel free to remove the redis-brain.coffee from hubot-scripts.json and you don't need to worry about redis at all.

Adapters

Adapters are the interface to the service you want your hubot to run on. This can be something like Campfire or IRC. There are a number of third party adapters that the community have contributed. Check Hubot Adapters for the available ones.

If you would like to run a non-Campfire or shell adapter you will need to add the adapter package as a dependency to the package.json file in the dependencies section.

Once you've added the dependency and run npm install to install it you can then run hubot with the adapter.

% bin/hubot -a <adapter>

Where <adapter> is the name of your adapter without the hubot- prefix.

hubot-scripts

There will inevitably be functionality that everyone will want. Instead of adding it to hubot itself, you can submit pull requests to hubot-scripts.

To enable scripts from the hubot-scripts package, add the script name with extension as a double quoted string to the hubot-scripts.json file in this repo.

external-scripts

Tired of waiting for your script to be merged into hubot-scripts? Want to maintain the repository and package yourself? Then this added functionality maybe for you!

Hubot is now able to load scripts from third-party npm packages! To enable this functionality you can follow the following steps.

  1. Add the packages as dependencies into your package.json
  2. npm install to make sure those packages are installed

To enable third-party scripts that you've added you will need to add the package name as a double quoted string to the external-scripts.json file in this repo.

Deployment

% heroku create --stack cedar
% git push heroku master
% heroku ps:scale app=1

If your Heroku account has been verified you can run the following to enable and add the Redis to Go addon to your app.

% heroku addons:add redistogo:nano

If you run into any problems, checkout Heroku's docs.

You'll need to edit the Procfile to set the name of your hubot.

More detailed documentation can be found on the deploying hubot onto Heroku wiki page.

Deploying to UNIX or Windows

If you would like to deploy to either a UNIX operating system or Windows. Please check out the deploying hubot onto UNIX and deploying hubot onto Windows wiki pages.

Restart the bot

You may want to get comfortable with heroku logs and heroku restart if you're having issues.

About

Flowdock bot which adds linked Spotify tracks to a playlist

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published