Skip to content

feat: support separate Telegram bots per pi session - #23

Open
musichen wants to merge 7 commits into
badlogic:mainfrom
musichen:feat/multiple-telegram-bots
Open

feat: support separate Telegram bots per pi session#23
musichen wants to merge 7 commits into
badlogic:mainfrom
musichen:feat/multiple-telegram-bots

Conversation

@musichen

Copy link
Copy Markdown

Summary

Allow separate pi sessions to use different Telegram bots without manually managing configuration filenames.

What changed

  • Add /telegram-add to validate a bot token with Telegram's getMe API and save its configuration as telegram-<bot-username>.json.
  • Rename the legacy default telegram.json configuration automatically using its saved bot username.
  • Make /telegram-connect present a selection menu when multiple bot configurations are available.
  • Show the selected bot and configuration filename in /telegram-status.
  • Support PI_TELEGRAM_CONFIG for scripted or fixed per-session bot assignment.

Each configuration retains its own token, paired user, and Telegram update offset. The existing single-bot flow still auto-connects when only one configuration exists.

Testing

  • Loaded the TypeScript extension module successfully.
  • Exercised /telegram-connect with a harness and verified discovery of two saved bot configurations.
  • Verified Telegram getMe and long-poll getUpdates requests for two local bot configurations.

@musichen

Copy link
Copy Markdown
Author

Follow-up fix: this branch now prevents duplicate Telegram replies when a bot is accidentally connected from more than one pi process, and guards against concurrent duplicate agent_end finalization for the same Telegram message.

The polling lock is keyed from a one-way hash of the bot token, supports stale-lock recovery, and is released when polling stops. A two-process regression harness verified that the second process is rejected with another pi session is already polling this bot.

agent_end fires before the agent is fully settled, so sending the next
queued turn as a fresh prompt throws 'Agent is already processing'. Pass
deliverAs: 'followUp' so pi queues it for the next run instead.
xqicxx pushed a commit to xqicxx/pi-telegram that referenced this pull request Aug 26, 2026
0.9.0: hidden settings and proactive push, queue ui
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.

1 participant