Official source repository for TBL (Tele Bot Language) helper libraries on TeleBotHost.
This repo holds the library code and documentation. On the TBL platform, built-in libraries are exposed as Libs.<name> — you do not upload or manage a Libs/ folder in your bot.
Version 1.0.0 (pre-release).
There are two separate paths:
Official libs (Libs.xx) |
Your own custom libs | |
|---|---|---|
| Source | This repo → deployed by TBL | Your bot commands |
| Access | Libs.random, Libs.refLib, … |
require("commandname") |
| Who can add | TBL platform (from this repo) | You, in your bot |
| Folder upload | Not possible — no Libs/ folder on bots |
Not needed |
Built-in libraries load lazily on the platform. Use them directly in any command Logic:
Libs.random.randomInt(1, 6)
await Libs.refLib.count()
Libs.tgutil.getNameFor(user)Names are case-sensitive (Libs.tgutil works; Libs.TgUtil does not).
In examples, Bot.sendMessage(text, options?) sends to the current chat — text first, options second.
You cannot add files to a Libs/ folder on TBL. To develop or test your own library:
- Create a command (e.g.
/testlibor a hidden command namedtestlib). - Paste the library code into that command’s Logic field — the full
.jsbody ending withmodule.exports = { ... }. - Load it from another command with
require():
let mylib = require("testlib")
let roll = mylib.randomInt(1, 6)
await mylib.doSomething(user.id)The string passed to require() is the command name, not a file path.
Logic field of command testlib (library only — no bot replies needed):
const mylib = {
randomInt: function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
greet: async function(name) {
await Bot.sendMessage("Hello " + name)
}
};
module.exports = mylib;let game = require("testlib")
let roll = game.randomInt(1, 6)
Bot.sendMessage("You rolled: " + roll)Use this pattern to prototype libs from this repo (under_dev/, or your own code) before contributing them as official Libs.* entries.
| Library | Access | Type | Purpose |
|---|---|---|---|
random |
Libs.random |
Sync | Numbers, strings, distributions, test data |
dateTimeFormat |
Libs.dateTimeFormat |
Sync | Formatting, arithmetic, locales, relative time |
tgutil |
Libs.tgutil |
Sync | Names, mentions, escaping, WebApp helpers |
mcl |
Libs.mcl |
Async | Channel membership checks and join buttons |
ResourcesLibv2 |
Libs.ResourcesLibv2 |
Async | Economy, inventories, growth, transfers |
refLib |
Libs.refLib |
Async | Referral links, tracking, leaderboard |
translate |
Libs.translate |
Async | Multi-language translation with provider fallback |
cooldown |
Libs.cooldown |
Async | Per-user and global cooldown timers |
ResourcesLib |
Libs.ResourcesLib |
Sync (deprecated) | Legacy economy on Bot properties |
In development (source in under_dev/, not yet on platform as Libs.*): oxapay, ton. Test via require() until promoted.
Documentation: Lib-Docs/ · Published: docs.telebothost.com/libs
let roll = Libs.random.randomInt(1, 6)
let name = Libs.tgutil.getNameFor(user)
Bot.sendMessage(name + " rolled " + roll)let gold = Libs.ResourcesLibv2.userRes("gold")
await gold.add(50)
Bot.sendMessage("Gold: " + await gold.value())if (!(await Libs.mcl.quick(user.id, ["@MyChannel"]))) {
return Api.sendMessage({
chat_id: chat.id,
text: "Join our channel to continue.",
reply_markup: { inline_keyboard: Libs.mcl.getBtn(["@MyChannel"]) }
})
}| Pattern | When to use | Example |
|---|---|---|
| Sync | Instant computation, no I/O | Libs.random.randomInt(1, 6) |
| Async | db, HTTP, Telegram API |
await Libs.refLib.count() |
- Always
awaitasync Lib methods. - TBL does not support
.then()/.catch()in command Logic. - Each Lib method has a 2-second execution timeout.
- Same rules apply to custom libs loaded via
require()—awaittheir async methods too.
Modern official libraries use async db.user and db.bot — not deprecated Bot.set / User.set.
| Library | Storage |
|---|---|
ResourcesLibv2 |
db.bot — keys ResourcesLib_* |
refLib |
db.user + db.bot — keys rfl:* |
translate |
db.user + db.bot |
cooldown |
db.user / db.bot — keys cd:{name} |
tbl-libs/
├── Libs/ # Official lib source (maps to Libs.* on TBL when deployed)
├── under_dev/ # Experimental source (test with require() first)
└── Lib-Docs/ # Documentation for bot developers
Files in Libs/ correspond to platform access names: Libs/tgutil.js → Libs.tgutil.
Copy code from Libs/ or under_dev/ into a command (e.g. mylib), then in a test command:
let lib = require("mylib")
await lib.configure({ ... })module.exports = {
myMethod: function() {},
myAsync: async function() {}
};Do not use exports = { ... } alone. Export an object or class.
Open a PR with:
.jsfile underLibs/(orunder_dev/for experimental)- Docs in
Lib-Docs/ - Notes on how you tested via
require()on TBL
Merged libs are deployed to the platform as Libs.<name> — not something you install per bot.
- Validate inputs before operating on user data.
- Use
db.incr/decrfor counters and balances. - Check
{ ok }ondb.set/db.del; try/catch onincr/push. - Escape user text with
Libs.tgutil.escapeTextwhen using official libs alongside custom code. - Store API keys in bot ENV — never hard-code secrets in Logic.
See repository license file. Libraries are provided for use with TeleBotHost TBL bots.