TeleGlanceClient

The main client class for all operations.

TypeScript
const client = new TeleGlanceClient({
  baseUrl: 'https://t.me',          // Base URL for requests
  rateLimit: 1000,                  // Milliseconds between requests
  retries: 3,                       // Retry attempts on failure
  timeout: 15000,                   // Request timeout in milliseconds
  proxy: undefined,                 // HTTP/HTTPS proxy URL
  headers: {},                      // Custom HTTP headers
  registry: undefined,              // Custom parser registry
  selectors: undefined,             // Custom CSS selectors
  strictParsing: false,             // Throw on parse warnings
});

getChannel

Fetch channel metadata including title, description, and subscriber count.

TypeScript
const channel = await client.getChannel('telegram');

console.log(channel.name);              // Channel username
console.log(channel.title);             // Display title
console.log(channel.description);       // Channel description (if available)
console.log(channel.counts.subscribers); // Subscriber count
console.log(channel.photoUrl);          // Profile photo URL (if available)

getMessage

Fetch a single message by ID.

TypeScript
const message = await client.getMessage('telegram', 12345);

console.log(message.id);                // Message ID
console.log(message.text);              // Text content
console.log(message.date);              // Posted timestamp
console.log(message.views);             // View count
console.log(message.media);             // Media attachments (if any)

getMessages

Fetch a page of messages. Returns newest-first by default.

TypeScript
// Get latest messages
const messages = await client.getMessages('telegram', { limit: 20 });

// Paginate backwards
const older = await client.getMessages('telegram', {
  limit: 20,
  before: messages[messages.length - 1].id
});

// Get newer messages (forward pagination)
const newer = await client.getMessages('telegram', {
  limit: 20,
  after: oldestId
});

iterMessages

Async iterator for history pagination. Automatically fetches pages.

TypeScript
for await (const message of client.iterMessages('telegram', { limit: 100 })) {
  console.log(message.id, message.text);
}

// With before cursor
for await (const message of client.iterMessages('telegram', {
  limit: 50,
  before: messageId
})) {
  process(message);
}

iterNewMessages

Iterate forward in time from a given message ID (oldest-first).

TypeScript
// Get all messages after ID 12345
for await (const message of client.iterNewMessages('telegram', { after: 12345 })) {
  console.log(`New: ${message.id}`);
}

search

Search for messages matching a query string.

TypeScript
// Simple search
const results = await client.search('telegram', 'python', { limit: 20 });

// Async iteration
for await (const message of client.search('telegram', 'release notes', { limit: 100 })) {
  console.log(message.url);
}

watch

Poll for new messages in real-time. See Live watching page for details.

TypeScript
import { watch } from 'teleglance';

for await (const message of watch(client, 'telegram', 30000)) {
  console.log(`New post: ${message.id}`);
}

Type definitions

All models are fully typed with exported TypeScript interfaces.

TypeScript
import type { Channel, Message, Media } from 'teleglance';

// All properties are typed
const channel: Channel = await client.getChannel('telegram');
const message: Message = await client.getMessage('telegram', 123);

// Media is an array of typed objects
if (message.media) {
  for (const item of message.media) {
    console.log(item.type, item.url);
  }
}