Практическая инструкция для тех, кто хочет подключить Telegram к локальному AI-ассистенту, Codex, Claude Code или другому coding agent, но не хочет отдавать агенту право писать, редактировать или удалять сообщения от своего имени.
This repository is a docs-only guide. It describes a safe local architecture for using selected Telegram chats as context for an AI assistant.
It puts extra emphasis on the most confusing setup blocker: getting api_id and api_hash from my.telegram.org when the Telegram application form only returns the vague ERROR message, especially for users in Russia or similar network environments.
This is often the hardest part before any AI assistant integration starts. The guide includes a dedicated troubleshooting flow for:
my.telegram.org says ERROR;ERRORwhen creating a Telegram App;- getting Telegram API
api_idandapi_hash; - VPN / proxy problems;
- phone number country vs IP country mismatch;
- temporary
hostsworkaround formy.telegram.org; - what not to do, including repeated automated
/apps/createrequests.
Use Telegram as a source of work context, not as an unrestricted agent tool.
Recommended flow:
Telegram work account
-> read-only Telethon / MTProto sync
-> explicit allowlist of selected work chats
-> local SQLite index
-> compact Markdown / Obsidian context
-> local AI assistant
-> optional draft queue
-> manual approval before any send
- Read-only first.
- Allowlist first.
- Local storage first.
- No secrets in Git.
- No full Telegram history in prompts.
- No auto-send.
- No broad Telegram MCP tools exposed directly to the assistant.
This is not a Telegram bot tutorial, a cloud service, or a full Telegram client. It is a pattern for building a narrow, local, safety-first context layer.
- How to use Telegram as context for a local AI assistant.
- How to connect Telegram to Codex, Claude Code, Cursor, Cline, Roo Code, Aider, Continue, Gemini CLI, OpenCode, or Obsidian without exposing broad write tools.
- How to get Telegram API
api_idandapi_hashfrommy.telegram.org. - How to troubleshoot the vague
my.telegram.org ERROR/my.telegram.org says ERRORmessage when creating a Telegram App. - How to build a read-only Telegram integration with Telethon or another MTProto client.
- How to choose a safer alternative to broad Telegram MCP tools.
This pattern is tool-agnostic. It can be used with local or agentic coding assistants such as OpenAI Codex, Claude Code, Cursor, Cline, Roo Code, Aider, Continue, Gemini CLI, OpenCode, GitHub Copilot-style agents, and Obsidian-based Markdown workflows.
Before publishing your own fork or implementation:
- Remove real chat IDs, names, phone numbers, and screenshots.
- Remove API ID, API hash, bot tokens, and session files.
- Keep
.env,*.session, SQLite databases, raw exports, attachments, and logs out of Git. - Use fake paths in examples.
- Do not expose unrestricted send, edit, delete, admin, contact, or group-management tools to an AI assistant.
