Skip to main content

Telegram

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.

This notebook covers how to load data from Telegram into a format that can be ingested into LangChain.

from langchain.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 loads data directly from any specified chat from Telegram. In order to export the data, you will need to authenticate your Telegram account.

You can get the API_HASH and API_ID from https://my.telegram.org/auth?to=apps

chat_entity – recommended to be the entity of a channel.

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