CONNECT CODEX TO TELEGRAM: SEND ONE CHOSEN FILE FROM ANY LOCAL PROJECT
Local Windows integration, version 1.0.0 — November 1, 2026

CURRENT HANDOFF STATUS: OPEN. The failed setup launch is now diagnosed: this
chat executes on Christopher's OFFICE PC, <OFFICE_COMPUTER>, under User, while he is
viewing it from <STUDIO_COMPUTER> (profile <USERPROFILE>; Documents <DOCUMENTS>).
The Studio launcher does not exist. Viewing an Office chat on Studio did not
retarget its execution environment. This is a CONFIRMED host mismatch.
No credential entry or Telegram delivery occurred. Use a NEW LOCAL chat on Studio
with the portable source/handoff package, verify that chat's execution host and
prerequisites before writing, and only then install there. Do not substitute a
profile name into the earlier Office command. See VERIFICATION.txt and
STUDIO-HANDOFF.txt. Every user-facing PowerShell command must be ONE LINE.

Status of this walkthrough
This is an implementation and setup guide. See VERIFICATION.txt for the current
observed results. Credential entry, live bot/chat checks, a real sample upload,
and Christopher's receipt/opening remain separate acceptance steps until recorded.
All private values below use placeholders. No real token belongs in this file.

The useful result
From a Codex chat running on the studio PC, ask:
  Send C:\Projects\Example\outputs\report.pdf to my Telegram.
Codex can use telegram_send_file to upload that exact file as a document attachment
to the private chat approved during local setup. It works with supported local
Windows drive paths across projects; Codex need not copy the file into this project.
Resolve an ambiguous filename before sending. Only send files Christopher chooses.

Why this design
The official OpenAI documentation supports local stdio MCP servers registered in
the user's config.toml, shared by local Codex clients on the same host. We used
that direct connection instead of a cloud plugin: the sender needs local files,
and this request did not authorize uploading a plugin or publishing a service.
The Plugin Creator local route was consulted before choosing the simpler MCP
connection that the task expressly allowed. No public account package was created.

The installed Python runtime uses only the standard library. Codex starts the
process when needed; it has no listening port or continuously running watcher.
Python runs with -I -B to isolate Python environment settings and avoid bytecode.
Imports are loaded from the installed integration directory, independently of
the active project's working directory. Startup and tool discovery need no token.

The token, numeric chat ID, approved bot ID and username are encrypted together
using Windows DPAPI for the current user. The private directory grants access
only to that user and SYSTEM. Codex config stores the executable and source path,
never the token. DPAPI protects bytes at rest; a process running as the same user
can decrypt them. The token necessarily exists briefly in process memory and
in Telegram's required HTTPS request path; this implementation never logs either.

1. Prerequisites
Use the studio PC and Christopher's normal Windows account. The observed host
for the executor was <OFFICE_COMPUTER>; its account profile was <OFFICE_USERPROFILE>. This
does not establish Christopher's actual studio-session identity. Python there was installed at
<OBSERVED_OFFICE_PYTHON_DIRECTORY>\python.exe with tkinter and pythonw.exe; Codex CLI was 0.153.4.
Subsequent target evidence establishes <STUDIO_COMPUTER> / <USERPROFILE> with Documents
at <DOCUMENTS>. Its Python/Codex runtime prerequisites have not yet been tested.
An existing Telegram bot and its token are required. Open that bot's private chat
in Telegram and press Start if necessary. Know the bot's expected @username and
your positive numeric private chat ID. Telegram account phone numbers and public
usernames are not substitutes for the numeric private destination ID.

If the ID is unknown, obtain it from the existing bot consumer or its owner using
the bot's established workflow. Do not guess or paste private credentials in chat.
This integration deliberately does not discover IDs by reading bot updates.
A configured webhook is inspected read-only during setup; an empty webhook does
not prove no other polling client exists. There is no getUpdates call, offset
advance, queue consumption, deleteWebhook, setWebhook, or bot-setting mutation.
The sender can coexist with a receiver because it only reads identity/status and
performs explicitly requested uploads. Shared bot rate limits still apply.

2. Install once at user scope
From PowerShell, run the delivered helper:
  & '<PACKAGE_DIRECTORY>\Install.ps1'
It resolves the user's Documents directory, installs the runtime in
  <DOCUMENTS>\Codex\Integrations\telegram-files
and registers a stdio server using the documented direct config.toml route.
It adds a 180-second timeout to its own table so identity checks and an upload
have time to complete. It does not change any other server or project config.
If a conflicting telegram_files server already exists, it stops for local review.

On this host the expected shared configuration is
  <OFFICE_USERPROFILE>\.codex\config.toml
with a table equivalent to:
  [mcp_servers.telegram_files]
  tool_timeout_sec = 180
  command = '<OBSERVED_OFFICE_PYTHON_DIRECTORY>\python.exe'
  args = ['-I', '-B', '<INSTALL_DIR>\server.py']
No token, private recipient, network secret, or environment credential is added.
The runtime is user-wide on THIS PC; registration does not copy it to a different
computer or make local files accessible from an unrelated cloud execution host.
Project policy or a project override can still disable a user-level MCP server.

3. Enter credentials in the local masked window
After confirming the correct host/account and actual installation, double-click
Setup Telegram.cmd in that installed integration folder. The earlier executor-only
example below FAILED in Christopher's physical session and is not a working next
step for that session:
  & '<OFFICE_USERPROFILE>\Documents\Codex\Integrations\telegram-files\Setup Telegram.cmd'
This reusable command contains no credential. It opens pythonw, with no console.
Enter the existing bot token, your numeric private chat ID, and expected bot
username. The token and chat ID fields are masked. They are not shell arguments,
environment variables, source code, chat messages, or history entries.

Choose Verify identities and save. The helper calls getMe, getChat and
getWebhookInfo over HTTPS. Check the LOCAL confirmation carefully: bot username
and ID, recipient name/username and private numeric chat ID must be yours.
Cancel if anything is wrong. Confirming saves a DPAPI-encrypted blob at
  %USERPROFILE%\.codex\telegram-files-private\credentials.dpapi
Only ciphertext is written, including temporary replacement files. Re-running
setup changes the pinned destination only after fresh identity confirmation.
Setup does not send a test file. It clears the fields after a successful save.
Close the setup window when finished. Do not screenshot actual credential entry.

4. Discover and use the tools
Ask Codex to check telegram_status. It reports credential readiness without
exposing the bot token, chat ID, or other private profile fields. The send tool
accepts only an absolute file path and an optional plain-text caption. Recipients
cannot be supplied as a normal parameter. Before each upload the sender checks
that getMe and getChat still match the approved bot and private destination.

If an already-open chat has not refreshed its tools, start your next ordinary
local project chat after installation, or reopen Codex. Do not repeatedly install
the server to force discovery. See VERIFICATION.txt for what was actually tested;
a command-line discovery result is not proof of visibility in every existing chat.

The chosen file must be a nonempty regular file at most 49,000,000 bytes. This
conservative limit leaves room below Telegram's documented 50 MB file limit.
UNC/device paths, alternate data streams, wildcards, parent traversal, symbolic
links and junctions are rejected. Use a direct local drive path. The integration
vault and a hardlink to its active blob cannot be sent. The file is read-locked
during streaming; close a program that has an incompatible write handle open.
Unicode filenames are retained; unsafe header characters are removed or rejected.

Files are uploaded using sendDocument multipart/form-data with actual file bytes,
not a local-path link. The sender makes no automatic retry. After a connection
failure during upload, delivery can be uncertain: check Telegram before retrying
to avoid duplicate attachments. Normal Telegram/API limits and connectivity apply.

5. Harmless acceptance test
After secure setup, ask Codex to send this explicitly chosen installed sample:
  <OFFICE_USERPROFILE>\Documents\Codex\Integrations\telegram-files\sample-delivery.txt
The expected content includes CODEX-TELEGRAM-LOCAL-2026-11-01. A successful tool
result says telegram_api_accepted and reports the message ID. It deliberately
keeps physical acceptance pending. In Telegram, confirm the expected bot sent a
file attachment, then download/open it and read the marker. Report that outcome
without sharing the token. Only that observation proves usable receipt/opening.

For cross-project acceptance, use two separate local project contexts. First
check tool discovery/readiness in both. Select a harmless file explicitly in each
and request delivery if end-to-end coverage from both is desired. Do not modify
unrelated project files for this test. The automated setup uses isolated fixture
contexts rather than creating changes inside existing projects.

6. Maintain or remove
To replace a token or change the fixed chat, run the same masked setup again.
To inspect registration without credentials, use codex mcp get telegram_files.
To remove the connection, use codex mcp remove telegram_files. Removing a server
does not revoke a Telegram token. If retiring it completely, remove only this
integration's installed runtime and encrypted private directory after checking
the paths locally. Do not delete the parent .codex directory or other integrations.
If a real token is ever exposed, manage revocation through your existing bot's
BotFather settings and repeat secure entry. This walkthrough never needs it in chat.

Observed build process and decisions
We inspected the current host, runtime paths, applicable instructions, and only
the relevant config metadata (server names, not private configuration contents).
We read Plugin Creator's local guidance and current official OpenAI MCP guidance.
We built and tested the sender, Windows store, masked setup, installer and sample
before any real credentials. Initial sandbox filesystem/security limitations and
a Windows PowerShell module-loading issue were recorded rather than treated as
missing user authorization. The final permission verifier uses .NET ACL APIs.
The first registration used the supported codex mcp add command. Its before/after
comparison flagged an unrelated parsed configuration difference. The initial
snapshot was not retained, so the exact difference cannot now be identified.
Inspection of OpenAI's source shows that command rewrites the whole MCP server
map; normalization is a plausible explanation, not a confirmed diagnosis. We did
not guess at or revert anyone else's settings. The final installer uses supported
direct configuration with a targeted append and an optimistic concurrent-change
check, preserves existing bytes, and rejects conflicting entries. Its regression
test includes an unrelated unknown future option, comments, and CRLF newlines.
Re-running installation left the current parsed configuration unchanged. This
does not retroactively prove preservation by the first CLI registration.
See VERIFICATION.txt for exact commands/results and remaining acceptance work.

Primary references consulted
OpenAI: shared MCP config, stdio registration, server instructions and timeouts:
https://developers.openai.com/codex/mcp
MCP protocol transport/lifecycle/tool format:
https://modelcontextprotocol.io/specification/2025-06-18/basic/transports
https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle
https://modelcontextprotocol.io/specification/2025-06-18/server/tools
Telegram: attachment upload, getMe/getChat and read-only webhook status:
https://core.telegram.org/bots/api#senddocument
https://core.telegram.org/bots/api#getme
https://core.telegram.org/bots/api#getchat
https://core.telegram.org/bots/api#getwebhookinfo
Microsoft: current-user DPAPI protection and its limitations:
https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata

OPTIONAL ADDENDUM — BOTFATHER FOR A READER WHO HAS NO BOT YET
Christopher already has a bot. No new bot was created for this integration.
This addendum is background for future tutorial readers, not a prerequisite to
repeat when an appropriate bot already exists.

In Telegram, find the official @BotFather account, send /newbot, and follow its
prompts to choose the bot's display name and available username. Keep the issued
token private. Open the new bot's private chat and press Start. Arrange a private
numeric chat ID through a trusted setup workflow before using the local form.
For an existing bot with another consumer, do not improvise by calling getUpdates
or removing a webhook; ask the owner for the ID from the established consumer.
Return to step 3 and enter the token only in the masked local setup window.
Do not use token-bearing URLs in a browser, command history, or tutorial screenshot.
Official Telegram beginner reference:
https://core.telegram.org/bots/tutorial#obtain-your-bot-token
