> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Telegram 集成

> 使用 LangChain Python 与 Telegram 文档加载器集成。

> [Telegram Messenger](https://web.telegram.org/a/) 是一个全球可访问的免费增值、跨平台、加密、基于云且中心化的即时通讯服务。该应用还提供可选的端到端加密聊天和视频通话、VoIP、文件共享以及其他多项功能。

本笔记本介绍了如何从 `Telegram` 加载数据，并将其转换为可被 LangChain 处理的格式。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders import (
    TelegramChatApiLoader,
    TelegramChatFileLoader,
)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
loader = TelegramChatFileLoader("example_data/telegram.json")
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
loader.load()
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[Document(page_content="Henry on 2020-01-01T00:00:02: It's 2020...\n\nHenry on 2020-01-01T00:00:04: Fireworks!\n\nGrace ðŸ§¤ ðŸ\x8d’ on 2020-01-01T00:00:05: You're a minute late!\n\n", metadata={'source': 'example_data/telegram.json'})]
```

`TelegramChatApiLoader` 直接从 Telegram 中指定的聊天加载数据。为了导出数据，您需要验证您的 Telegram 账户。

您可以从 [my.telegram.org/auth?to=apps](https://my.telegram.org/auth?to=apps) 获取 API\_HASH 和 API\_ID。

chat\_entity——建议使用频道的 [实体](https://docs.telethon.dev/en/stable/concepts/entities.html?highlight=Entity#what-is-an-entity)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
loader = TelegramChatApiLoader(
    chat_entity="<CHAT_URL>",  # 建议在此处使用 Entity
    api_hash="<API HASH >",
    api_id="<API_ID>",
    username="",  # 仅用于缓存会话。
)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
loader.load()
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
```

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\document_loaders\telegram.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
