pi-telegram-multi
v0.1.0
Published
Multi-account and multi-bot Telegram DM bridge for pi: allowlist multiple Telegram users and assign a separate bot to each pi session to drive multiple coding-agent sessions in parallel.
Downloads
154
Maintainers
Readme
pi-telegram-multi
A Telegram DM bridge for pi that supports multiple authorized Telegram accounts and multiple bots - one bot assigned per pi session.
With it you can drive several coding-agent sessions in parallel from Telegram:
- Multi-account: allowlist multiple Telegram users so several accounts can message the same bot.
- Multi-bot: register multiple bots and assign a separate bot to each pi session, so each session is controlled through its own bot.
- Multi-session: run several pi sessions at once, each owned by a different bot and managed independently.
Use it when you want, for example:
- one bot for a work pi session and another for personal work
- two pi sessions running at once, each controlled through a different bot
- multiple trusted Telegram accounts that can message the same bot
This independent extension is based on badlogic/pi-telegram.
Install
Install globally for your user:
pi install git:github.com/musichen/pi-telegram-multiInstall only for the current project:
pi install -l git:github.com/musichen/pi-telegram-multiTry it for one pi run without installing it:
pi -e git:github.com/musichen/pi-telegram-multiUpdate installed pi packages later with:
pi update --extensionsExtensions run with your full system permissions. Review the source before installing it.
Create Telegram bots
- Open @BotFather.
- Run
/newbotonce for each bot you want to use. - Choose each bot's name and username.
- Copy each bot token.
First bot
Start pi and configure the first bot:
/telegram-setupPaste the token when prompted, then connect it:
/telegram-connectFrom Telegram, open that bot's DM and send /start. The first account to do this is authorized automatically.
Add another bot
For every additional bot, run this in any pi session:
/telegram-addPaste the new bot's token. The extension asks Telegram's official getMe API for the bot username and creates a configuration automatically:
~/.pi/agent/telegram-<bot-username>.jsonFor example, two configured bots create:
~/.pi/agent/telegram-codyagent1_bot.json
~/.pi/agent/telegram-codyagent2_bot.jsonThe existing legacy telegram.json file is renamed automatically on startup once its saved bot username is available.
Connect two pi sessions to two bots
Open two terminals and start pi in each.
Terminal 1
pi/telegram-connect
? Connect Telegram bot
❯ @codyagent1_bot (telegram-codyagent1_bot.json)
@codyagent2_bot (telegram-codyagent2_bot.json)Select @codyagent1_bot.
Terminal 2
pi/telegram-connect
? Connect Telegram bot
@codyagent1_bot (telegram-codyagent1_bot.json)
❯ @codyagent2_bot (telegram-codyagent2_bot.json)Select @codyagent2_bot, then DM it in Telegram and send /start from the account that should control it.
Each bot must be connected to only one pi session at a time. Telegram's polling API is not designed for two sessions to poll the same bot concurrently.
Check a session's assignment with:
/telegram-status
bot: @codyagent2_bot | config: telegram-codyagent2_bot.json | allowed users: 123456789 | polling: runningAllow multiple Telegram accounts for one bot
Each bot config has an allowlist. Add every trusted Telegram numeric user ID to allowedUserIds:
{
"allowedUserIds": [123456789, 987654321]
}Keep the existing botToken, botId, botUsername, and lastUpdateId fields in that config file. Existing configurations using the original single-user form remain supported and are migrated automatically:
{
"allowedUserId": 123456789
}After editing the allowlist, reconnect the bot:
/telegram-disconnect
/telegram-connectUse numeric Telegram user IDs, not usernames. Usernames can change. You can obtain an account ID from a bot such as @userinfobot.
Fixed bot assignment for scripts
Normally /telegram-connect displays a menu when multiple configured bots exist. For a script or fixed assignment, start pi with a specific configuration:
PI_TELEGRAM_CONFIG="$HOME/.pi/agent/telegram-codyagent1_bot.json" piThat pi process always uses @codyagent1_bot and bypasses the selection menu.
Commands
/telegram-setup Configure the current bot
/telegram-add Add another bot from its token
/telegram-connect Select and connect a configured bot
/telegram-disconnect Stop polling in the current pi session
/telegram-status Show the assigned bot, config, and connection stateLicense and attribution
This project is released under the MIT License. It is derived from pi-telegram by Mario Zechner and retains its license and attribution.
