A simple proof-of-concept bot that monitors Telegram groups for token addresses and automatically executes trades via the Bankr Agent API.
Proof of Concept: This is a minimal example to demonstrate Telegram + Bankr integration. It's meant to be extended and customized for your specific use cases.
- Connects to your Telegram account (user client, not bot)
- Monitors specified groups for messages from trusted users
- Extracts EVM token addresses from messages
- Automatically executes buy orders via Bankr with limit/stop orders
┌─────────────────┐ ┌──────────────┐ ┌─────────────┐
│ Telegram Groups │────▶│ Message │────▶│ Bankr API │
│ │ │ Handlers │ │ (Execute) │
└─────────────────┘ └──────────────┘ └─────────────┘
│ │
│ ┌──────┴──────┐
│ │ Extractors │
│ │ (EVM, etc) │
│ └─────────────┘
│
┌────┴────┐
│ Registry│ ← Configure which groups to watch
└─────────┘
- Node.js 18+
- Telegram API credentials (from https://my.telegram.org)
- Bankr API key (from https://bankr.bot/api)
bun install
# or
npm installCreate a .env file:
# Telegram (get from https://my.telegram.org)
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
# Bankr
BANKR_API_KEY=bk_your_api_key
BANKR_API_URL=https://api.bankr.bot # optional, defaults to thisbun run start list-groupsThis will list all your groups/channels with their IDs.
Edit src/groups/config.ts to add your groups:
export const GROUP_HANDLERS: GroupHandlerEntry[] = [
{
chatId: -1001234567890, // Your group's chat ID (from step 3)
enabled: true,
create: (params) =>
new EVMTrustedUserHandler(
{ chatId: -1001234567890, name: params.resolvedName, enabled: true },
"trusted_username" // Only trades based on this user's messages
),
},
];bun run start
# or
npm startOn first run, you'll be prompted to authenticate with Telegram.
| Command | Description |
|---|---|
bun run start |
Run the trading bot (default) |
bun run start list-groups |
List all your groups/channels with IDs |
bun run start --verbose |
Run with debug logging |
Create new handlers in src/groups/handlers/:
export class MyCustomHandler implements GroupHandler<MyContext> {
async decide(context: MessageContext): Promise<TradeDecision<MyContext>> {
// Your logic to decide whether to trade
}
async execute(params: ExecuteParams<MyContext>): Promise<void> {
// Your trade execution logic using params.bankrClient
}
}Add extractors in src/extractors/ for different token identification strategies. Extractors receive the full MessageContext, so they can:
- Extract token patterns: EVM addresses, Solana addresses, $TICKER symbols, URLs (pump.fun, dexscreener, etc.)
- Filter by sender: Only extract from specific trusted users or verified accounts
- Analyze surrounding text: Use context clues to determine token intent (e.g., "buying X" vs "sold X")
- Apply heuristics: Combine multiple signals (message format, reply context, user history) to decide if a tradeable token is present
// Example: Extractor that only returns tokens from trusted users
export class TrustedUserExtractor implements TokenExtractor {
private trustedUsers = new Set(['alice', 'bob']);
extract(context: MessageContext): ExtractedToken[] {
// Skip if sender is not trusted
if (!this.trustedUsers.has(context.sender.username ?? '')) {
return [];
}
// Only then look for token patterns...
return this.findTokenPatterns(context.text);
}
}// Example: Extractor that checks message context for buy signals
export class BuySignalExtractor implements TokenExtractor {
extract(context: MessageContext): ExtractedToken[] {
const text = context.text.toLowerCase();
// Only extract if message indicates buying intent
const isBuySignal = text.includes('buying') ||
text.includes('aping') ||
text.includes('entry');
if (!isBuySignal) return [];
// Extract token addresses only from buy-intent messages
return this.extractAddresses(context.text);
}
}- Copy trading: Mirror trades from alpha callers
- Alert-based trading: Auto-buy tokens mentioned in signal groups
- Portfolio automation: Rebalance based on group sentiment
- Research automation: Track addresses mentioned by influencers
- Uses Telegram user client (your account), not a bot token
- Store credentials securely (never commit
.env) - The bot can execute real trades - test with small amounts first
- Consider rate limiting for production use
MIT