Skip to main content

AgentForge Telegram Gateway

Connect user-owned AI agents to people through Telegram for notifications, conversations and file exchange.

Community Edition · MVP/Beta · GNU AGPL v3 (AGPL-3.0-only)

Quickstart · Features · MCP · Security · Architecture · Contributing

AgentForge Telegram Gateway is for developers and operators who want a small, self-hosted bridge between Telegram and local or remote AI-agent workflows. Pair a Telegram chat once, provision a source-scoped agent identity, then exchange text, documents and photos without putting a Telegram chat ID or bot token into agent prompts.

It works with MCP-capable clients and agent workflows such as ChatGPT, Codex, Claude and Qwen. The gateway is provider-independent: provider-account authentication remains with the provider's own tooling.

Quickstart

1. Install

git clone https://github.com/AgentForge-Labs/shared-telegram-notifier.git
cd shared-telegram-notifier
python3 -m venv .venv
. .venv/bin/activate
python -m pip install .

This installs four commands:

agentforge-telegram          inbox, reply, file and notification CLI
agentforge-telegram-mcp      MCP diagnostics and tool access
agentforge-telegram-admin    bot setup, source provisioning and pairing
agentforge-telegram-gateway  gateway server

2. Create a Telegram bot

Create a bot with Telegram's @BotFather, then store the token through the protected setup flow:

sudo agentforge-telegram-admin telegram-setup
sudo agentforge-telegram-admin telegram-doctor

The bot token is entered through a hidden prompt and stored outside the repository. Do not commit bot tokens, chat IDs or generated source credentials.

3. Provision and pair an agent source

sudo agentforge-telegram-admin provision my-agent \
  --output /var/lib/my-agent/telegram-gateway-key \
  --owner my-agent:my-agent

sudo agentforge-telegram-admin pair my-agent

Open the generated Telegram deep link. The pairing flow learns the authorized Telegram identity from Telegram itself; users do not need to copy a numeric chat ID.

4. Run the gateway

A hardened systemd unit is included at deploy/telegram-notifier.service. After installing the service and configuration paths for your host:

sudo systemctl daemon-reload
sudo systemctl enable --now telegram-notifier
curl http://127.0.0.1:8818/health

The gateway defaults to loopback. Put a TLS reverse proxy in front of it if an MCP client must connect remotely.

Features

  • one-time Telegram pairing links — no manual chat-ID discovery;
  • bidirectional text messages;
  • inbound and outbound documents/photos;
  • per-source receive, send and files permissions;
  • multiple agent sources with isolated credentials and bindings;
  • Telegram commands such as /agents, /use, /status and /help;
  • REST/agent CLI for inbox, replies, files and proactive notifications;
  • Streamable HTTP-style MCP endpoint;
  • Bearer authentication for header-capable MCP clients;
  • URL-secret mode for clients that cannot send custom authorization headers;
  • OAuth 2.1 Authorization Code + PKCE for OAuth-capable MCP clients;
  • source-scoped authorization so one agent credential cannot impersonate another source;
  • loopback-first deployment and protected file-based secrets.

MCP access

The MCP gateway exposes the Telegram bridge to MCP-capable clients while preserving source isolation.

Bearer

Use the normal MCP endpoint with the source credential:

POST https://telegram.example.com/mcp
Authorization: Bearer <source-secret>

URL secret

For clients that cannot attach an authorization header:

https://telegram.example.com/client/<source-secret>/mcp

Treat that URL as a credential. Configure reverse-proxy access logs so the secret-bearing path is never recorded verbatim.

OAuth + PKCE

OAuth-capable MCP clients can use the gateway's protected-resource and authorization-server discovery endpoints with Authorization Code + PKCE S256. Configure OAuth with protected secret files; do not place client secrets directly in committed service files.

See docs/ARCHITECTURE.md for the authentication and trust boundaries.

Generate an MCP connection file

The admin CLI can write a protected client configuration without printing the source secret to standard output:

sudo agentforge-telegram-admin mcp-config my-agent \
  --provider qwen \
  --base-url https://telegram.example.com \
  --key-file /var/lib/my-agent/telegram-gateway-key \
  --output /var/lib/my-agent/telegram-mcp.json \
  --owner my-agent:my-agent

Use the provider value that matches the client you are configuring. Generated connection files are credentials and should remain outside the repository.

Agent CLI examples

Check the authenticated inbox:

agentforge-telegram --help

The CLI supports receiving events, replying, retrieving inbound files and sending notifications. Run --help for the current command surface rather than copying credentials into shell history.

Python SDKs

The REST client is importable directly after installing the PyPI package:

from agent_client import TelegramAgentClient

client = TelegramAgentClient.from_key_file(
    "my-agent", "/var/lib/my-agent/telegram-gateway-key"
)
events = client.inbox(limit=10)

For MCP transport diagnostics and arbitrary tool calls, use mcp_client.TelegramMcpClient or the matching CLI command:

agentforge-telegram-mcp --base-url https://telegram.example.com \
  --auth bearer --key-file /var/lib/my-agent/telegram-gateway-key call \
  telegram_inbox --arguments '{"limit":10}'

Security

The project is designed around a simple rule: Telegram identity, gateway identity and model-provider identity are separate trust boundaries.

Key defaults and protections include:

  • gateway TCP bind defaults to 127.0.0.1:8818;
  • the bot token lives in a protected file outside the repository;
  • source credentials are generated per agent/source;
  • persistent registries store credential digests rather than plaintext source keys;
  • pairing codes are short-lived and one-use;
  • OAuth uses exact redirect-URI matching and PKCE S256;
  • OAuth authorization/access/refresh state is stored as digests where applicable;
  • URL-secret application logs are redacted;
  • audit metadata excludes message text, file contents and raw credentials;
  • group chats are disabled by default.

Example configuration lives in .env.example and contains placeholders/file paths only. Never commit a real bot token, numeric personal chat/user identifier, real conversation fixture, private webhook URL or generated agent credential.

For trust boundaries and protocol flow, see docs/ARCHITECTURE.md. For vulnerability reporting, see SECURITY.md.

Deployment notes

The included systemd unit is a reference for Linux hosts. Review service user/group ownership and paths before enabling it on your system. Remote MCP access should use HTTPS at the reverse proxy; do not expose the loopback HTTP listener directly to the public internet.

Useful diagnostics:

agentforge-telegram-admin telegram-doctor
agentforge-telegram-mcp --help
agentforge-telegram-gateway --check

What this project is — and is not

This repository is the focused Telegram communication bridge. It does not contain the AgentForge cloud control plane, private AgentScope backend, enterprise infrastructure orchestration or production credentials.

For broader AgentForge projects and public releases, visit AgentForge Labs on GitHub.

Within the AgentForge product family:

  • AgentScope is the natural next step when you need observability and operations around agent runs;
  • AgentForge Runtime is the commercial expansion when you need controlled infrastructure access and enterprise runtime capabilities.

No private repository is required to use this Community Edition.

Contributing

See CONTRIBUTING.md. Please keep examples synthetic and never include real Telegram credentials, personal chat/user IDs or customer messages in issues, fixtures or pull requests.

License

AgentForge Telegram Gateway Community Edition is licensed under the GNU Affero General Public License v3.0 only (AGPL-3.0-only). See LICENSE.

Maintainers

Maintained by AgentForge Labs.

Commercial web application

The private commercial repository includes a separate Next.js marketing and checkout app in web/.

cd web
npm ci
npm run validate
npm run dev

Payment credentials and provider product/variant IDs are documented in web/.env.example. They are server-side only.

Metadata

Release files for agentforge-telegram-gateway 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentforge-telegram-gateway 3.1.1
File Size Uploaded Provenance
agentforge_telegram_gateway-3.1.1.tar.gz 63.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agentforge-telegram-gateway 3.1.1
File Interpreter ABI Platform
agentforge_telegram_gateway-3.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 120.7 kB

Release files / agentforge_telegram_gateway-3.1.1.tar.gz

Download URL agentforge_telegram_gateway-3.1.1.tar.gz
Size 63.2 kB
Tags Source
SHA-256 checksum
How to use checksums
00ea5689f7d287d8c1d441df458234b570c198e8952547c4255ac48ea4ba8361
BLAKE2b-256 checksum
How to use checksums
3a66f8bdfde931e3e4f8bb2ac8ef2466116d81871a5bf5d17920130cf13269f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / agentforge_telegram_gateway-3.1.1-py3-none-any.whl

Download URL agentforge_telegram_gateway-3.1.1-py3-none-any.whl
Size 57.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8a85e9262ad6f871cbe6c6418593be39f73d73eb25c71e12044dd77641caa67
BLAKE2b-256 checksum
How to use checksums
1f243d3e4a1e60e731c4a4b928fcfc84a9ddbd1013bcff868988b2928d8c2b85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for agentforge-telegram-gateway 3.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page