TypeScript
Customization
Configure transport, selectors, parsers, and error handling.
Proxy configuration
Route requests through HTTP/HTTPS proxies.
TypeScript
const client = new TeleGlanceClient({
proxy: 'http://proxy.example.com:8080'
});
// With authentication
const client2 = new TeleGlanceClient({
proxy: 'http://user:pass@proxy.example.com:8080'
});Rate limiting
Control request rate to avoid triggering Telegram's rate limits.
TypeScript
// Default: 1 request per second (1000ms)
const client = new TeleGlanceClient({ rateLimit: 1000 });
// More conservative
const client2 = new TeleGlanceClient({ rateLimit: 2000 });
// Aggressive (risk rate limiting)
const client3 = new TeleGlanceClient({ rateLimit: 500 });Custom headers
Override User-Agent or add custom headers.
TypeScript
const client = new TeleGlanceClient({
headers: {
'User-Agent': 'MyBot/1.0',
'Accept-Language': 'en-US,en;q=0.9',
}
});Strict parsing
Enable strict mode to throw exceptions on parsing warnings.
TypeScript
// Default: log warnings but continue
const client = new TeleGlanceClient({ strictParsing: false });
// Strict: throw ParseError on any parsing issue
const client2 = new TeleGlanceClient({ strictParsing: true });Custom selectors
Override CSS selectors if Telegram changes their markup.
TypeScript
import { DEFAULT_SELECTORS, type Selectors } from 'teleglance';
const customSelectors: Selectors = {
...DEFAULT_SELECTORS,
channelTitle: '.tgme_channel_info_header_title',
messageBubble: '.tgme_widget_message',
};
const client = new TeleGlanceClient({ selectors: customSelectors });Request hooks
Inspect or modify requests before they're sent.
TypeScript
import type { RequestHook } from 'teleglance';
const logRequest: RequestHook = (url, params) => {
console.log(`GET ${url}`, params);
};
const client = new TeleGlanceClient({
requestHooks: [logRequest]
});Response hooks
Inspect responses after they arrive.
TypeScript
import type { ResponseHook } from 'teleglance';
const logResponse: ResponseHook = (response) => {
console.log(`Response: ${response.statusCode}`);
};
const client = new TeleGlanceClient({
responseHooks: [logResponse]
});