# Telegram Comments Scraper (`i-scraper/telegram-comments-scraper`) Actor

⚡️ Telegram Comments Scraper: Extract comments from public & private Telegram channels.

- **URL**: https://apify.com/i-scraper/telegram-comments-scraper.md
- **Developed by:** [i-Scraper](https://apify.com/i-scraper) (community)
- **Categories:** Social media
- **Stats:** 83 total users, 5 monthly users, 89.4% runs succeeded, 3 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.10 / 1,000 comments

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Telegram Comments Scraper

> 📊 Powerful Apify Actor for extracting comments from Telegram **channel posts**.

**Telegram Comments Scraper** automatically downloads comments from channel posts you specify, either by direct post links or by scanning a channel within a date range.

***

### 1. Why you will love it

- 🏎 **Fast** — fetches thousands of comments per minute thanks to full async processing.
- 🛡 **Reliable** — retries API calls, respects rate limits and survives network hiccups.
- 🔎 **Flexible** — supports two modes: direct post links OR channel + date range scanning.
- ☁️ **Scalable** — run dozens of parallel actors on Apify without dealing with servers.

***

### 2. Input configuration

#### Mode 1: Direct Post Links

```json
{
  "postLinks": [
    "https://t.me/channel/123",
    "https://t.me/channel/456"
  ],
  "limit": 10000,
  "telegramSession": "${{ TELEGRAM_SESSION }}",
  "telegram2faPassword": "${{ TELEGRAM_2FA_PASSWORD }}"
}
```

#### Mode 2: Channel + Date Range

```json
{
  "channel": "@mychannel",
  "postsFrom": "2025-01-01T00:00:00Z",
  "postsTo": "2025-01-31T23:59:59Z",
  "commentsFrom": "2025-01-15T00:00:00Z",
  "limit": 10000,
  "telegramSession": "${{ TELEGRAM_SESSION }}",
  "telegram2faPassword": "${{ TELEGRAM_2FA_PASSWORD }}"
}
```

Parameters explained:

**Mode 1 Parameters:**

- `postLinks` *(array, required for Mode 1)* — direct links to channel posts in format `https://t.me/channel/123`

**Mode 2 Parameters:**

- `channel` *(string, required for Mode 2)* — channel identifier accepted in any of the following forms:
  - `@channel`
  - `https://t.me/channel` *(public)*
- `postsFrom` *(string, required for Mode 2)* — ISO-8601 timestamp. Posts **older** than this value are skipped.
- `postsTo` *(string, optional)* — ISO-8601 timestamp. Posts **newer** than this value are skipped.
- `commentsFrom` *(string, optional)* — ISO-8601 timestamp. Comments **older** than this value are skipped.

**Common Parameters:**

- `limit` *(integer, optional, default **10000**)* — maximum **total** number of comments to retrieve across all posts.
- `telegramSession` *(string, optional)* — pass a session string directly instead of using the secret.
- `telegram2faPassword` *(string, optional)* — account password if two-factor authentication is enabled.

***

### 3. Running the Actor

1. Open **Telegram Comments Scraper** on Apify.
2. Choose your input mode (direct links or channel + date range).
3. Click **Run** and open the **Logs** tab.
4. If you didn't provide a session string, a QR code will appear. In the Telegram app open **Settings → Devices → Link Desktop Device** and scan the QR code.
5. If Telegram prompts for a password after scanning the QR (two-factor authentication), stop the run, open the input section and fill **Telegram 2FA password** (or set the secret `TELEGRAM_2FA_PASSWORD`) and start the Actor again.
6. (Optional) Copy the session string shown in the logs and store it as `TELEGRAM_SESSION` for future runs.

***

### 4. Output dataset

The actor produces two types of records in the **default dataset**:

#### Post Record

```json
{
  "type": "post",
  "channel": "mychannel",
  "post_id": 123,
  "post_link": "https://t.me/mychannel/123",
  "date": "2024-05-21T15:32:10+00:00",
  "text": "Check out this post!",
  "comments_count": 42
}
```

#### Comment Record

```json
{
  "type": "comment",
  "channel": "mychannel",
  "post_id": 123,
  "post_link": "https://t.me/mychannel/123",
  "comment_id": 5,
  "date": "2024-05-21T16:20:30+00:00",
  "sender_id": 67890,
  "sender_username": "username",
  "text": "Great post!",
  "media_type": null
}
```

Download results in **JSON**, **CSV**, **Parquet** and more via Apify API or UI.

***

### 5. FAQ

**Q: What's the difference between Mode 1 and Mode 2?**\
A: Mode 1 (Direct Links) lets you specify exact posts to scrape. Mode 2 (Channel + Date Range) automatically finds all posts in a channel within a date range and scrapes their comments.

**Q: I see FloodWaitError in logs — did the run fail?**\
A: No. The actor automatically waits the required time and resumes. You will only see a warning.

**Q: Can I scrape comments from private channels?**\
A: Yes, but your Telegram account must have access to the channel. Provide a valid session string for an account that is a member of the channel.

**Q: Does the `limit` apply per post or globally?**\
A: The `limit` is **global** — it applies to the total number of comments across all posts.

**Q: What if a post has no comments?**\
A: The post record will still be saved with `comments_count: 0`.

**Q: Is it safe to provide `telegramSession` and `telegram2faPassword`?**\
A: Both values are stored in Apify **Secrets**; they never appear in logs and cannot be read by other actors. A session string only grants access to act as your account, and the 2FA password is used once during the sign-in flow. Recommended practices:\
• keep both values exclusively in Secrets;\
• regenerate / update the session string whenever you change your Telegram password;\
• you can revoke access at any moment in Telegram settings by logging out the linked device.

**Q: Can I filter comments by date in Mode 1?**\
A: No, `commentsFrom` only works in Mode 2 (channel + date range). In Mode 1, all comments for the specified posts are fetched (up to the global limit).

***

### 6. Related Telegram Scrapers

Looking for more Telegram data extraction tools? Check out our complete suite:

- 🔗 **[Telegram Channels Scraper](https://apify.com/i-scraper/telegram-channels-scraper)** — extract complete message history from public Telegram channels.
- 👍 **[Telegram Like Scraper](https://apify.com/i-scraper/telegram-like-scraper)** — collect like statistics, emoji reactions, and view counts from channel posts.
- 👥 **[Telegram Groups Scraper](https://apify.com/i-scraper/telegram-groups-scraper)** — scrape message history from Telegram groups (including private invite links).

***

### 7. Support & contributions

Found a bug or have a feature request? Feel free to open an issue or submit a pull request. We're happy to discuss ideas like additional fields, filters or export formats.

***

⭐️ Launch **Telegram Comments Scraper** today and turn Telegram comments into valuable data for analytics, sentiment analysis and research!

# Actor input Schema

## `postLinks` (type: `array`):

Direct links to Telegram channel posts. Example: https://t.me/channel/123. Leave empty to use Mode 2 (channel + date range).

## `channel` (type: `string`):

Telegram channel username or link (e.g., @channel or https://t.me/channel). Use with 'Posts from' and 'Posts to' to scrape all posts in date range. Leave empty if using Mode 1 (direct links).

## `postsFrom` (type: `string`):

Only fetch posts newer than this date (inclusive). Required for Mode 2.

## `postsTo` (type: `string`):

Only fetch posts older than this date (inclusive). Optional for Mode 2.

## `commentsFrom` (type: `string`):

Only fetch comments newer than this date. Optional, works only in Mode 2.

## `limit` (type: `integer`):

Maximum total number of comments to fetch across all posts (default 10000)

## `telegramSession` (type: `string`):

Optional Telegram session string. Fill it to skip QR login next time.

## `telegram2faPassword` (type: `string`):

Password for Telegram accounts with two-factor authentication enabled. Provide it only if Telegram asks for a password after scanning the QR code. Leave empty otherwise.

## Actor input object example

```json
{
  "postLinks": [
    "https://t.me/linuxgramgroup/145773"
  ],
  "limit": 10000
}
```

# Actor output Schema

## `postsAndComments` (type: `string`):

Dataset containing Telegram channel posts and their comments with sender info, dates, comment counts, and media types.

# 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 = {
    "postLinks": [
        "https://t.me/linuxgramgroup/145773"
    ],
    "limit": 10000
};

// Run the Actor and wait for it to finish
const run = await client.actor("i-scraper/telegram-comments-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 = {
    "postLinks": ["https://t.me/linuxgramgroup/145773"],
    "limit": 10000,
}

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

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

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

```

## CLI example

```bash
echo '{
  "postLinks": [
    "https://t.me/linuxgramgroup/145773"
  ],
  "limit": 10000
}' |
apify call i-scraper/telegram-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=i-scraper/telegram-comments-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/8OfgOcJBy2ebyuSEU/builds/i1McnQHmRFnNS55Wx/openapi.json
