Skip to main content
Open In ColabOpen on GitHub

电报

Telegram Messenger is a globally accessible freemium, cross-platform, encrypted, cloud-based and centralized instant messaging service. The application also provides optional end-to-end encrypted chats and video calling, VoIP, file sharing and several other features.

本笔记本介绍如何将数据从 Telegram 加载为可被 LangChain 摄入的格式。

from langchain_community.document_loaders import (
TelegramChatApiLoader,
TelegramChatFileLoader,
)
loader = TelegramChatFileLoader("example_data/telegram.json")
loader.load()
[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 账户。

您可以从 https://my.telegram.org/auth?to=apps 获取 API_HASH 和 API_ID

chat_entity – 建议作为频道的 实体

loader = TelegramChatApiLoader(
chat_entity="<CHAT_URL>", # recommended to use Entity here
api_hash="<API HASH >",
api_id="<API_ID>",
username="", # needed only for caching the session.
)
loader.load()