Public
funny & usefull tg bot
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

kontrtem

A Telegram group bot, ported from Python (aiogram + LangChain) to TypeScript on Val Town (Deno + grammY). It only responds inside a configured allowlist of groups.

Commands

All text commands accept the text either as an argument (/ai привет) or by replying to a message.

CommandWhat it does
/tFixes wrong keyboard layout (RU↔EN transliteration), shows original struck-through
/aiAsks Groq for an assistant reply (in Russian)
/argueGenerates aggressive counterarguments to the target message
/google, /gReturns a Google search link for the text
/current_map, /cmApex Legends map rotation (ranked default, battle_royale/br, ltm)

Setup

  1. Create a bot via @BotFather and grab the token.
  2. Set the environment variables below.
  3. The webhook registers itself automatically on the first request to the HTTP endpoint (open the val's URL once, or just message the bot).

Environment variables

KeyRequiredDescription
TELEGRAM_TOKENyesBot token from @BotFather
GROQ_API_KEYyesGroq API key (for /ai and /argue)
MOZAMBIQUE_API_KEYyesmozambiquehe.re key (for /current_map)
GROQ_MODELnoDefaults to deepseek-r1-distill-llama-70b
ALLOWED_GROUPSnoComma/space-separated negative group chat IDs the bot replies in
TARGET_ACCOUNTSnoComma/space-separated positive user IDs that get the extra /argue jab

👉 Add TELEGRAM_TOKEN here: https://www.val.town/x/xflammm/kontrtem/environment-variables?key=TELEGRAM_TOKEN

👉 Add GROQ_API_KEY here: https://www.val.town/x/xflammm/kontrtem/environment-variables?key=GROQ_API_KEY

👉 Add MOZAMBIQUE_API_KEY here: https://www.val.town/x/xflammm/kontrtem/environment-variables?key=MOZAMBIQUE_API_KEY

👉 Add ALLOWED_GROUPS here: https://www.val.town/x/xflammm/kontrtem/environment-variables?key=ALLOWED_GROUPS

Architecture

Rendering mermaid diagram...

Files

  • main.ts — HTTP webhook handler + grammY command wiring
  • config.ts — env var parsing/validation (was the pydantic Settings)
  • keyboard.ts — RU↔EN keyboard-layout transliteration
  • llm.ts — Groq chat helpers (replaces LangChain ChatGroq)
  • maprotation.ts — Apex map rotation lookup

Notes on the port

  • aiogram → grammY: middleware, command handlers, and reply-to logic map over directly. Long polling is replaced by a self-registering webhook, which is how bots run on Val Town.
  • LangChain + ChatGroq → OpenAI SDK: Groq exposes an OpenAI-compatible API, so llm.ts uses npm:openai pointed at https://api.groq.com/openai/v1. The <think>…</think> stripping for deepseek-r1 is preserved.
  • pydantic → plain validation in config.ts (positive target accounts, negative group IDs).