enkaNetwork
GitHubNPM
  • ✨Overview
  • 📦Quick Start | Installation
  • 🖇️TypeScript usage
  • ⚙️Class description
    • 📝EnkaNetwork
    • 💾AssetsUpdater
    • 🔎AssetsFinder
  • 🔗Methods
    • 👤fetchUser
    • 🕵️fetchProfileInfo
    • 🌟fetchEnkaProfile
    • 📕fetchEnkaHoyos
    • 🔹fetchEnkaHoyo
    • 🟣fetchEnkaHoyoBuilds
    • 🚩setLanguage
  • 🎓Models
    • EnkaProfile
    • Character
      • Character
      • CharacterConstellation
      • CharacterReliquary
      • CharacterSkill
      • CharacterStats
      • CharacterWeapon
    • PlayerInfo
      • CharacterPreview
      • Namecard
      • PlayerInfo
      • ProfilePicture
    • Fetcher
      • FetchEnkaHoyosBuilds
      • FetchEnkaHoyo
      • FetchEnkaProfile
      • FetchUserUID
      • FetchProfileInfo
  • ✏️Examples
    • 1️⃣Simple usage
    • 2️⃣Express API
    • 3️⃣Fastify API
    • 4️⃣Telegram bot
Powered by GitBook
On this page

Was this helpful?

  1. Examples

Telegram bot

PreviousFastify API

Last updated 1 year ago

Was this helpful?

- powerful and modern telegram bot api sdk for node.js and 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"));
✏️
4️⃣
Puregram