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.
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.
All text commands accept the text either as an argument (/ai привет) or by
replying to a message.
| Command | What it does |
|---|---|
/t | Fixes wrong keyboard layout (RU↔EN transliteration), shows original struck-through |
/ai | Asks Groq for an assistant reply (in Russian) |
/argue | Generates aggressive counterarguments to the target message |
/google, /g | Returns a Google search link for the text |
/current_map, /cm | Apex Legends map rotation (ranked default, battle_royale/br, ltm) |
- Create a bot via @BotFather and grab the token.
- Set the environment variables below.
- The webhook registers itself automatically on the first request to the HTTP endpoint (open the val's URL once, or just message the bot).
| Key | Required | Description |
|---|---|---|
TELEGRAM_TOKEN | yes | Bot token from @BotFather |
GROQ_API_KEY | yes | Groq API key (for /ai and /argue) |
MOZAMBIQUE_API_KEY | yes | mozambiquehe.re key (for /current_map) |
GROQ_MODEL | no | Defaults to deepseek-r1-distill-llama-70b |
ALLOWED_GROUPS | no | Comma/space-separated negative group chat IDs the bot replies in |
TARGET_ACCOUNTS | no | Comma/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
Rendering mermaid diagram...
main.ts— HTTP webhook handler + grammY command wiringconfig.ts— env var parsing/validation (was the pydanticSettings)keyboard.ts— RU↔EN keyboard-layout transliterationllm.ts— Groq chat helpers (replaces LangChainChatGroq)maprotation.ts— Apex map rotation lookup
- 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.tsusesnpm:openaipointed athttps://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).