4️⃣Telegram bot
Puregram - 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"));
Last updated