The crawler at the heart ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-ollama-crontab/llms.txt
Use this file to discover all available pages before exploring further.
backtest-ollama-crontab reads messages directly from public Telegram channels using the MTProto protocol via the GramJS (telegram npm package) TelegramClient. Unlike the Telegram Bot API, MTProto authenticates as a real Telegram user account, which means it can read any channel your account has access to — no channel administrator permission is needed. Authentication happens once via a QR code, and the resulting session is serialised to a plain text file that the application loads on every subsequent start.
Why MTProto instead of the Bot API?
The Bot API only delivers messages to bots that are explicitly added to a channel. MTProto client authentication (the same protocol used by the official Telegram desktop app) lets the application subscribe to any channel as a regular user. ThegetTelegram singleton in packages/core/src/config/telegram.ts reads session.txt, deserialises it into a StringSession, and hands back an authenticated TelegramClient that can call iterMessages on any channel the account follows.
packages/core/src/config/telegram.ts
singleshot wrapper from functools-kit ensures the async initialisation runs exactly once — concurrent callers all await the same promise rather than opening multiple connections.
The StringSession mechanism
StringSession is a GramJS session adapter that serialises the entire MTProto session state (server keys, auth keys, DC assignments) into a single base64-like string. Writing this string to session.txt and reading it back on the next run means the client never needs to re-authenticate, even across process restarts. If the string is empty (as during the initial auth flow), GramJS starts a fresh session from scratch.
If
session.txt is missing or unreadable when getTelegram is called, the
function logs "No session found. Please run 'npm start -- --auth' to create a session." to stderr and re-throws the underlying error, which will crash the
crontab with a clear diagnostic message rather than failing silently mid-run.Prerequisites
Before running the auth command, make sure the following environment variables are set inpackages/main/.env (or exported in your shell). These are the MTProto application credentials registered at my.telegram.org:
Your MTProto application’s numeric API ID. Log in to
my.telegram.org, open API development tools,
and copy the
App api_id value. The repository ships a default development
credential — replace it with your own for any serious use.Your MTProto application’s API hash, shown on the same
my.telegram.org dashboard page alongside the API
ID. Treat this value like a password.
Authentication walkthrough
Navigate to the main package
Open a terminal at the repository root and change into the Make sure dependencies are installed and the workspace has been built before
continuing:
packages/main
directory:Run the auth command
Start the QR-code authentication flow:Internally this invokes If your Telegram account has two-factor authentication (2FA) enabled, the
terminal will prompt
packages/main/src/main/session.ts, which calls
client.signInUserWithQrCode(...) from GramJS. The terminal clears and a
QR code is rendered using qrcode-terminal.Enter your 2FA password: after a successful scan —
type your cloud password and press Enter.Scan the QR code with Telegram mobile
On your phone, open the Telegram app and navigate to:Settings → Devices → Link Desktop DevicePoint the in-app camera at the QR code in your terminal. The phone
authorises the new session on the Telegram server side. When the connection
is confirmed, the terminal prints:
Verify session.txt was created
Confirm the file exists in the The file contains a single long base64-like string — the serialised
packages/main directory:StringSession. Keep it secret and do not open it in a GUI text editor that
syncs to the cloud.Copy the session file into your strategy directory
The strategy reads Each strategy directory that needs Telegram access must have its own copy.
If you create a new strategy, repeat this copy step — the session string
itself is reusable across directories.
session.txt relative to its own working directory.
Copy the file into the strategy folder before running a backtest or going
live: