Add tguser CLI for sending Telegram messages#150
Conversation
Implements a GramJS-based CLI tool that sends Telegram messages as a real user account (MTProto), required by test-bot.sh for Telegram platform testing. Session is persisted in ~/.tguser/session. https://claude.ai/code/session_01CbMGHLawRiDRhC2euMdR8U
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1793e98beb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stderr, | ||
| }); |
There was a problem hiding this comment.
Prompt against TTY for first-time authentication
The prompt() helper binds readline to process.stdin/process.stderr; when tguser is invoked by scripts/test-bot.sh (which runs tguser send ... inside command substitution with 2>&1), those streams are captured so phone/code prompts are not visible and first-time login appears to hang. This blocks the documented Telegram test flow for fresh sessions unless users do an out-of-band manual auth step; reading/writing via /dev/tty (or detecting non-interactive mode and failing with guidance) avoids that.
Useful? React with 👍 / 👎.
| saveSession(client.session.save() as unknown as string); | ||
| console.error("Session saved to", SESSION_FILE); | ||
| } else { | ||
| await client.connect(); |
There was a problem hiding this comment.
Re-authenticate when persisted session is invalid
When a saved session exists, the code only calls client.connect() and skips client.start(). If ~/.tguser/session is revoked or corrupted, sends will keep failing with auth errors on every run and the CLI never recovers automatically, forcing users to manually delete the session file. Adding a fallback to interactive auth on connect/auth failure would make this command resilient.
Useful? React with 👍 / 👎.
Description
Add a new
tgusercommand-line tool for sending messages via Telegram user accounts. This tool provides a simple interface to authenticate with Telegram and send messages to peers, with session persistence to avoid repeated authentication.The implementation includes:
scripts/tguser.ts) using thetelegramlibraryscripts/tguser) for convenient execution viabun run~/.tguser/sessionType of Change
Testing
TG_API_IDandTG_API_HASHenvironment variablesbun run scripts/tguser send <peer> <message>for initial authenticationChecklist
Additional Notes
The tool requires Telegram API credentials from https://my.telegram.org and uses the
telegramlibrary for client functionality. Session files are stored with restricted permissions (0o600) for security.https://claude.ai/code/session_01CbMGHLawRiDRhC2euMdR8U