# Getting started

## Installation

Install emoteTTV using you favorite package manager:

```bash
$ npm install emotettv
```

Then, you can import emoteTTV like this:

```typescript
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:

```typescript
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:

```typescript
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:

<figure><img src="/files/S1ilBnptkOB36uoFXuzL" alt="" width="140"><figcaption></figcaption></figure>

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](#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()`](/emotettv/api-reference/parseemotes.md) 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](http://tmijs.com) library. Luckily, emoteTTV is designed to easily integrate with it:

{% content-ref url="/pages/Vzf28Edn1kLuian4tgsk" %}
[Usage with TMI.js](/emotettv/usage/usage-with-tmi.js.md)
{% endcontent-ref %}

## 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()`](/emotettv/api-reference/reloadbadges.md) or [`reloadEmotes()`](/emotettv/api-reference/reloademotes.md) .


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emotettv.gitbook.io/emotettv/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
