# Telegram Channel Scraper (`twizzler/telegram-channel-scraper`) Actor

Scrapes posts from public Telegram channels via their t.me/s web preview. No account or API keys needed.

- **URL**: https://apify.com/twizzler/telegram-channel-scraper.md
- **Developed by:** [Twizzler Fan](https://apify.com/twizzler) (community)
- **Stats:** 1 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $3.10 / 1,000 scraped items

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Telegram Channel Scraper

Scrapes posts from **public Telegram channels** using their `t.me/s/<channel>` web preview. No Telegram account, phone number or API keys are required.

For every post the Actor extracts the text, publish time, views, reactions, media (photos, videos, audio, documents, stickers), link previews, forward and reply information, hashtags and mentions, together with channel metadata (title, avatar, subscriber count, verified badge).

### What can this Actor do?

- Monitor one or many public channels for new posts in a time window (last N minutes/hours/days or an explicit `since`/`until` range).
- Deduplicate across runs with the stable `uniqueKey` (`<channel>:<messageId>`).
- Run many channels in parallel with per-channel safety caps on posts and pages.
- Rotate Apify Proxy sessions automatically, retrying blocked or geo-restricted previews on a fresh IP.

### Input

| Field                | Type                           | Description                                                                                                     |
| -------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------- |
| `channels`           | `string[]`                     | **Required.** Channel URLs (`https://t.me/durov`, `https://t.me/s/durov`), `@usernames` or bare usernames.      |
| `lookbackValue`      | `integer`                      | How far back to fetch (default `24`).                                                                           |
| `lookbackUnit`       | `minutes` | `hours` | `days` | Unit for `lookbackValue` (default `hours`).                                                                     |
| `sinceTimestamp`     | `string`                       | Optional ISO 8601 date or Unix timestamp. Overrides the lookback.                                               |
| `untilTimestamp`     | `string`                       | Optional ISO 8601 date or Unix timestamp. Defaults to now.                                                      |
| `maxPostsPerChannel` | `integer`                      | Cap on posts per channel, `0` = unlimited (default).                                                            |
| `maxPagesPerChannel` | `integer`                      | Safety cap on preview pages (~20 posts each) per channel (default `50`).                                        |
| `concurrency`        | `integer`                      | Channels scraped in parallel (default `8`).                                                                     |
| `proxyConfiguration` | `object`                       | Standard Apify proxy settings (default: Apify Proxy on). Residential proxies help with geo-restricted channels. |

Example:

```json
{
    "channels": ["https://t.me/s/telegram", "@durov"],
    "lookbackValue": 7,
    "lookbackUnit": "days"
}
```

### Output

One dataset item per post:

```json
{
    "uniqueKey": "telegram:350",
    "id": 350,
    "url": "https://t.me/telegram/350",
    "channel": {
        "username": "telegram",
        "title": "Telegram News",
        "url": "https://t.me/telegram",
        "avatarUrl": "https://cdn4.telesco.pe/file/....jpg",
        "isVerified": true,
        "subscribers": 10123456
    },
    "text": "Telegram 11.0 is out ...",
    "publishedAt": "2026-10-20T14:03:11.000Z",
    "publishedAtTimestamp": 1792504991000,
    "views": 2345678,
    "isEdited": false,
    "isAlbum": false,
    "postAuthor": null,
    "isForwarded": false,
    "forwardedFrom": null,
    "isReply": false,
    "replyToMessageId": null,
    "replyToUrl": null,
    "reactions": [
        {
            "type": "emoji",
            "emoji": "❤",
            "customEmojiId": null,
            "imageUrl": "https://telegram.org/img/emoji/40/E29DA4.png",
            "count": 12000
        },
        {
            "type": "custom_emoji",
            "emoji": null,
            "customEmojiId": "5780596797219016124",
            "imageUrl": null,
            "count": 66
        },
        { "type": "paid", "emoji": "⭐", "customEmojiId": null, "imageUrl": null, "count": 5 }
    ],
    "totalReactions": 12071,
    "hasMedia": true,
    "mediaTypes": ["video"],
    "media": [
        {
            "type": "video",
            "url": "https://cdn4.telesco.pe/file/....mp4",
            "thumbnailUrl": "https://cdn4.telesco.pe/file/....jpg",
            "caption": null,
            "duration": 42,
            "isDownloadable": true
        }
    ],
    "linkPreview": null,
    "hashtags": [],
    "mentions": [],
    "scrapedAt": "2026-10-21T09:00:00.000Z"
}
```

A per-run summary (time window, per-channel page/post counts, skipped inputs and errors) is stored in the default key-value store under the `SUMMARY` key. If the run is aborted, the summary written so far is flagged with `"aborted": true`.

#### Reactions

Each entry in `reactions` has a `type`:

- `emoji` – a standard emoji reaction; `emoji` holds the character and `imageUrl` the icon shown on t.me.
- `custom_emoji` – a Telegram Premium custom emoji; only `customEmojiId` is available (the web preview does not render it).
- `paid` – Telegram Stars; `emoji` is `⭐`.

#### Media

`media[].url` is the direct CDN link to the file (photo, video, audio, document, sticker) as served on the web preview; `thumbnailUrl` is the poster image for videos and link previews. `linkPreview` is a convenience copy of the first `link`-type media entry.

Telegram does not serve large videos on the web preview ("Media is too big"). Such entries have `isDownloadable: false`, `caption` set to Telegram's reason, `url` pointing at the post on t.me and `thumbnailUrl` still populated.

### Limitations

- Only channels with a public web preview can be scraped. Private channels, groups, users and invite links (`t.me/+…`, `t.me/joinchat/…`, `t.me/c/…`) are skipped.
- Some channels are geo-restricted on the web preview; using residential proxies in `proxyConfiguration` usually resolves this.
- Comments / discussion threads are not part of the web preview and are not scraped.
- Telegram's preview serves ~20 posts per page; very large lookback windows on busy channels need a higher `maxPagesPerChannel`.

### Local development

```bash
npm install
apify run        # reads storage/key_value_stores/default/INPUT.json, writes storage/datasets/default/
npm test         # unit tests for input parsing and the HTML parser
```

### Project structure

```text
.actor/
├── actor.json                   # Actor config: name, version, schemas
├── input_schema.json            # Input validation & Console form definition
├── dataset_schema.json          # Shape of each post item + Console table view
├── key_value_store_schema.json  # The SUMMARY record
└── output_schema.json           # Links to the dataset and SUMMARY
src/
├── main.ts      # Entry point: input → scrape channels concurrently → dataset + SUMMARY
├── input.ts     # Input validation, channel/timestamp parsing
├── scraper.ts   # Walks a channel's t.me/s preview backwards page by page
├── http.ts      # undici GET with proxy sessions, retries and redirect detection
├── proxy.ts     # Sticky proxy session pool + undici dispatcher cache
├── parser.ts    # Cheerio parser for the web preview HTML
├── output.ts    # Maps parsed posts to dataset items
├── types.ts     # Shared types
└── utils.ts     # Helpers (counters, concurrency)
```

# Actor input Schema

## `channels` (type: `array`):

Public Telegram channels to scrape. Accepts channel URLs (`https://t.me/durov`, `https://t.me/s/durov`), `@usernames` or bare usernames. Private channels, groups and invite links are skipped.

## `lookbackValue` (type: `integer`):

How far back from `untilTimestamp` (or now) to collect posts, in the unit selected below. Ignored when `sinceTimestamp` is set.

## `lookbackUnit` (type: `string`):

Unit for the lookback value.

## `sinceTimestamp` (type: `string`):

Start of the time window as an ISO 8601 date (`2026-10-20T00:00:00Z`) or a Unix timestamp. Overrides the lookback settings.

## `untilTimestamp` (type: `string`):

End of the time window (exclusive) as an ISO 8601 date or a Unix timestamp. Defaults to the time the run starts.

## `maxPostsPerChannel` (type: `integer`):

Stop collecting once this many posts were found for a channel. `0` means unlimited.

## `maxPagesPerChannel` (type: `integer`):

Safety cap on the number of web preview pages (about 20 posts each) walked back per channel.

## `concurrency` (type: `integer`):

How many channels are scraped in parallel.

## `proxyConfiguration` (type: `object`):

Proxy settings. Apify Proxy is recommended; residential proxies help with geo-restricted channels.

## Actor input object example

```json
{
  "channels": [
    "https://t.me/s/telegram",
    "@durov"
  ],
  "lookbackValue": 24,
  "lookbackUnit": "hours",
  "maxPostsPerChannel": 0,
  "maxPagesPerChannel": 50,
  "concurrency": 8,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `posts` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "channels": [
        "https://t.me/s/telegram",
        "@durov"
    ],
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("twizzler/telegram-channel-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "channels": [
        "https://t.me/s/telegram",
        "@durov",
    ],
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("twizzler/telegram-channel-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "channels": [
    "https://t.me/s/telegram",
    "@durov"
  ],
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call twizzler/telegram-channel-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,twizzler/telegram-channel-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/WkJfCFWeYHMI4eDgN/builds/rAZqMa09iaXcwSCRj/openapi.json
