Getting started

Installation

Install emoteTTV using you favorite package manager:

$ npm install emotettv

Then, you can import emoteTTV like this:

import { parseBadges, parseEmotes } from "emotettv";

Basic usage

You can use emoteTTV to parse any messages you want and then convert the results to the format that better suits you. For example, let's parse a sample message and get an array to see how it works:

import { parseEmotes } from "emotettv";

const message = await parseEmotes("Hello emotettv! D:");
console.log(message.toArray());
// > [{…}, {…}, {…}]

This will return an array of words and emotes to be handled however you want. Notice this only replaces global third party emotes, as we didn't specify a Twitch channel and didn't pass the Twitch emote offsets that the Twitch IRC gives us (we'll see more about that later).

Also, if we just want to simply render the message with emotes, handling an array of words can be tiring. So instead of .toArray() let's use .toHTML() to render the message on the document body:

import { parseEmotes } from "emotettv";

const message = await parseEmotes(
  "thats sick!! PogChamp",
  { "305954156": ["13-20"] },
  { channelId: "98776633" }
);
document.body.innerHTML = message.toHTML();

This should render something like this:

Notice the second parameter is an object map with the positions of each emote in our message. This is provided by the Twitch IRC when a message comes in and you shouldn't need to write this manually as we'll se on real-world usage of emoteTTV.

We also added a third parameter with the ID of the channel we want to parse the emotes. This is so the library can load the channel emotes from third party providers. You can check all the params and options available on the parseEmotes() API reference.

Real-world usage

Now, if you want to parse real messages, you'll need to connect to a channel chat using the Twitch IRC. For this, you can use TMI.js library. Luckily, emoteTTV is designed to easily integrate with it:

Core concepts

At this point, you might have noticed that you don't need to instantiate emoteTTV like you would with other parser libraries — you can use it right away. This is because emoteTTV works as a singleton, we have a single instance of the parser and we manage everything internally.

For example, emoteTTV will automatically load all the needed emotes and badges on the first call and store them for the next calls. If you decide to parse a message of a different channel, it will share all the global data instead of loading them again and storing duplicates. If you ever need to reload data, you can call reloadBadges() or reloadEmotes() .

Last updated