@elizaos/plugin-telegram 1.0.0-alpha.0
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 +88 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +4741 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters, aka Moon aka @lalalune
|
|
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,88 @@
|
|
|
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
|
+
## Example `<charactername>.character.json`
|
|
26
|
+
|
|
27
|
+
Below is an example configuration file with all options:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"clients": ["telegram"],
|
|
32
|
+
"allowDirectMessages": true,
|
|
33
|
+
"shouldOnlyJoinInAllowedGroups": true,
|
|
34
|
+
"allowedGroupIds": ["-123456789", "-987654321"],
|
|
35
|
+
"messageTrackingLimit": 100,
|
|
36
|
+
"templates": {
|
|
37
|
+
"telegramMessageHandlerTemplate": "Your custom template here"
|
|
38
|
+
},
|
|
39
|
+
"secrets": {
|
|
40
|
+
"key": "<your-bot-token>"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## How to Modify Settings
|
|
46
|
+
|
|
47
|
+
1. Locate the `character.json` file in your project directory.
|
|
48
|
+
2. Update the file with the desired configuration options as shown in the example above.
|
|
49
|
+
3. Save the file and restart the bot for the changes to take effect.
|
|
50
|
+
|
|
51
|
+
## Best Practices
|
|
52
|
+
|
|
53
|
+
- **Production**: Restrict bot access with `shouldOnlyJoinInAllowedGroups: true` and specify `allowedGroupIds` to ensure security.
|
|
54
|
+
- **Token Management**: Always keep your bot token and backend tokens secure and never expose them in public repositories.
|
|
55
|
+
|
|
56
|
+
## Pre-Requisites
|
|
57
|
+
|
|
58
|
+
1. Add the bot token to the `.env` file in the project root:
|
|
59
|
+
|
|
60
|
+
```env
|
|
61
|
+
TELEGRAM_BOT_TOKEN=your-bot-token
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
2. Add the same token to your character configuration file:
|
|
65
|
+
|
|
66
|
+
Create or modify `characters/your-character.json`:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"clients": ["telegram"],
|
|
71
|
+
"secrets": {
|
|
72
|
+
"key": "<your-bot-token>"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## From the project root:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm run dev
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Or using pnpm:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pnpm start --character="characters/your-character.json"
|
|
87
|
+
```
|
|
88
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IAgentRuntime, Plugin, Service } from '@elizaos/core';
|
|
2
|
+
import { Update } from '@telegraf/types';
|
|
3
|
+
import { Telegraf, Context, NarrowedContext } from 'telegraf';
|
|
4
|
+
|
|
5
|
+
declare class MessageManager {
|
|
6
|
+
bot: Telegraf<Context>;
|
|
7
|
+
protected runtime: IAgentRuntime;
|
|
8
|
+
constructor(bot: Telegraf<Context>, runtime: IAgentRuntime);
|
|
9
|
+
private processImage;
|
|
10
|
+
private sendMessageInChunks;
|
|
11
|
+
private sendMedia;
|
|
12
|
+
private splitMessage;
|
|
13
|
+
handleMessage(ctx: Context): Promise<void>;
|
|
14
|
+
handleReaction(ctx: NarrowedContext<Context<Update>, Update.MessageReactionUpdate>): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class TelegramService extends Service {
|
|
18
|
+
static serviceType: string;
|
|
19
|
+
capabilityDescription: string;
|
|
20
|
+
private bot;
|
|
21
|
+
messageManager: MessageManager;
|
|
22
|
+
private options;
|
|
23
|
+
constructor(runtime: IAgentRuntime);
|
|
24
|
+
static start(runtime: IAgentRuntime): Promise<TelegramService>;
|
|
25
|
+
static stop(runtime: IAgentRuntime): Promise<void>;
|
|
26
|
+
stop(): Promise<void>;
|
|
27
|
+
private initializeBot;
|
|
28
|
+
private isGroupAuthorized;
|
|
29
|
+
private setupMessageHandlers;
|
|
30
|
+
}
|
|
31
|
+
declare const telegramPlugin: Plugin;
|
|
32
|
+
|
|
33
|
+
export { TelegramService, telegramPlugin as default };
|