Join us on Discord https://discord.gg/4AA2DqWpVc
A simple nodejs wrapper for the turntable API.
You'll need to find your AUTH
, USERID
and ROOMID
information with this bookmarklet.
Ttapi is also available in Python and Ruby.
See also turntabler (Ruby) maintained by obrie.
npm install ttapi
This bot responds to anybody who writes "/hello" in the chat.
var Bot = require('ttapi');
var bot = new Bot(AUTH, USERID, ROOMID);
bot.on('speak', function (data) {
// Respond to "/hello" command
if (data.text.match(/^\/hello$/)) {
bot.speak('Hey! How are you @'+data.name+' ?');
}
});
This bot logs the room activity in the console.
var Bot = require('ttapi');
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var USERID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var ROOMID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var bot = new Bot(AUTH, USERID);
bot.on('ready', function (data) { bot.roomRegister(ROOMID); });
bot.on('roomChanged', function (data) { console.log('The bot has changed room.', data); });
bot.on('speak', function (data) { console.log('Someone has spoken', data); });
bot.on('update_votes', function (data) { console.log('Someone has voted', data); });
bot.on('registered', function (data) { console.log('Someone registered', data); });
REPL allows you to dynamically call the bot functions and modify his variables during his execution.
var Bot = require('ttapi')
, repl = require('repl');
var bot = new Bot(AUTH, USERID, ROOMID);
repl.start('> ').context.bot = bot;
// ...
bot.debug = true;
That will print on the terminal all the data that you get and all the data that you send.
Here are some examples of the data that you'll receive from those events.
Triggered when the bot is connected. Do not attempt to use any actions until you receive this event.
Triggered when attempting to connect using an invalid roomid.
If you do not handle this event, your bot will stop running when this error occurs.
Triggered on recoverable connection errors.
If you do not handle this event, an error
event will be triggered when the connection to Turntable is lost.
Triggered when a socket opens a connection.
Triggered when the bot receives a TCP message.
Triggered when a socket closes its connection.
Triggered when the bot receives an HTTP request.
Triggered when the bot enters a room.
Triggered when a user enters the room.
Triggered when a user leaves the room.
Triggered when a new message is sent via the chat.
Triggered at the end of the song. (Just before the newsong/nosong event)
The data returned by this event contains information about the song that has just ended.
Triggered when a new song starts.
Triggered when there is no song.
Triggered when a user votes.
The userid is provided only if the user votes up, or later changes their mind and votes down.
Triggered when a user gets booted.
Triggered when a user updates their name/profile.
Triggered when a user takes a dj spot.
Triggered when a user leaves a dj spot.
Triggered when a user is escorted off the stage.
Triggered when a user is promoted to a moderator.
Triggered when a user loses their moderator title.
Triggered when a user queues the currently playing song.
Triggered when the bot receives a private message.
Start a TCP server.
Start an HTTP server.
Get the Turntable server time.
Get 20 rooms.
Search the directory for rooms.
limit
- The number of rooms to returnquery
- Filter based on this search termGet the location of your friends/idols.
Get a directory of rooms.
limit
- The number of rooms to returnsection_aware
sort
- What to sort by,skip
- The number of rooms to skipGet the location of a user. If allInformation
is true
, you'll also receive the information about the room and the user.
This function will make you become a fan of the user.
Get your favorite rooms.
Add a room to your favorite rooms.
Remove a room from your favorite rooms.
Register in a room.
Deregister from the current room.
Get the current room information. Do not include song log if 'extended' is false.
Broadcast a message in the chat.
Boot a user.
Alias of bootUser()
.
Add a moderator.
Remove a moderator. (Note the person does NOT have to be in the room to remove their moderator status.)
Add yourself as a DJ.
Remove the specified DJ, or yourself if not specified.
Stop the currently playing song. You must be a moderator to stop playing someone else's song.
Alias of stopSong()
.
Vote for the current song.
Alias of vote('up')
.
Authenticate the user.
Get the current user's information.
Get all available avatars.
Get the avatar ids that you can currently use.
Get the list of everyone the specified userid is a fan of, or the list of everyone you are a fan of if a userid is not specified.
Get the list of everyone who is a fan of the specified userid, or the list of everyone who is your fan if a userid is not specified.
bot.getFans(function (data) { console.log(data); });
// { msgid: 7, fans: [ '4e69c14e4fe7d00e7303cd6d', ... ], success: true }
Get a user's id by their name.
bot.getUserId('@alain_gilbert', function (data) { console.log(data); });
// { msgid: 12, userid: '4deadb0f4fe7d013dc0555f1', success: true }
Get presence for the specified user, or your presence if a userid is not specified.
Get the profile for the specified user, or your profile if a userid is not specified.
Modify your profile. Any missing properties from the 'profile' object will be replaced with the current values.
profile
:obj (required)
name
:string (optional)twitter
:string (optional)soundcloud
:string (optional)facebook
:string (optional)website
:string (optional)about
:string (optional)topartists
:string (optional)hangout
:string (optional)callback
:fn (optional)bot.modifyProfile({ website:'http://ttdashboard.com/', about:'My bot.' }, callback);
Modify your laptop.
Modify your name.
Set your avatar.
Fan someone.
Unfan someone.
Trigger the heart animation used to show that you've snagged the currently playing song.
This function will not add the song into the queue. Use .playlistAdd
to queue the song, and if successful, then use .snag
to trigger the animation.
Send a private message.
Get the private conversation history.
Set your current status.
Set the user to be considered a bot. This puts the user under the "Bots" group in the room list. A good place to run this command is in the callback to .roomRegister
.
bot.roomRegister(roomid, function() {
bot.setAsBot();
});
List all your playlists.
Create a new playlist.
playlistName
(required)callback
(optional)bot.playlistCreate(newPlaylistName)
bot.playlistCreate(newPlaylistName, callback)
Delete a playlist.
playlistName
(required)callback
(optional)bot.playlistDelete(playlistName)
bot.playlistDelete(paylistName, callback)
Rename a playlist.
oldPlaylistName
(required)newPlaylistName
(required)callback
(optional)bot.playlistRename(oldPlaylistName, newPlaylistName)
bot.playlistRename(oldPlaylistName, newPlaylistName, callback)
Switch to another playlist.
playlistName
(required)callback
(optional)bot.playlistSwitch(playlistName)
bot.playlistSwitch(playlistName, callback)
Get all information about a playlist.
playlistName
(optional) default: default
callback
(required)bot.playlistAll(callback);
bot.playlistAll(playlistName, callback);
Add a song to a playlist.
playlistName
(optional) default: default
songId
(required)index
(optional) default: 0
callback
(optional)bot.playlistAdd(songId);
bot.playlistAdd(songId, idx);
bot.playlistAdd(songId, callback);
bot.playlistAdd(songId, idx, callback);
bot.playlistAdd(playlistName, songId, idx);
bot.playlistAdd(playlistName, songId, callback);
bot.playlistAdd(playlistName, songId, idx, callback);
bot.playlistAdd(false, songId, callback); // Backward compatibility
bot.playlistAdd(false, songId); // Backward compatibility
Remove a song on a playlist.
playlistName
(optional) default: default
index
(optional) default: 0
callback
(optional)bot.playlistRemove();
bot.playlistRemove(index);
bot.playlistRemove(index, callback);
bot.playlistRemove(playlistName, index);
bot.playlistRemove(playlistName, index, callback);
Reorder a playlist. Take the song at index indexFrom
and move it to index indexTo
.
playlistName
(optional) default: default
indexFrom
(required) default: 0
indexTo
(required) default: 0
callback
(optional)bot.playlistReorder(indexFrom, indexTo);
bot.playlistReorder(indexFrom, indexTo, callback);
bot.playlistReorder(playlistName, indexFrom, indexTo);
bot.playlistReorder(playlistName, indexFrom, indexTo, callback);
Search for songs.
query
callback
bot.searchSong(query, callback);
Get all stickers information.
bot.getStickers(function (data) { console.log(data); });
// https://github.com/alaingilbert/Turntable-API/blob/master/turntable_data/getstickers.js
Get the information about a user's stickers.
bot.getStickerPlacements('4e0889d4a3f7517d1100af78', function (data) { console.log(data); });
// https://github.com/alaingilbert/Turntable-API/blob/master/turntable_data/getstickerplacements.js
Sets your sticker placements. The placements object is formatted the same as the placements object retrieved in the getStickerPlacements callback.
var placements = [{
top: 126,
angle: -23.325931577,
sticker_id: '4f86fe84e77989117e000008',
left: 78
}];
bot.placeStickers(placements);