# Telegram Groups Scraper (`i-scraper/telegram-groups-scraper`) Actor

⚡️ Telegram Groups Scraper: Extract messages from public & private Telegram groups.

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

## Pricing

$0.30 / 1,000 results

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?

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

## Private Telegram Groups Scraper

> Export message history from private, invite-only, and members-only Telegram groups your account can access.

**Telegram Groups Scraper** automatically downloads complete or incremental message history from the groups you specify.

***

### 1. Why you will love it

- 🏎 **Fast** — fetches thousands of messages per minute thanks to full async processing.
- 🛡 **Reliable** — retries API calls, respects rate limits and survives network hiccups.
- 🔎 **Flexible** — scrape up to 20 groups per run and use `historyFrom` to limit the time range.
- 🔐 **Reusable login** — scan the QR in Live View once; the Actor securely reuses the session on later runs.

***

### 2. Input configuration

```json
{
  "groups": [
    "@mygroup",
    "https://t.me/+abcdef1234567"
  ],
  "historyFrom": "2025-01-01T00:00:00Z",
  "telegram2faPassword": "${{ TELEGRAM_2FA_PASSWORD }}",
  "limit": 3000
}
```

Parameters explained:

- `groups` *(array, required)* — group identifiers accepted in any of the following forms:
  - `@group`
  - `https://t.me/group` *(public)*
  - `https://t.me/+<hash>` or `https://t.me/joinchat/<hash>` *(invite link)*
- `historyFrom` *(string, optional)* — ISO-8601 timestamp. Messages **older** than this value are skipped.
- `telegramSession` *(string, optional)* — pass a session string directly instead of using the secret.
- `telegram2faPassword` *(string, optional)* — account password if two-factor authentication is enabled.
- `limit` *(integer, optional, default **3000**)* — maximum number of messages to retrieve **per group**.

***

### 3. Running the Actor

1. Open **Telegram Groups Scraper** on Apify.
2. Click **Run** and open the **Live View** tab.
3. If there is no valid saved session, a QR code appears in Live View and in Logs. In Telegram open **Settings → Devices → Link Desktop Device** and scan it.
4. 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.
5. The Actor saves the session in a private per-user Key-value store and reuses it automatically.

***

### 4. Output dataset

Each message is stored in the **default dataset**. Sample record:

```json
{
  "type": "message",
  "group": "mygroup",
  "id": 12345,
  "date": "2024-05-21T15:32:10+00:00",
  "sender_id": 67890,
  "sender_username": "username",
  "text": "Hello, Apify!",
  "media_type": null
}
```

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

The **Run summary** output is stored as the `OUTPUT` record in the run's default Key-value store. It includes group-level outcomes, authentication state, rate-limit waits, and message counters. It is not added to the Dataset, so it does not create an extra dataset-item charge.

***

### 5. FAQ

**Q: I see a Telegram cooldown in the summary — did the run fail?**

A: Short cooldowns are handled automatically and message collection resumes without restarting from the beginning. Long cooldowns are reported per group so the Actor does not waste the entire run waiting.

**Q: Can I scrape a private group?**\
A: Yes. Provide a valid invite link and the Actor joins and fetches its history. If the group requires administrator approval, the run summary says `pending-approval`; rerun after the account is accepted.

**Q: How do I save only media messages?**\
A: After the run finishes, filter the dataset by `media_type`.

**Q: Is it safe to provide `telegramSession` and `telegram2faPassword`?**\
A: Secret input values never appear in logs. The generated session is stored in an Actor-specific Key-value store available only in that user's Actor scope. The QR token is displayed temporarily and is not persisted. 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: I noticed a new device called “apifytg” logged into my Telegram from an unfamiliar location. What is it?**\
A: When the actor authenticates, Telethon registers a *device* for the session (the default device model is “ApifyTG”). The IP you see is the data-centre where the actor is running (Apify Cloud or your local machine). This is expected and safe. If you want to revoke access, simply log this device out in **Settings → Devices** and remove the saved `telegramSession` / secret.

***

### 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 Comments Scraper](https://apify.com/i-scraper/telegram-comments-scraper)** — download comments from channel posts with flexible filtering options.
- 👍 **[Telegram Like Scraper](https://apify.com/i-scraper/telegram-like-scraper)** — collect like statistics, emoji reactions, and view counts from channel posts.

***

### 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 Groups Scraper** today and turn Telegram content into valuable data for analytics, brand monitoring and research!

# Actor input Schema

## `groups` (type: `array`):

Group usernames, t.me links, or private invite links. For approval-only groups, rerun after an administrator accepts the join request.

## `historyFrom` (type: `string`):

Only return messages on or after this date. Leave empty to read from the newest message backwards.

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

Maximum number of messages saved for each group.

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

Advanced: optional Telethon StringSession. Usually leave empty; the Actor saves and reuses the session after QR login.

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

Only needed when Telegram requests the account password after the QR code is scanned.

## Actor input object example

```json
{
  "groups": [
    "@python"
  ],
  "limit": 5
}
```

# Actor output Schema

## `messages` (type: `string`):

Dataset containing the messages successfully collected in this run.

## `runSummary` (type: `string`):

Authentication, group outcomes, rate limits, and message counters for this run.

## `liveView` (type: `string`):

Live QR login and progress page available while the Actor is running.

# 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 = {
    "groups": [
        "@python"
    ],
    "limit": 5
};

// Run the Actor and wait for it to finish
const run = await client.actor("i-scraper/telegram-groups-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 = {
    "groups": ["@python"],
    "limit": 5,
}

# Run the Actor and wait for it to finish
run = client.actor("i-scraper/telegram-groups-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 '{
  "groups": [
    "@python"
  ],
  "limit": 5
}' |
apify call i-scraper/telegram-groups-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,i-scraper/telegram-groups-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/cbUCAfF7bnP6B23ks/builds/UYkfa4DhB0ewqyI3M/openapi.json
