TAPIC

Twitch API & Chat in javascript.
Source:
Version:
  • 5.0.1
Author:
  • Skhmt
License:
  • MIT

Methods

(inner) emit(eventName, eventDetail)

Source:
Emits an event.
Parameters:
Name Type Description
eventName string The name of the event.
eventDetail any The parameter to send the callback.

(inner) findID(username, callback)

Source:
Takes in a username (or channel name, same thing) and returns the user's ID
Parameters:
Name Type Description
username string The username to check.
callback string The user/channel id.

(inner) getChannel() → {string}

Source:
Gets the channel name.
Returns:
The channel name in lowercase.
Type
string

(inner) getChannelID() → {string}

Source:
Gets the channel id.
Returns:
The channel id.
Type
string

(inner) getChatters() → {object}

Source:
Gets the current chatters in the channel. The returned object has 5 arrays: moderators, staff, admins, global_mods, and viewers. The arrays are simple lists of the viewers that belong to each category.
Returns:
An object of arrays.
Type
object

(inner) getClientID() → {string}

Source:
Gets the client id.
Returns:
The client id
Type
string

(inner) getColor() → {string}

Source:
Gets the user's color preference for their username in chat. The format is hex and includes the leading #.
Returns:
Color of the username.
Type
string

(inner) getCommunityDescription() → {string}

Source:
Gets the community description in markdown.
Returns:
Description of the community
Type
string

(inner) getCommunityDescriptionHTML() → {string}

Source:
Gets the community description in HTML.
Returns:
Description of the community
Type
string

(inner) getCommunityName() → {string}

Source:
Gets the community name.
Returns:
Name of the community
Type
string

(inner) getCommunityRules() → {string}

Source:
Gets the community rules in markdown.
Returns:
Rules of the community
Type
string

(inner) getCommunityRulesHTML() → {string}

Source:
Gets the community rules in HTML.
Returns:
Rules of the community
Type
string

(inner) getCommunitySummary() → {string}

Source:
Gets the community summary in plaintext.
Returns:
Summary of the community
Type
string

(inner) getCreatedAt() → {string}

Source:
Gets the time the stream started in the W3C date and time format, in UTC. ex: 2014-09-20T21:00:43Z
Returns:
The time the stream started.
Type
string

(inner) getCurrentViewCount() → {number}

Source:
Gets the number of current logged-in viewers of the channel.
Returns:
The current number of logged-in viewers.
Type
number

(inner) getDelay() → {number}

Source:
Gets the delay of the channel. This doesn't return the actual delay, just the intentionally added delay.
Returns:
The delay in seconds.
Type
number

(inner) getDisplayName() → {string}

Source:
Gets the display name of the user. This includes capitalization preferences.
Returns:
The display name of the user.
Type
string

(inner) getEmoteSets() → {string}

Source:
Gets the user's emote set in comma-delimited format.
Returns:
List of the user's emote sets.
Type
string

(inner) getFollowerCount() → {number}

Source:
Gets the number of followers of the channel.
Returns:
The follower count.
Type
number

(inner) getFps() → {number}

Source:
Gets the channel's frames per second - generally 30 or 60.
Returns:
The FPS of the channel.
Type
number

(inner) getGame() → {string}

Source:
Gets the game being played according to the channel owner. This works even if the channel is offline.
Returns:
The game.
Type
string
Source:
Gets the channel's 300x300px logo URL.
Returns:
The URL of the channel's logo.
Type
string

(inner) getMod() → {boolean}

Source:
Gets the moderator status of the user in the channel.
Returns:
True if a moderator, false if not.
Type
boolean

(inner) getOauth() → {string}

Source:
Gets the user's oauth token.
Returns:
User's oauth token
Type
string

(inner) getPreview() → {string}

Source:
Gets the stream preview if live.
Returns:
640x360 .jpg url
Type
string

(inner) getProfileBanner() → {string}

Source:
Gets the channel's profile banner URL.
Returns:
The URL of the channel's profile banner.
Type
string

(inner) getStatus() → {string}

Source:
Gets the status (title) of the channel. This works even if the channel is offline.
Returns:
The status.
Type
string

(inner) getSub() → {boolean}

Source:
Gets the subscriber status of the tapic user in the channel.
Returns:
True if a subscriber, false if not.
Type
boolean

(inner) getSubBadgeUrl() → {string}

Source:
Gets the URL of the subscriber badge displayed to the left of the username in chat if the channel is partnered.
Returns:
The URL of the sub badge.
Type
string

(inner) getTapicUptime() → {object}

Source:
Gets the uptime that TAPIC has been running. This is not the stream's uptime.
Returns:
"total" is the total uptime in miliseconds, if you want to parse it yourself. "hours", "minutes", and "seconds" are integers meant to be used together.
Type
object

(inner) getTeamDisplayName() → {string}

Source:
Gets the channel's team (display) name. This is meant to be shown to user(s).
Returns:
Team (display) name
Type
string

(inner) getTeamName() → {string}

Source:
Gets the channel's team name. This is mostly used to get more information via the twitchapi.
Returns:
Team name
Type
string

(inner) getTotalViewCount() → {number}

Source:
Gets the total (cumulative) viewer count of the channel.
Returns:
The total number of viewers.
Type
number

(inner) getTurbo() → {boolean}

Source:
Gets the turbo status of the user.
Returns:
True if turbo, false if not.
Type
boolean

(inner) getUserID() → {string}

Source:
Gets the user's id.
Returns:
The user id.
Type
string

(inner) getUsername() → {string}

Source:
Gets the username of the bot.
Returns:
The lowercase username.
Type
string

(inner) getUserType() → {string}

Source:
Gets the user's usertype. For example, "staff".
Returns:
User's user type.
Type
string

(inner) getVideoBanner() → {string}

Source:
Gets the channel's offline video banner/image URL.
Returns:
The URL of the channel's offline image.
Type
string

(inner) getVideoHeight() → {number}

Source:
Gets the height in pixels of the video. This is often 480, 720, or 1080.
Returns:
The height in pixels of the stream.
Type
number

(inner) isFollowing(user, channel, callback)

Source:
Checks if "user" is following "channel". This is an asynchronous function and requires a callback.
Parameters:
Name Type Description
user string The user id to check.
channel string The channel id to check.
callback function The function that's called when the check is complete. Callback is given an object with isFollowing (boolean) and dateFollowed (string).

(inner) isOnline() → {boolean}

Source:
Gets the online status of the channel.
Returns:
True if the channel is streaming, false if not.
Type
boolean

(inner) isPartner() → {boolean}

Source:
Gets the partner status of the channel.
Returns:
Returns true if the channel is a Twitch partner, false if not.
Type
boolean

(inner) isSubscribing(user, callback)

Source:
Checks if "user" is subscribed to the current channel. This is an asynchronous function and requires a callback. Requires the channel_check_subscription permission and the username and channel must be the same.
Parameters:
Name Type Description
user string The user id to check.
callback function The function that's called when the check is complete. Callback is given an object with isSubscribing (boolean), dateSubscribed (string), sub_plan (string), and sub_plan_name (string).

(inner) joinChannel(channel, callback)

Source:
Joins a new channel. If you were already in a channel, this exits you from that channel first, then joins the new one.
Parameters:
Name Type Description
channel string The channel name, with or without the #.
callback function Optional callback that's triggered after the Twitch API has been polled for the first time after joining.

(inner) joinCommunity(community)

Source:
Joins the channel to a community
Parameters:
Name Type Description
community string The community NAME

(inner) kraken(path, params, callback)

Source:
Uses tapic.js to do calls to the twitchapi that aren't supported by default at https://api.twitch.tv/kraken/... Example: TAPIC.kraken('games/top/', '&limit=100&offset=0', function (response) {...});
Parameters:
Name Type Description
path string The url to after "/kraken/"
params string Optional. Query parameters in the format of "&___=___&___=___ ...".
callback function Callback function is given the response object, see https://dev.twitch.tv/docs for specific info

(inner) leaveCommunity()

Source:
Removes the channel from its current community.

(inner) listen(eventName, callback)

Source:
Listens for certain events, then runs the callback.
Parameters:
Name Type Description
eventName string The name of the event.
callback function What do do when the event happens.

(inner) runCommercial(length)

Source:
Runs a commercial. Requires channel_commercial permission and the user must be an editor of the channel or the username must be the same as the channel. Commercials usually run for 30 seconds.
Parameters:
Name Type Description
length number Amount of time to run the commercial in seconds.

(inner) sendChat(message)

Source:
Sends a message to the channel. Actions such as /me, /host, etc work as normal. This is echoed back to the client if you listen for the "echoChat" event.
Parameters:
Name Type Description
message string The message to send.

(inner) sendWhisper(user, message)

Source:
Sends a whisper to a user. This is echoed back to the client if you listen for the "echoWhisper" event.
Parameters:
Name Type Description
user string The target user to send the whisper to.
message string The message to send.

(inner) setRefreshRate(refreshRate)

Source:
Sets the rate at which tapic pings the Twitch API, by default it's 5
Parameters:
Name Type Description
refreshRate number in seconds

(inner) setStatusGame(status, game)

Source:
Sets the status and game of the channel. Requires channel_editor permission.
Parameters:
Name Type Description
status string The status/title of the channel.
game string The game being played, or Creative or Music or whatever.

(inner) setup(oauth, callback)

Source:
Sets the oauth, then opens a chat connection and starts polling the Twitch API for data. This needs to be done before joining a channel.
Parameters:
Name Type Description
oauth string Your user's oauth token. See: https://github.com/justintv/Twitch-API/blob/master/authentication.md for instructions on how to do that.
callback function Calls back the username when TAPIC has successfully connected to Twitch.

Events

bits

Source:
Properties:
Name Type Description
message_id string Message ID
message_type string Message type (that is, the type of object contained in the data field)
version string Message version
data.badge_entitlement object Information about the user’s new badge level (.new_version and .previous_version), if the user reached a new badge level with this cheer; otherwise. null.
data.bits_used number Number of bits used.
data.channel_id string User ID of the channel on which bits were used.
data.channel_name string Name of the channel on which bits were used.
data.chat_message string Chat message sent with the cheer.
data.context string Event type associated with this use of bits (for example, cheer).
data.time string Time when the bits were used. RFC 3339 format.
data.total_bits_used number All-time total number of bits used on this channel by the specified user.
data.user_id string User ID of the person who used the bits.
data.user_name string Login name of the person who used the bits.
Bit tip notification. Via PubSub.

clearChat

Source:
This is sent when a moderator wants to purge all of the chat. The default action should be to remove or hide all of the previous chatroom text.

clearUser

Source:
Properties:
Name Type Description
name string The cleared user's name.
reason string The optional reason for timeout.
duration number The length of the timeout in seconds.
This is sent when a user is timed out or banned or "purged" by a moderator. The default action should be to remove or hide all of that user's previous chat text.

dev

Source:
Properties:
Name Type Description
message string the message
Dev status events sent by TAPIC. All errors are sent to the console, this is strictly for non-errors. This will never probably have full coverage and is intended for use when modifying TAPIC.js itself. Therefore, probably don't listen to this topic in production. Or at all.

echoChat

Source:
Properties:
Type Description
string The text of the chat message.
Echos chat messages sent by the bot to the chatroom.

echoWhisper

Source:
Properties:
Name Type Description
to string The target of the whisper.
text string The text of the whisper.
Echos whispers sent by the bot.

follow

Source:
Properties:
Type Description
string The user that followed the channel.
This is sent when a user follows the channel. The limitation is about 100 follows per minute. Any more might get lost.

host

Source:
Properties:
Type Description
string The user that hosted you.
This is sent when the user (not the channel) is hosted. If the logged in user is not the broadcaster, this will not be an accurate notification of hosts. To get host notifications if you're not logged in as the broadcaster, you need to use: http://tmi.twitch.tv/hosts?include_logins=1&target=[user id number] (Won't work on a client-side browser - no CORS/JSONP support) or https://decapi.me/twitch/hosts?channel=[channel name] (CORS support. Thanks Decicus)

join

Source:
Properties:
Type Description
string The entering user's name.
When a user joins your channel. Fires for every user in the channel when you enter, so be careful on how you use this. This doesn't seem to be real-time, unlike real IRC.

message

Source:
Properties:
Name Type Description
from string The username of the person who sent the message.
text string The text of the message.
color string The color of the user name.
emotes string The emote id and character locations. See: https://github.com/justintv/Twitch-API/blob/master/IRC.md#privmsg.
action boolean True if it is an action (/me), false if it is a regular message.
streamer boolean True if the streamer (channel name) sent the message, false if it is anyone else.
mod boolean True if the user that sent the message is a moderator, false if not.
sub boolean True if the user that sent the message is a subscriber, false if not.
turbo boolean True if the user that sent the message has turbo, false if not.
badges array Array of badges, such as 'broadcaster/1', 'subscriber/1', and 'warcraft/alliance'.
room_id number The chatroom ID of the room the message was sent to.
user_id number The Twitch ID number of the user that sent the message.
A regular message (PRIVMSG in IRC). This includes actions (/me).

moderation

Source:
Properties:
Name Type Description
type string should be "chat_login_moderation"
moderation_action string "timeout", "ban", etc
args array -
created_by string -
Moderation actions. Via PubSub. Unsupported - may not work.

notice

Source:
Properties:
Type Description
string The notice.
Notices from the standard chat server. For example, the response of the /mods command.

part

Source:
Properties:
Type Description
string The parting user's name.
When a user leaves your channel. This doesn't seem to be real-time, unlike real IRC.

raw

Source:
Properties:
Type Description
string The raw message
Every RAW TMI message from the standard chat server. You most likely won't be using this unless you need to parse for something that TAPIC.js doesn't already have a listener for.

roomstate

Source:
Properties:
Name Type Description
lang string The language of the room. Often left blank.
r9k boolean True if the room is in r9k mode, false if not.
slow boolean True if the room is in slow mode, false if not.
subs_only boolean True if the room is in subs (and mods) only mode, false if not.
The roomstate options set on a room.

sub

Source:
Properties:
Name Type Description
name string The user that subscribed to the channel.
user_id number User's unique twitch id number.
user_type string User's type. For example: staff.
room_id number Twitch id of the room being sub'd to.
months number Number of months subscribed for.
resub boolean True if a resub, false if a new subscriber.
plan string Possible values are: "Prime", "1000", "2000", or "3000".
planName string Name of the plan.
sysMsg string What the system normally outputs, usually: "TWITCH_UserName\shas\ssubscribed\sfor\s6\smonths!".
joinedText string Message the user wants to include with the sub.
Subscription notification. These only show up if the user decides to share their sub/resub.

update

Source:
This is sent when the app state has been updated with the latest Twitch API data. That doesn't necessarilly mean the data is different, only that it's the most recent data.

whisper

Source:
Properties:
Name Type Description
from string The username of the person who sent the message.
to string The recipient of the whisper (the bot name).
text string The text of the message.
color string The color of the user name.
turbo boolean True if the user that sent the message has turbo, false if not.
badges array Array of badges, such as 'broadcaster/1', 'subscriber/1', and 'warcraft/alliance'.
message_id number The message id.
thread_id number The thread id.
user_id number The user id.
A whisper sent to the user.