# Telegram Channel Scraper - Posts, Views, Reactions (`stas_k/telegram-channel-scraper`) Actor

Most Telegram scrapers return an empty dataset and call it a day: a group, a dead username and a channel with the preview switched off all look the same. Here every channel gets a free row that says what happened, and only delivered posts are charged.

- **URL**: https://apify.com/stas_k/telegram-channel-scraper.md
- **Developed by:** [Stas K](https://apify.com/stas_k) (community)
- **Categories:** Social media, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.50 / 1,000 posts

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 - Posts, Views, Reactions

Read public Telegram channels through their web preview: no account, no phone number, no bot
token. One row per post with the exact publication time, the text, view count, reactions,
reply target, media and links, plus one free row per channel that says how that channel reads.

Pay only for delivered posts: one charge event `message-delivered` per post that reaches the
dataset. A channel that does not exist, turns out to be a group, hides its public preview or
answers with an error costs nothing, and its row names the reason in plain words.

### Why this actor exists

The complaint in this niche is not "the data is thin", it is "I got nothing and nobody told me
why". Telegram answers HTTP 200 for a username that does not exist, for a group chat, and for a
channel whose owner switched the public preview off. Scrapers that return an empty dataset for
all three leave the buyer guessing whether the channel is dead, private, or a group.

Here every input line produces a row. If posts arrive, the row says `READ` and the posts follow.
If they do not, the row says which of the impossible cases actually happened.

### What you get

Per post (`rowType: "message"`):

| field | meaning |
|---|---|
| `channel`, `messageId`, `url` | the post identity, `https://t.me/<channel>/<id>` |
| `date` | exact UTC timestamp from the page, not a rounded "2 hours ago" |
| `text`, `textLength` | the post body as plain text, line breaks kept |
| `views`, `viewsRaw`, `viewsApproximate` | `1.67M` becomes `1670000` and is marked approximate |
| `reactions` | list of `{emoji, emojiId, count, approx, paid, kind}` where `kind` is `emoji` or `stars` |
| `reactionsTotal` | the sum of reaction counts |
| `replyToId` | the post this one answers, when it answers one |
| `forwardedFrom`, `authorSignature` | the source of a forward, the signature of a signed channel |
| `edited` | Telegram marks the post as edited |
| `mediaType`, `mediaUrl`, `mediaTitle`, `mediaCount` | `photo`, `video`, `album`, `document`, `sticker`, `poll` |
| `linkPreviewUrl`, `linkPreviewSite` | the link card Telegram shows under the post |
| `links`, `hashtags`, `mentions` | what the body itself points at |

Per channel (`rowType: "channel"`, never charged): `channel`, `channelTitle`, `channelDescription`,
`channelPhotoUrl`, `subscribers` and `subscribersApprox`, `channelPhotos`, `channelVideos`,
`channelLinks`, `messagesSeen` (posts the page carried inside the date range, before the limit),
`messagesDelivered` (posts of this channel that reached the dataset), `pagesFetched`, `truncated`
(true when `maxPostsPerChannel` cut this channel), `status`, `reason`.

### What this actor does not do

Say this before the first run, not after:

- **No forward counts and no comment counts.** Telegram's public web preview publishes neither.
  Other actors list those fields and fill them with a guess; a wrong number is worse than a
  missing one.
- **No media download.** Media is reported as the CDN link Telegram hands out. Those links carry
  a token and expire, so fetch them within the same day if you need the file itself.
- **No groups.** The public preview covers channels only. A group comes back as
  `NOT_CHECKED_NOT_A_CHANNEL`, with its member count if Telegram shows one.
- **No private channels.** An invite link comes back as `NOT_CHECKED_PRIVATE_INVITE`.
- **No search across Telegram.** This reads channels you name. It does not find channels by
  keyword.
- **Views are exact only as far as Telegram publishes them.** Below one thousand the number is
  exact; above it Telegram rounds to three significant digits, and `viewsApproximate` says so.

### Input

```json
{
  "channels": ["durov", "@telegram", "https://t.me/s/ukrpravda_news"],
  "maxPostsPerChannel": 100,
  "sinceDate": "2026-11-01",
  "maxChannels": 20
}
```

`channels` accepts a bare username, `@username`, `https://t.me/<name>`, `t.me/s/<name>` or a
link to a single post (only the channel is taken). `maxPostsPerChannel` walks from the newest
post backwards, so the newest posts are the ones a limit keeps; `0` means walk until `sinceDate`
or the start of the channel. `sinceDate` is a UTC date floor and must be written `YYYY-MM-DD`: a
date the actor cannot read is refused before the first request, because ignoring it silently
would charge you for posts outside the window you asked for. `maxChannels` cuts the list, and the
cut lines still get their own row.

### Charging

One `message-delivered` event per post written to the dataset. The charge rides on the same call
that writes the row, so a post is never billed without being delivered. A post that hits the
spending cap keeps its identity (`channel`, `messageId`, `url`, `date`) with `text: null` and
status `NOT_CHECKED_CAP`: you see what the cap cut, and it costs nothing.

The platform sets its own default cap per run when you do not set one, which is roughly 3 to 4
dollars. For a long history export, set "Max cost per run" yourself.

### Statuses

`READ` posts delivered. `NOT_CHECKED_CHANNEL_NOT_FOUND` Telegram does not know the username.
`NOT_CHECKED_NOT_A_CHANNEL` it is a group or chat. `NOT_CHECKED_NO_PUBLIC_PREVIEW` the channel
exists but shows no public posts. `NOT_CHECKED_PRIVATE_INVITE` an invite link. `NOT_CHECKED_INVALID`
the line is not a Telegram username. `NOT_CHECKED_DUPLICATE` the same channel came earlier.
`NOT_CHECKED_LIMIT` beyond `maxChannels`. `NOT_CHECKED_EMPTY` the channel has posts, none inside
`sinceDate`. `NOT_CHECKED_SOURCE` Telegram refused or timed out. `NOT_CHECKED_TIME` the platform
deadline stopped the walk. `NOT_CHECKED_CAP` the spending cap was reached. `NOT_CHECKED_ERROR` the
dataset refused the row.

A message row can also carry `NOT_CHECKED_CHARGE_UNVERIFIED`: the write raised, and the dataset
count could neither confirm nor deny that the row landed. In that case the post is not repeated
as a second row, because a duplicate in your dataset is worse than a named uncertainty.

### Run summary

The key-value store keeps `RUN_SUMMARY-<runId>`, plus a plain `RUN_SUMMARY` copy in the same
store: the default store of a run belongs to that run alone, so the copy cannot be overwritten by
another run. Counters:

- channels: requested, unique, read, empty, unreadable, invalid, cut by `maxChannels`,
  duplicates, and `channelsMismatch` if they fail to add up;
- posts: seen, delivered, cut by the limit, older than `sinceDate`, cut by the cap, refused by
  the dataset, and `messagesChargeUnverified` for the writes that could not be settled;
- money: `chargedEvents` from the platform, `deliveredUncharged` for rows that reached you free,
  `rowsDelivered` for every row written, and `billingActive` with `billingReason`.

`byStatusChannels` and `byStatusMessages` keep the two kinds of status apart. If the numbers ever
disagree, the summary says so in `counterMismatch` instead of rounding it away.

### Politeness and limits

The actor reads one page (20 posts) per request with at least 0.7 seconds between requests, and
walks back through `?before=<id>`. On HTTP 429 it waits and retries, and after that it stops the
run with `rate-limited` rather than hammering Telegram. The default window is small enough for
the platform's own five minute check, so the actor does not fall under maintenance.

### Local development

```bash
python -m src.main            # reads APIFY_LOCAL_STORAGE_DIR/key_value_stores/default/INPUT.json
python tests/test_parse.py    # parser checks on real saved pages
python tests/test_main.py     # flow checks with a fake Actor that follows the SDK
```

# Actor input Schema

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

Public channel usernames or links, one per line: durov, @durov, https://t.me/durov, t.me/s/durov, or t.me/durov/553 (only the channel is taken). Invite links to private chats cannot be read by the web preview and come back as NOT_CHECKED_PRIVATE_INVITE. Up to 20 channels per run unless maxChannels says otherwise.

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

The newest posts are read first, then the walk goes back in time. Posts beyond this number are not delivered and not charged, and the summary reports how many the limit cut. 0 means walk until sinceDate or the end of the channel.

## `sinceDate` (type: `string`):

Stop when the walk reaches a post older than this date, UTC. Leave empty for no date floor. A channel with posts, none of them inside the range, comes back as NOT_CHECKED_EMPTY with the date in the reason, not as an empty dataset with no explanation.

## `maxChannels` (type: `integer`):

The channel list is cut here. Channels beyond the limit come back as a NOT_CHECKED_LIMIT row and are not charged. 0 means no limit.

## Actor input object example

```json
{
  "channels": [
    "durov",
    "telegram"
  ],
  "maxPostsPerChannel": 100,
  "maxChannels": 20
}
```

# Actor output Schema

## `dataset` (type: `string`):

Two kinds of rows. rowType 'message' is one post: channel, messageId, url, date (the exact UTC timestamp Telegram publishes), text, textLength, views and viewsRaw, viewsApproximate (Telegram's own web preview rounds large counts, so a rounded number is marked instead of being passed off as exact), reactions as a list of {emoji, emojiId, count, approx, paid, kind} where kind is 'emoji' or 'stars' and emoji is null for a custom emoji that has only an id, reactionsTotal, replyToId when the post answers another one, forwardedFrom, authorSignature for signed channels, edited, mediaType (photo, video, album, document, sticker, poll), mediaUrl, mediaTitle, mediaCount, linkPreviewUrl, linkPreviewSite, links, hashtags, mentions, billable. Custom emoji are not media: Telegram paints them as background images, and the actor filters them out instead of claiming media a post does not have. A post cut by the spending cap keeps its identity (channel, messageId, url, date) with text null and a status NOT_CHECKED_CAP plus the reason, so nothing disappears silently. Forward counts and comment counts are NOT in this dataset: Telegram's public web preview does not publish them, and inventing them would be a worse product. rowType 'channel' is one free row per input line: channel title, description, photo, subscribers and subscribersApprox, channelPhotos, channelVideos, channelLinks, messagesSeen (posts the page carried inside the date range, before any limit), messagesDelivered (posts of this channel that reached the dataset), pagesFetched, truncated (true when maxPostsPerChannel cut this channel), status and reason. status READ means posts were delivered; NOT_CHECKED_CHANNEL_NOT_FOUND, NOT_CHECKED_NOT_A_CHANNEL (a group or chat: the web preview covers channels only), NOT_CHECKED_NO_PUBLIC_PREVIEW (the channel exists but shows no public posts), NOT_CHECKED_PRIVATE_INVITE, NOT_CHECKED_INVALID, NOT_CHECKED_DUPLICATE, NOT_CHECKED_LIMIT, NOT_CHECKED_EMPTY (posts exist but none inside sinceDate), NOT_CHECKED_SOURCE, NOT_CHECKED_TIME and NOT_CHECKED_ERROR name the reason in plain words. Only message rows are charged. A message row can also carry NOT_CHECKED_CAP, NOT_CHECKED_ERROR or NOT_CHECKED_CHARGE_UNVERIFIED: the last one means the write raised, the dataset count could not confirm the row either way, and the post is therefore not repeated as a second row.

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

Run summary kept in the key-value store under RUN_SUMMARY-<runId>, with a plain RUN_SUMMARY copy in the same store (the default store of a run belongs to that run alone, so the copy cannot be overwritten by another run) and that plain key is what the output schema template points at. Channels: channelsRequested, channelsUnique, channelsRead, channelsEmpty (read, but nothing inside the range), channelsUnreadable (not found, a group, no public preview, refused, out of time, error), channelsInvalid (the line is not a channel), channelsCutByLimit, duplicateChannels, and channelsMismatch if unique does not equal read plus empty plus unreadable plus cut. Posts: pagesFetched, messagesSeen, messagesDelivered, messagesCutByLimit, messagesBeforeSinceDate, messagesCap, messagesWriteError (the dataset refused the row), messagesChargeUnverified (the write raised and the count could not settle whether the row landed). rowsDelivered counts every row written, paid ones included. chargedEvents is what the platform actually charged, deliveredUncharged counts message rows that reached the dataset without money. billingActive and billingReason say whether the run could charge at all. stopReason is null, spending-cap, charge-error, dataset-write-error, rate-limited, deadline or empty-input. byStatusChannels and byStatusMessages keep channel and message statuses apart instead of mixing them in one bucket. chargeErrors lists the posts whose write or charge call failed, with the error text. datasetItemCount is our own count of written rows, datasetItemCountApi the same number as the platform reported it, datasetItemCountNote says the platform number was missing or behind. sinceDateParsed, maxPostsPerChannel and maxChannels report the settings actually applied; a sinceDate that cannot be read is refused before any request instead of being ignored. durationSecs and versions (apify, httpx) close the picture. messagesDelivered over messagesSeen is never claimed: a counterMismatch field appears if the numbers ever disagree.

# 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": [
        "durov",
        "telegram"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("stas_k/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": [
        "durov",
        "telegram",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("stas_k/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": [
    "durov",
    "telegram"
  ]
}' |
apify call stas_k/telegram-channel-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,stas_k/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/QcdW5Pb6Gx82bzCEf/builds/vZGUbymIVXkeSG81F/openapi.json
