Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-ollama-crontab/llms.txt

Use this file to discover all available pages before exploring further.

The crawler component of backtest-ollama-crontab connects to Telegram using GramJS (the telegram npm package) over the MTProto protocol. Unlike a Telegram Bot, this is a user-account connection — it authenticates as a real Telegram user, which is required to read messages from public channels without needing to be a member or administrator. Once authentication succeeds, GramJS serializes the session to a session.txt file. Every subsequent run loads that file and reconnects without prompting again.

Get Telegram API Credentials

Before you can authenticate, you need a Telegram application registered under your account:
  1. Open my.telegram.org in a browser and log in with your phone number.
  2. Navigate to API Development Tools.
  3. Fill in the form (App title and short name can be anything) and click Create Application.
  4. Copy the App api_id (an integer) and App api_hash (a 32-character hex string).
  5. Add both values to your .env file:
.env
CC_TELEGRAM_API_ID=12345678
CC_TELEGRAM_API_HASH=0123456789abcdef0123456789abcdef
The bundled default credentials (CC_TELEGRAM_API_ID=31861455) are demo values included for development convenience. They have strict rate limits imposed by Telegram and may not work for all public channels. Always replace them with your own application credentials before running the crawler against real channels.

Run the Auth Command

The packages/main package exposes an auth script that launches a QR-code authentication flow using qrcode-terminal. The script is triggered by passing --session to the main entry point, which npm run auth handles automatically.
1

Navigate to the main package

cd packages/main
2

Run the auth command

npm run auth
Internally this executes:
dotenv -e .env -- npm start -- --session
Environment variables from .env are injected before the process starts, so your CC_TELEGRAM_API_ID and CC_TELEGRAM_API_HASH values are available at runtime.
3

A QR code appears in the terminal

The terminal clears and displays a QR code along with the prompt:
Scan this QR code in Telegram app (Settings -> Devices -> Link Desktop Device):
4

Scan the QR code on your phone

On your mobile device:
  1. Open Telegram.
  2. Go to Settings → Devices (or Settings → Privacy and Security → Active Sessions on some versions).
  3. Tap Link Desktop Device.
  4. Point your camera at the QR code displayed in the terminal.
5

Enter your 2FA password if prompted

If your Telegram account has two-step verification enabled, the terminal will prompt:
Enter your 2FA password:
Type your cloud password and press Enter.
6

Session file is written

On successful authentication the terminal prints:
Connected!
Session saved to ./session.txt
The file packages/main/session.txt now contains your serialized GramJS StringSession.
7

Copy the session to your strategy folder

The crawler reads session.txt from its working directory at runtime. Copy the file to the relevant strategy content folder:
cp packages/main/session.txt content/jan_2026.strategy/session.txt

Session File

session.txt contains a single serialized string produced by the GramJS StringSession class. The getTelegram() function in packages/core/src/config/telegram.ts wraps session loading in a singleshot singleton so the client is initialized only once per process lifetime:
packages/core/src/config/telegram.ts
export const getTelegram = singleshot(async () => {
    try {
        const session = await readFile('./session.txt', 'utf-8');
        const stringSession = new StringSession(session);
        const client = new TelegramClient(stringSession, CC_TELEGRAM_API_ID, CC_TELEGRAM_API_HASH, {
            connectionRetries: 5,
            systemVersion: 'Windows 10',
            deviceModel: 'Desktop',
            appVersion: '1.0.0',
        });
        await client.connect();
        await client.getMe();
        return client;
    } catch (error) {
        console.error("No session found. Please run 'npm start -- --auth' to create a session.");
        throw error;
    }
});
If session.txt is missing, readFile throws and the error handler logs:
No session found. Please run 'npm start -- --auth' to create a session.
The session.txt file must be present in the working directory from which the crawler process is launched — not necessarily at the repository root. When running a specific strategy, place the file inside that strategy’s content folder and start the process from there.

Security Considerations

Never share or commit your session.txt file. A serialized MTProto session grants full read (and potentially write) access to your Telegram account — treat it with the same care as a password or private key. If a session string is compromised, revoke it immediately from Telegram → Settings → Devices on your phone.
  • session.txt is already listed in .gitignore at the repository root. Verify this before your first commit if you have modified .gitignore.
  • Never copy session.txt into a Docker image or include it in build artifacts.
  • The crawler targets public Telegram channels; no channel membership or administrative rights are required — a valid authenticated Telegram account is sufficient.
  • If you need to rotate a session (e.g. after a password change or a suspected leak), delete session.txt, re-run npm run auth, and replace the file in all strategy folders.

Build docs developers (and LLMs) love