# Telegram bot

{% hint style="info" %}
[**Puregram**](https://github.com/nitreojs/puregram) **- powerful and modern telegram bot api sdk for node.js and typescript 😁**
{% endhint %}

{% code overflow="wrap" %}
```typescript
import { Telegram } from "puregram";
import { HearManager } from "@puregram/hear";
import { EnkaNetwork } from "enkanetwork";

const bot = new Telegram({
    token: "SOME_SECRET_TOKEN",
});
const hearManager = new HearManager();
const enka = new EnkaNetwork();
const UID_REGEXP = /([1,2,5-9])\d{8}/;

bot.updates.on("message", hearManager.middleware);

// if message.text contains UID
hearManager.hear(UID_REGEXP, async (context) => {
    const user = await enka.fetchUser(context.text); // we will not invent the choice of language

    return context.send(
        `${user.player.nickname}'s characters list:\n\n` +
            user.characters
                .map(
                    (character) =>
                        `${character.name} (${character.rarity} ⭐) - ${character.level} level`
                )
                .join("\n")
    );
});

// else
bot.updates.on("message", (context) =>
    context.send(
        `Hi, ${context.from.firstName}! Write your uid from the Genshin Impact correctly`
    )
);

bot.updates.startPolling().then(() => console.log("[BOT] Bot was started"));

```
{% endcode %}

<figure><img src="https://129309102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHRuRVaMzLuUsL0mMhv72%2Fuploads%2FnL4WL71yBZYlY7R4N2GU%2Fimage.png?alt=media&#x26;token=f56e13da-6214-4581-8a3f-eb749c65ab90" alt=""><figcaption></figcaption></figure>
