parser

package module
v0.0.0-...-e857a45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 12 Imported by: 0

README

telegram-auto

telegram parser for w_popularity.

Scrapes the public preview at https://t.me/s/<handle> — no auth, no API token, no MTProto. The same HTML response carries both the channel counters and the last ~20 posts inline.

Caveats

  • Works only for public channels. User handles (t.me/<user>) have no /s/ preview — Telegram redirects them to a plain "Send Message" page, so FetchChannel and FetchRecentPosts return shared.ErrNotFound with a hint that the handle is not a public channel.
  • Private channels and missing handles likewise return ErrNotFound.
  • The preview embeds the most recent ~20 messages only. For deeper history you'd need MTProto or ?before= pagination (not implemented).
  • Reactions and comments are not exposed in the preview; those fields stay at zero in PostSnapshot.
  • Telegram's compact counters (1.2K, 5M, 2.1B) are parsed by multiplying the float prefix. There is some loss of precision for large numbers (Telegram itself rounds).

Usage

import parser "github.com/suenot/telegram-auto"

p := parser.New(parser.Config{HTTPTimeout: 15 * time.Second})
snap, err := p.FetchChannel(ctx, "durov")
posts, err := p.FetchRecentPosts(ctx, "durov", time.Now().Add(-24*time.Hour))

Strategy

  • Primary: GET https://t.me/s/<handle> HTML scrape (this module).
  • Fallback (not implemented): MTProto via gotd/td for private channels or deep history; Camoufox for anti-bot scenarios.

License

MIT

Documentation

Overview

Package parser implements the w_popularity telegram adapter.

Strategy: scrape the public preview at https://t.me/s/<handle>. That endpoint exposes subscriber counts and the last ~20 posts inline for public CHANNELS. User handles (and private/missing channels) have no preview and return ErrNotFound.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Credential is unused for the public preview scraper; kept for
	// symmetry with sibling parsers.
	Credential string
	// HTTPTimeout caps every outbound call. Default: 15s.
	HTTPTimeout time.Duration
	// CamoufoxURL is unused; reserved for future browser fallback.
	CamoufoxURL string
	// BaseURL overrides https://t.me. Used in tests.
	BaseURL string
	// HTTPClient overrides the default HTTP client. Used in tests.
	HTTPClient *http.Client
	// UserAgent overrides the request UA. Default: Mozilla/5.0.
	UserAgent string
}

Config controls runtime behaviour.

type TelegramParser

type TelegramParser struct {
	// contains filtered or unexported fields
}

TelegramParser scrapes the public t.me/s/ preview.

func New

func New(cfg Config) *TelegramParser

New constructs a TelegramParser.

func (*TelegramParser) FetchChannel

func (p *TelegramParser) FetchChannel(ctx context.Context, handle string) (shared.ChannelSnapshot, error)

FetchChannel returns a snapshot for the given public channel or group. Channels expose subscribers + posts via the /s/ preview; groups expose only member count via the plain t.me/<handle> page. Private/missing entries return shared.ErrNotFound.

func (*TelegramParser) FetchRecentPosts

func (p *TelegramParser) FetchRecentPosts(ctx context.Context, handle string, since time.Time) ([]shared.PostSnapshot, error)

FetchRecentPosts parses the embedded posts in the /s/ preview. Posts older than `since` are filtered out. Newest-first.

func (*TelegramParser) Platform

func (p *TelegramParser) Platform() shared.Platform

Platform implements shared.Parser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL