Skip to content

Add tguser CLI for sending Telegram messages#150

Closed
buremba wants to merge 1 commit into
mainfrom
claude/test-bot-prod-GkQqM
Closed

Add tguser CLI for sending Telegram messages#150
buremba wants to merge 1 commit into
mainfrom
claude/test-bot-prod-GkQqM

Conversation

@buremba
Copy link
Copy Markdown
Member

@buremba buremba commented Mar 4, 2026

Description

Add a new tguser command-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:

  • TypeScript CLI script (scripts/tguser.ts) using the telegram library
  • Bash wrapper (scripts/tguser) for convenient execution via bun run
  • Session management with persistent storage in ~/.tguser/session
  • Interactive authentication flow (phone number, auth code, 2FA password)
  • Support for sending messages to any peer (user, group, channel)

Type of Change

  • New feature (non-breaking change which adds functionality)

Testing

  • No automated tests needed for this CLI tool
  • Manual testing can be performed by:
    1. Setting TG_API_ID and TG_API_HASH environment variables
    2. Running bun run scripts/tguser send <peer> <message> for initial authentication
    3. Verifying subsequent runs use the persisted session without prompting

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Additional Notes

The tool requires Telegram API credentials from https://my.telegram.org and uses the telegram library for client functionality. Session files are stored with restricted permissions (0o600) for security.

https://claude.ai/code/session_01CbMGHLawRiDRhC2euMdR8U

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
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread scripts/tguser.ts
Comment on lines +26 to +29
const rl = readline.createInterface({
input: process.stdin,
output: process.stderr,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread scripts/tguser.ts
saveSession(client.session.save() as unknown as string);
console.error("Session saved to", SESSION_FILE);
} else {
await client.connect();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@buremba buremba closed this Mar 4, 2026
buremba added a commit that referenced this pull request May 17, 2026
Includes:
- #150 PATH-based agent detection (replaces MCP session inference)
- #152 auto-pick default agent when defaultAgent is unset
- #155 distinct SF Symbol icons per CLI agent kind
- #154 WATCHERS section in menubar with last-fired + manual trigger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants