@elizaos/plugin-telegram 2.0.0-alpha.8 → 2.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.js +1000 -10825
- package/dist/index.js.map +1 -80
- package/package.json +19 -25
- package/dist/accounts.d.ts +0 -139
- package/dist/accounts.d.ts.map +0 -1
- package/dist/actions/deleteMessage.d.ts +0 -4
- package/dist/actions/deleteMessage.d.ts.map +0 -1
- package/dist/actions/deleteMessage.test.d.ts +0 -2
- package/dist/actions/deleteMessage.test.d.ts.map +0 -1
- package/dist/actions/editMessage.d.ts +0 -4
- package/dist/actions/editMessage.d.ts.map +0 -1
- package/dist/actions/editMessage.test.d.ts +0 -2
- package/dist/actions/editMessage.test.d.ts.map +0 -1
- package/dist/actions/index.d.ts +0 -6
- package/dist/actions/index.d.ts.map +0 -1
- package/dist/actions/sendMessage.d.ts +0 -4
- package/dist/actions/sendMessage.d.ts.map +0 -1
- package/dist/actions/sendReaction.d.ts +0 -4
- package/dist/actions/sendReaction.d.ts.map +0 -1
- package/dist/actions/sendSticker.d.ts +0 -4
- package/dist/actions/sendSticker.d.ts.map +0 -1
- package/dist/config.d.ts +0 -153
- package/dist/config.d.ts.map +0 -1
- package/dist/constants.d.ts +0 -11
- package/dist/constants.d.ts.map +0 -1
- package/dist/environment.d.ts +0 -49
- package/dist/environment.d.ts.map +0 -1
- package/dist/formatting.d.ts +0 -114
- package/dist/formatting.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/messageManager.d.ts +0 -61
- package/dist/messageManager.d.ts.map +0 -1
- package/dist/providers/chatState.d.ts +0 -4
- package/dist/providers/chatState.d.ts.map +0 -1
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/service.d.ts +0 -137
- package/dist/service.d.ts.map +0 -1
- package/dist/tests.d.ts +0 -19
- package/dist/tests.d.ts.map +0 -1
- package/dist/types.d.ts +0 -238
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -15
- package/dist/utils.d.ts.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Telegram Client Plugin for ElizaOS
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Seamless Telegram Integration**: Connects ElizaOS characters to Telegram through the bot API.
|
|
8
|
+
- **Configuration Validation**: Ensures required settings are properly configured before starting.
|
|
9
|
+
- **Startup Logging**: Logs successful initialization of the Telegram client for better debugging.
|
|
10
|
+
- **Future-proof Design**: Provides a basic structure for stopping the client (currently unsupported).
|
|
11
|
+
|
|
12
|
+
## Configuration Options
|
|
13
|
+
|
|
14
|
+
Here are the available configuration options for the `character.json` file:
|
|
15
|
+
|
|
16
|
+
| Key | Type | Default | Description |
|
|
17
|
+
| ------------------------------- | ------- | -------- | --------------------------------------------------------------------------------------------------- |
|
|
18
|
+
| `clients` | Array | Required | Specifies the client type (e.g., `["telegram"]`). |
|
|
19
|
+
| `allowDirectMessages` | Boolean | `false` | Determines whether the bot should respond to direct messages (DMs). |
|
|
20
|
+
| `shouldOnlyJoinInAllowedGroups` | Boolean | `false` | Ensures the bot only joins and responds in specified groups. |
|
|
21
|
+
| `allowedGroupIds` | Array | `[]` | Lists the group IDs the bot is allowed to interact with (requires `shouldOnlyJoinInAllowedGroups`). |
|
|
22
|
+
| `messageTrackingLimit` | Integer | `100` | Sets the maximum number of messages to track in memory for each chat. |
|
|
23
|
+
| `templates` | Object | `{}` | Allows customization of response templates for different message scenarios. |
|
|
24
|
+
|
|
25
|
+
## Error 409: Conflict in Multiple Agents Environment
|
|
26
|
+
|
|
27
|
+
When you encounter this error in your logs:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
error: 409: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
In ElizaOS multi-agent environments, this error commonly occurs when:
|
|
36
|
+
|
|
37
|
+
1. **Multiple Agents Using Same Token**: Two or more agents (such as "Eliza" and another character) each have the `@elizaos/plugin-telegram` plugin enabled in their configuration
|
|
38
|
+
2. **Simultaneous Initialization**: Each agent independently attempts to initialize its own Telegram service during startup
|
|
39
|
+
3. **Token Collision**: All agents use the same `TELEGRAM_BOT_TOKEN` from your environment configuration
|
|
40
|
+
4. **Connection Rejection**: When a second agent tries to establish a connection while another is already active, Telegram rejects it with a 409 error
|
|
41
|
+
|
|
42
|
+
This 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.
|
|
43
|
+
|
|
44
|
+
## Example `<charactername>.character.json`
|
|
45
|
+
|
|
46
|
+
Below is an example configuration file with all options:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"clients": ["telegram"],
|
|
51
|
+
"allowDirectMessages": true,
|
|
52
|
+
"shouldOnlyJoinInAllowedGroups": true,
|
|
53
|
+
"allowedGroupIds": ["-123456789", "-987654321"],
|
|
54
|
+
"messageTrackingLimit": 100,
|
|
55
|
+
"templates": {
|
|
56
|
+
"telegramMessageHandlerTemplate": "Your custom template here"
|
|
57
|
+
},
|
|
58
|
+
"secrets": {
|
|
59
|
+
"key": "<your-bot-token>"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## How to Modify Settings
|
|
65
|
+
|
|
66
|
+
1. Locate the `character.json` file in your project directory.
|
|
67
|
+
2. Update the file with the desired configuration options as shown in the example above.
|
|
68
|
+
3. Save the file and restart the bot for the changes to take effect.
|
|
69
|
+
|
|
70
|
+
## Best Practices
|
|
71
|
+
|
|
72
|
+
- **Production**: Restrict bot access with `shouldOnlyJoinInAllowedGroups: true` and specify `allowedGroupIds` to ensure security.
|
|
73
|
+
- **Token Management**: Always keep your bot token and backend tokens secure and never expose them in public repositories.
|
|
74
|
+
|
|
75
|
+
## Pre-Requisites
|
|
76
|
+
|
|
77
|
+
1. Add the bot token to the `.env` file in the project root:
|
|
78
|
+
|
|
79
|
+
```env
|
|
80
|
+
TELEGRAM_BOT_TOKEN=your-bot-token
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
2. Add the same token to your character configuration file:
|
|
84
|
+
|
|
85
|
+
Create or modify `characters/your-character.json`:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"clients": ["telegram"],
|
|
90
|
+
"secrets": {
|
|
91
|
+
"key": "<your-bot-token>"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## From the project root:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npm run dev
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Or using bun:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
bun start --character="characters/your-character.json"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Utilizing Telegram Buttons
|
|
109
|
+
|
|
110
|
+
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.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
export const initAuthHandshakeAction: Action = {
|
|
114
|
+
name: 'INIT_AUTH_HANDSHAKE',
|
|
115
|
+
description: 'Initiates the identity linking and authentication flow for new users.',
|
|
116
|
+
validate: async (_runtime, _message, _state) => {
|
|
117
|
+
return _message.content.source === 'telegram';
|
|
118
|
+
},
|
|
119
|
+
handler: async (runtime, message, _state, _options, callback): Promise<boolean> => {
|
|
120
|
+
try {
|
|
121
|
+
const user = await getUser(message.userId);
|
|
122
|
+
if (user) return false;
|
|
123
|
+
|
|
124
|
+
callback({
|
|
125
|
+
text: "Let's get you set up with a new account",
|
|
126
|
+
buttons: [
|
|
127
|
+
{
|
|
128
|
+
text: '🔑 Authenticate with Telegram',
|
|
129
|
+
url: `${FRONTEND_URL}/integrations/telegram`,
|
|
130
|
+
kind: 'login',
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
}).catch((error) => {
|
|
134
|
+
console.error('Error sending callback:', error);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return true;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
...
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { DELETE_MESSAGE_ACTION, deleteMessageAction, EDIT_MESSAGE_ACTION, editMessageAction, SEND_MESSAGE_ACTION, SEND_REACTION_ACTION, SEND_STICKER_ACTION, sendMessageAction, sendReactionAction, sendStickerAction } from "./actions";
|
|
3
|
-
import { buildTelegramSettings, type TelegramSettings, type TelegramUpdateMode, validateTelegramConfig } from "./environment";
|
|
4
|
-
import { MessageManager } from "./messageManager";
|
|
5
|
-
import { CHAT_STATE_PROVIDER, chatStateProvider } from "./providers";
|
|
6
|
-
import { TelegramService } from "./service";
|
|
7
|
-
import { type SendReactionParams, type SendReactionResult, TELEGRAM_REACTIONS, type TelegramBotInfo, type TelegramBotProbe, type TelegramContent, TelegramEventTypes, type TelegramReactionEmoji } from "./types";
|
|
8
|
-
declare const telegramPlugin: Plugin;
|
|
9
|
-
export { TelegramService, MessageManager, sendMessageAction, SEND_MESSAGE_ACTION, sendReactionAction, SEND_REACTION_ACTION, editMessageAction, EDIT_MESSAGE_ACTION, deleteMessageAction, DELETE_MESSAGE_ACTION, sendStickerAction, SEND_STICKER_ACTION, chatStateProvider, CHAT_STATE_PROVIDER, TelegramEventTypes, TELEGRAM_REACTIONS, type TelegramContent, type TelegramBotProbe, type SendReactionParams, type SendReactionResult, type TelegramBotInfo, type TelegramReactionEmoji, type TelegramSettings, type TelegramUpdateMode, buildTelegramSettings, validateTelegramConfig, };
|
|
10
|
-
export { DEFAULT_ACCOUNT_ID, isMultiAccountEnabled, listEnabledTelegramAccounts, listTelegramAccountIds, normalizeAccountId, normalizeTelegramToken, type ResolvedTelegramAccount, resolveDefaultTelegramAccountId, resolveTelegramAccount, resolveTelegramToken, type TelegramAccountRuntimeConfig, type TelegramDmConfig, type TelegramGroupRuntimeConfig, type TelegramMultiAccountConfig, type TelegramTokenResolution, type TelegramTokenSource, } from "./accounts";
|
|
11
|
-
export { buildTelegramDeepLink, buildTelegramMessageLink, type ChunkTelegramTextOpts, chunkTelegramText, escapeHtml, escapeHtmlAttr, escapeMarkdownV2, formatMediaCaption, formatTelegramChat, formatTelegramUser, formatTelegramUserMention, getChatTypeString, isChannelChat, isGroupChat, isPrivateChat, type MarkdownToTelegramOptions, markdownToTelegramChunks, markdownToTelegramHtml, markdownToTelegramHtmlChunks, parseTelegramMessageLink, resolveTelegramSystemLocation, stripHtmlTags, type TelegramFormattedChunk, truncateText, } from "./formatting";
|
|
12
|
-
export default telegramPlugin;
|
|
13
|
-
export type { TelegramAccountConfig, TelegramActionConfig, TelegramCapabilitiesConfig, TelegramChannelConfig, TelegramConfig, TelegramCustomCommand, TelegramGroupConfig, TelegramInlineButtonsScope, TelegramNetworkConfig, TelegramTopicConfig, } from "./config";
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from "@elizaos/core";
|