plugins/plugin-telegram/README.md
This plugin integrates a Telegram client with ElizaOS, allowing characters in ElizaOS to interact via Telegram. It provides an easy setup for starting the Telegram client using the provided bot token and includes basic lifecycle management.
Here are the available configuration options for the character.json file:
| Key | Type | Default | Description |
|---|---|---|---|
clients | Array | Required | Specifies the client type (e.g., ["telegram"]). |
allowDirectMessages | Boolean | false | Determines whether the bot should respond to direct messages (DMs). |
shouldOnlyJoinInAllowedGroups | Boolean | false | Ensures the bot only joins and responds in specified groups. |
allowedGroupIds | Array | [] | Lists the group IDs the bot is allowed to interact with (requires shouldOnlyJoinInAllowedGroups). |
messageTrackingLimit | Integer | 100 | Sets the maximum number of messages to track in memory for each chat. |
templates | Object | {} | Allows customization of response templates for different message scenarios. |
When you encounter this error in your logs:
error: 409: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
This indicates a fundamental architectural limitation with the Telegram Bot API. The Telegram API strictly enforces that only one active connection can exist per bot token at any given time. This is by design to ensure reliable message delivery and prevent message duplication or loss.
In ElizaOS multi-agent environments, this error commonly occurs when:
@elizaos/plugin-telegram plugin enabled in their configurationTELEGRAM_BOT_TOKEN from your environment configurationThis is not a bug in ElizaOS or the Telegram plugin, but rather a result of using a shared resource (the bot token) that can only accept one connection at a time.
<charactername>.character.jsonBelow is an example configuration file with all options:
{
"clients": ["telegram"],
"allowDirectMessages": true,
"shouldOnlyJoinInAllowedGroups": true,
"allowedGroupIds": ["-123456789", "-987654321"],
"messageTrackingLimit": 100,
"templates": {
"telegramMessageHandlerTemplate": "Your custom template here"
},
"secrets": {
"key": "<your-bot-token>"
}
}
character.json file in your project directory.shouldOnlyJoinInAllowedGroups: true and specify allowedGroupIds to ensure security..env file in the project root:TELEGRAM_BOT_TOKEN=your-bot-token
Create or modify characters/your-character.json:
{
"clients": ["telegram"],
"secrets": {
"key": "<your-bot-token>"
}
}
bun run dev
bun start --character="characters/your-character.json"
To send a message with native Telegram buttons, include an array of buttons in the message content. The following action demonstrates how to initiate a login flow using a Telegram button.
export const initAuthHandshakeAction: Action = {
name: 'INIT_AUTH_HANDSHAKE',
description: 'Initiates the identity linking and authentication flow for new users.',
validate: async (_runtime, _message, _state) => {
return _message.content.source === 'telegram';
},
handler: async (runtime, message, _state, _options, callback): Promise<boolean> => {
try {
const user = await getUser(message.userId);
if (user) return false;
callback({
text: "Let's get you set up with a new account",
buttons: [
{
text: '🔑 Authenticate with Telegram',
url: `${FRONTEND_URL}/integrations/telegram`,
kind: 'login',
},
],
}).catch((error) => {
console.error('Error sending callback:', error);
});
return true;
} catch (error) {
...
}
},
};