telegram-mcp-tools 1.0.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/.env.example +3 -0
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/auth.d.ts +2 -0
- package/dist/auth.js +33 -0
- package/dist/auth.js.map +1 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/env-file.d.ts +1 -0
- package/dist/env-file.js +32 -0
- package/dist/env-file.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +283 -0
- package/dist/index.js.map +1 -0
- package/dist/telegram/chats.d.ts +3 -0
- package/dist/telegram/chats.js +10 -0
- package/dist/telegram/chats.js.map +1 -0
- package/dist/telegram/client.d.ts +2 -0
- package/dist/telegram/client.js +14 -0
- package/dist/telegram/client.js.map +1 -0
- package/dist/telegram/dialogs.d.ts +3 -0
- package/dist/telegram/dialogs.js +26 -0
- package/dist/telegram/dialogs.js.map +1 -0
- package/dist/telegram/folders.d.ts +4 -0
- package/dist/telegram/folders.js +131 -0
- package/dist/telegram/folders.js.map +1 -0
- package/dist/telegram/index.d.ts +10 -0
- package/dist/telegram/index.js +9 -0
- package/dist/telegram/index.js.map +1 -0
- package/dist/telegram/messages.d.ts +5 -0
- package/dist/telegram/messages.js +64 -0
- package/dist/telegram/messages.js.map +1 -0
- package/dist/telegram/peers.d.ts +11 -0
- package/dist/telegram/peers.js +79 -0
- package/dist/telegram/peers.js.map +1 -0
- package/dist/telegram/send.d.ts +12 -0
- package/dist/telegram/send.js +56 -0
- package/dist/telegram/send.js.map +1 -0
- package/dist/telegram/types.d.ts +49 -0
- package/dist/telegram/types.js +2 -0
- package/dist/telegram/types.js.map +1 -0
- package/dist/telegram/urls.d.ts +1 -0
- package/dist/telegram/urls.js +8 -0
- package/dist/telegram/urls.js.map +1 -0
- package/dist/telegram-client.d.ts +1 -0
- package/dist/telegram-client.js +2 -0
- package/dist/telegram-client.js.map +1 -0
- package/package.json +58 -0
package/.env.example
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ausievich
|
|
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,153 @@
|
|
|
1
|
+
# telegram-mcp-tools
|
|
2
|
+
|
|
3
|
+
A local MCP server for Cursor and Claude Desktop. It reads your Telegram subscriptions over MTProto (personal account, not a bot) and exposes channel posts to the agent for digests and natural-language questions like “what’s interesting in my Serbia travel channels this week?”
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g telegram-mcp-tools
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or run without installing (recommended for MCP):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx telegram-mcp-tools-auth # one-time login
|
|
15
|
+
npx telegram-mcp-tools # MCP server (stdio)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **10 MCP tools:** folders, dialogs, messages, digests, send message, archive/unarchive
|
|
21
|
+
- **Post links** — every message includes a `url` field (`https://t.me/...`)
|
|
22
|
+
- **Archived channels** — included when listing subscriptions
|
|
23
|
+
- **QR login** — scan from the terminal, no SMS or in-app codes
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Node.js 18+
|
|
28
|
+
- Telegram API credentials from [my.telegram.org/apps](https://my.telegram.org/apps)
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
Create a project directory, add credentials, authorize, then connect MCP.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
mkdir my-telegram-mcp && cd my-telegram-mcp
|
|
36
|
+
cp path/to/node_modules/telegram-mcp-tools/.env.example .env
|
|
37
|
+
# or from a git clone: cp .env.example .env
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Fill in `.env`:
|
|
41
|
+
|
|
42
|
+
```env
|
|
43
|
+
TELEGRAM_API_ID=12345678
|
|
44
|
+
TELEGRAM_API_HASH=your_api_hash
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Authorize (scan QR in terminal; session is saved to `.env` in the current directory):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx telegram-mcp-tools-auth
|
|
51
|
+
# or, from a git clone: npm run auth
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Verify the MCP server starts:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx telegram-mcp-tools
|
|
58
|
+
# or, from a git clone: npm run mcp
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Cursor setup
|
|
62
|
+
|
|
63
|
+
Add to `.cursor/mcp.json` in your project (where `.env` lives):
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"telegram": {
|
|
69
|
+
"command": "npx",
|
|
70
|
+
"args": ["-y", "telegram-mcp-tools"]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The server loads `.env` from the **current working directory** (your project root). You don't need to duplicate env vars in `mcp.json` if `.env` is present.
|
|
77
|
+
|
|
78
|
+
For local development from a git clone, use:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"mcpServers": {
|
|
83
|
+
"telegram": {
|
|
84
|
+
"command": "npm",
|
|
85
|
+
"args": ["run", "mcp"]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
After changing the config, reload Cursor (**Developer: Reload Window**).
|
|
92
|
+
|
|
93
|
+
## MCP tools
|
|
94
|
+
|
|
95
|
+
| Tool | Purpose |
|
|
96
|
+
|------|---------|
|
|
97
|
+
| `telegram_get_folders` | Telegram chat folders (tabs) with id and name |
|
|
98
|
+
| `telegram_create_folder` | Create a folder with channels and filter rules |
|
|
99
|
+
| `telegram_get_dialogs` | List channels, groups, and chats; optional `folder` filter |
|
|
100
|
+
| `telegram_get_messages` | Posts from one channel (@username or numeric id) |
|
|
101
|
+
| `telegram_get_recent_from_channels` | Digest from multiple channels, sorted by date |
|
|
102
|
+
| `telegram_get_recent_from_folder` | Digest from all channels/groups in a folder |
|
|
103
|
+
| `telegram_send_message` | Send formatted text to a user (@username), chat id, or `"me"` (Markdown/HTML) |
|
|
104
|
+
| `telegram_archive_chats` | Move chats/channels to Archive |
|
|
105
|
+
| `telegram_unarchive_chats` | Restore chats/channels from Archive |
|
|
106
|
+
|
|
107
|
+
Example prompts in Cursor:
|
|
108
|
+
|
|
109
|
+
> What’s new in my **Сербия** folder this week?
|
|
110
|
+
|
|
111
|
+
> List channels in folder id **2**.
|
|
112
|
+
|
|
113
|
+
When answering digest questions, the agent should cite **source links** from each post’s `url` field. See [`.cursor/skills/telegram-digest/SKILL.md`](.cursor/skills/telegram-digest/SKILL.md).
|
|
114
|
+
|
|
115
|
+
## Authorization
|
|
116
|
+
|
|
117
|
+
1. Run `npx telegram-mcp-tools-auth` from the directory where `.env` should live
|
|
118
|
+
2. On your phone: **Telegram → Settings → Devices → Link Desktop Device**
|
|
119
|
+
3. Scan the QR code in the terminal
|
|
120
|
+
4. Enter your 2FA password if prompted
|
|
121
|
+
5. `TELEGRAM_SESSION` is written to `.env` automatically
|
|
122
|
+
|
|
123
|
+
## Scripts
|
|
124
|
+
|
|
125
|
+
| Command | Description |
|
|
126
|
+
|---------|-------------|
|
|
127
|
+
| `npx telegram-mcp-tools-auth` | One-time login; saves `TELEGRAM_SESSION` to `.env` in cwd |
|
|
128
|
+
| `npx telegram-mcp-tools` | Start the MCP server (stdio) |
|
|
129
|
+
| `npm run auth` / `npm run mcp` | Same, when developing from a git clone |
|
|
130
|
+
| `npm run build` | Compile TypeScript → `dist/` |
|
|
131
|
+
|
|
132
|
+
## Security
|
|
133
|
+
|
|
134
|
+
- **Do not commit `.env`** — it contains your Telegram session (full account access)
|
|
135
|
+
- Never share `TELEGRAM_SESSION` in logs, issues, or chats
|
|
136
|
+
- Revoke API credentials or sessions at [my.telegram.org](https://my.telegram.org)
|
|
137
|
+
|
|
138
|
+
## Project layout
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
src/
|
|
142
|
+
├── config.ts # load .env from repo root
|
|
143
|
+
├── env-file.ts # update .env values after auth
|
|
144
|
+
├── telegram-client.ts # mtcute: dialogs, history, post URLs
|
|
145
|
+
├── index.ts # MCP server and tool registration
|
|
146
|
+
└── auth.ts # CLI auth (QR)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Stack
|
|
150
|
+
|
|
151
|
+
- [@mtcute/node](https://github.com/mtcute/mtcute) — MTProto client
|
|
152
|
+
- [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) — MCP
|
|
153
|
+
- TypeScript (ESM), zod, dotenv
|
package/dist/auth.d.ts
ADDED
package/dist/auth.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { MemoryStorage, TelegramClient } from "@mtcute/node";
|
|
3
|
+
import qrcode from "qrcode-terminal";
|
|
4
|
+
import { envFilePath, loadAuthConfig } from "./config.js";
|
|
5
|
+
import { updateEnvFileVariable } from "./env-file.js";
|
|
6
|
+
function printQr(url, expires) {
|
|
7
|
+
console.log(`\nScan before ${expires.toISOString()}:`);
|
|
8
|
+
qrcode.generate(url, { small: true });
|
|
9
|
+
console.log(`\nOr open manually:\n${url}\n`);
|
|
10
|
+
}
|
|
11
|
+
async function main() {
|
|
12
|
+
const { TELEGRAM_API_ID, TELEGRAM_API_HASH } = loadAuthConfig();
|
|
13
|
+
const client = new TelegramClient({
|
|
14
|
+
apiId: TELEGRAM_API_ID,
|
|
15
|
+
apiHash: TELEGRAM_API_HASH,
|
|
16
|
+
storage: new MemoryStorage(),
|
|
17
|
+
});
|
|
18
|
+
console.log("On phone: Telegram → Settings → Devices → Link Desktop Device → scan QR below.\n");
|
|
19
|
+
await client.start({
|
|
20
|
+
qrCodeHandler: printQr,
|
|
21
|
+
password: async () => (await client.input("2FA password: ")).trim(),
|
|
22
|
+
});
|
|
23
|
+
const session = await client.exportSession();
|
|
24
|
+
await updateEnvFileVariable(envFilePath, "TELEGRAM_SESSION", session);
|
|
25
|
+
console.log(`\nAuthorization successful. TELEGRAM_SESSION saved to ${envFilePath}\n`);
|
|
26
|
+
await client.destroy();
|
|
27
|
+
}
|
|
28
|
+
main().catch((error) => {
|
|
29
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
30
|
+
console.error(`Authorization failed: ${message}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,SAAS,OAAO,CAAC,GAAW,EAAE,OAAa;IACzC,OAAO,CAAC,GAAG,CAAC,iBAAiB,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IACvD,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,GAAG,cAAc,EAAE,CAAC;IAEhE,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC;QAChC,KAAK,EAAE,eAAe;QACtB,OAAO,EAAE,iBAAiB;QAC1B,OAAO,EAAE,IAAI,aAAa,EAAE;KAC7B,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACT,kFAAkF,CACnF,CAAC;IAEF,MAAM,MAAM,CAAC,KAAK,CAAC;QACjB,aAAa,EAAE,OAAO;QACtB,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE;KACpE,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;IAC7C,MAAM,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;IACtE,OAAO,CAAC,GAAG,CAAC,yDAAyD,WAAW,IAAI,CAAC,CAAC;IAEtF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const projectRoot: string;
|
|
3
|
+
export declare const envFilePath: string;
|
|
4
|
+
declare const envSchema: z.ZodObject<{
|
|
5
|
+
TELEGRAM_API_ID: z.ZodEffects<z.ZodString, number, string>;
|
|
6
|
+
TELEGRAM_API_HASH: z.ZodString;
|
|
7
|
+
} & {
|
|
8
|
+
TELEGRAM_SESSION: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
TELEGRAM_API_ID: number;
|
|
11
|
+
TELEGRAM_API_HASH: string;
|
|
12
|
+
TELEGRAM_SESSION: string;
|
|
13
|
+
}, {
|
|
14
|
+
TELEGRAM_API_ID: string;
|
|
15
|
+
TELEGRAM_API_HASH: string;
|
|
16
|
+
TELEGRAM_SESSION: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type Config = z.infer<typeof envSchema>;
|
|
19
|
+
export declare function loadConfig(): Config;
|
|
20
|
+
export declare function loadAuthConfig(): Pick<Config, "TELEGRAM_API_ID" | "TELEGRAM_API_HASH">;
|
|
21
|
+
export {};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
6
|
+
export const envFilePath = path.join(process.cwd(), ".env");
|
|
7
|
+
dotenv.config({ path: envFilePath });
|
|
8
|
+
const apiIdSchema = z
|
|
9
|
+
.string()
|
|
10
|
+
.min(1, "TELEGRAM_API_ID is required")
|
|
11
|
+
.transform((value) => {
|
|
12
|
+
const parsed = Number.parseInt(value, 10);
|
|
13
|
+
if (Number.isNaN(parsed)) {
|
|
14
|
+
throw new Error("TELEGRAM_API_ID must be a number");
|
|
15
|
+
}
|
|
16
|
+
return parsed;
|
|
17
|
+
});
|
|
18
|
+
const authEnvSchema = z.object({
|
|
19
|
+
TELEGRAM_API_ID: apiIdSchema,
|
|
20
|
+
TELEGRAM_API_HASH: z.string().min(1, "TELEGRAM_API_HASH is required"),
|
|
21
|
+
});
|
|
22
|
+
const envSchema = authEnvSchema.extend({
|
|
23
|
+
TELEGRAM_SESSION: z.string().min(1, "TELEGRAM_SESSION is required"),
|
|
24
|
+
});
|
|
25
|
+
function formatEnvError(error) {
|
|
26
|
+
return error.issues
|
|
27
|
+
.map((issue) => `${issue.path.join(".")}: ${issue.message}`)
|
|
28
|
+
.join("; ");
|
|
29
|
+
}
|
|
30
|
+
export function loadConfig() {
|
|
31
|
+
const result = envSchema.safeParse(process.env);
|
|
32
|
+
if (!result.success) {
|
|
33
|
+
throw new Error(`Invalid environment configuration: ${formatEnvError(result.error)}`);
|
|
34
|
+
}
|
|
35
|
+
return result.data;
|
|
36
|
+
}
|
|
37
|
+
export function loadAuthConfig() {
|
|
38
|
+
const result = authEnvSchema.safeParse(process.env);
|
|
39
|
+
if (!result.success) {
|
|
40
|
+
throw new Error(`Invalid environment configuration: ${formatEnvError(result.error)}`);
|
|
41
|
+
}
|
|
42
|
+
return result.data;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;AAErC,MAAM,WAAW,GAAG,CAAC;KAClB,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,EAAE,6BAA6B,CAAC;KACrC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,CAAC;AAEL,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,eAAe,EAAE,WAAW;IAC5B,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,+BAA+B,CAAC;CACtE,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC;IACrC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,8BAA8B,CAAC;CACpE,CAAC,CAAC;AAIH,SAAS,cAAc,CAAC,KAAiB;IACvC,OAAO,KAAK,CAAC,MAAM;SAChB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;SAC3D,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function updateEnvFileVariable(envPath: string, key: string, value: string): Promise<void>;
|
package/dist/env-file.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
function quoteEnvValue(value) {
|
|
3
|
+
if (/[\s#'"\\]/.test(value)) {
|
|
4
|
+
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
5
|
+
}
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
export async function updateEnvFileVariable(envPath, key, value) {
|
|
9
|
+
let content;
|
|
10
|
+
try {
|
|
11
|
+
content = await fs.readFile(envPath, "utf8");
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code === "ENOENT") {
|
|
15
|
+
throw new Error(`.env not found at ${envPath}. Create it from .env.example first.`);
|
|
16
|
+
}
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
const line = `${key}=${quoteEnvValue(value)}`;
|
|
20
|
+
const pattern = new RegExp(`^${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}=.*$`, "m");
|
|
21
|
+
if (pattern.test(content)) {
|
|
22
|
+
content = content.replace(pattern, line);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (content.length > 0 && !content.endsWith("\n")) {
|
|
26
|
+
content += "\n";
|
|
27
|
+
}
|
|
28
|
+
content += `${line}\n`;
|
|
29
|
+
}
|
|
30
|
+
await fs.writeFile(envPath, content, "utf8");
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=env-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../src/env-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAe,EACf,GAAW,EACX,KAAa;IAEb,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,sCAAsC,CAAC,CAAC;QACtF,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;IAC9C,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEtF,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,IAAI,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,GAAG,IAAI,IAAI,CAAC;IACzB,CAAC;IAED,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { loadConfig } from "./config.js";
|
|
6
|
+
import { archiveChats, createTelegramFolder, fetchDialogs, fetchFolders, fetchMessages, fetchRecentFromChannels, fetchRecentFromFolder, getTelegramClient, sendTelegramMessage, unarchiveChats, } from "./telegram-client.js";
|
|
7
|
+
const channelIdsSchema = z
|
|
8
|
+
.array(z.string().min(1))
|
|
9
|
+
.min(1)
|
|
10
|
+
.max(100)
|
|
11
|
+
.describe("List of @usernames or numeric ids");
|
|
12
|
+
const folderSchema = z
|
|
13
|
+
.union([z.string().min(1), z.number().int()])
|
|
14
|
+
.describe("Folder id (e.g. 2) or folder name (e.g. Сербия). Use telegram_get_folders to list.");
|
|
15
|
+
const config = loadConfig();
|
|
16
|
+
const telegramClientPromise = getTelegramClient(config.TELEGRAM_API_ID, config.TELEGRAM_API_HASH, config.TELEGRAM_SESSION);
|
|
17
|
+
const server = new McpServer({
|
|
18
|
+
name: "telegram-mcp",
|
|
19
|
+
version: "1.0.0",
|
|
20
|
+
});
|
|
21
|
+
server.registerTool("telegram_archive_chats", {
|
|
22
|
+
description: "Move one or more chats/channels to Telegram Archive.",
|
|
23
|
+
inputSchema: {
|
|
24
|
+
channelIds: channelIdsSchema,
|
|
25
|
+
},
|
|
26
|
+
}, async ({ channelIds }) => {
|
|
27
|
+
const client = await telegramClientPromise;
|
|
28
|
+
await archiveChats(client, channelIds);
|
|
29
|
+
return {
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: JSON.stringify({ archived: channelIds }, null, 2),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
server.registerTool("telegram_unarchive_chats", {
|
|
39
|
+
description: "Restore one or more chats/channels from Telegram Archive.",
|
|
40
|
+
inputSchema: {
|
|
41
|
+
channelIds: channelIdsSchema,
|
|
42
|
+
},
|
|
43
|
+
}, async ({ channelIds }) => {
|
|
44
|
+
const client = await telegramClientPromise;
|
|
45
|
+
await unarchiveChats(client, channelIds);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: "text",
|
|
50
|
+
text: JSON.stringify({ unarchived: channelIds }, null, 2),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
server.registerTool("telegram_create_folder", {
|
|
56
|
+
description: "Creates a new Telegram chat folder with optional channels and filter rules.",
|
|
57
|
+
inputSchema: {
|
|
58
|
+
name: z
|
|
59
|
+
.string()
|
|
60
|
+
.min(1)
|
|
61
|
+
.max(12)
|
|
62
|
+
.describe("Folder name (max 12 UTF-8 characters, Telegram limit)"),
|
|
63
|
+
includeChannels: z
|
|
64
|
+
.array(z.string().min(1))
|
|
65
|
+
.max(100)
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("Channels/groups to include (@username or numeric id)"),
|
|
68
|
+
excludeChannels: z
|
|
69
|
+
.array(z.string().min(1))
|
|
70
|
+
.max(100)
|
|
71
|
+
.optional()
|
|
72
|
+
.describe("Channels/groups to exclude (@username or numeric id)"),
|
|
73
|
+
emoticon: z
|
|
74
|
+
.string()
|
|
75
|
+
.optional()
|
|
76
|
+
.describe("Folder icon emoji (e.g. ✈️)"),
|
|
77
|
+
includeAllBroadcasts: z
|
|
78
|
+
.boolean()
|
|
79
|
+
.optional()
|
|
80
|
+
.describe("Auto-include all channels"),
|
|
81
|
+
includeAllGroups: z
|
|
82
|
+
.boolean()
|
|
83
|
+
.optional()
|
|
84
|
+
.describe("Auto-include all groups"),
|
|
85
|
+
includeAllContacts: z.boolean().optional(),
|
|
86
|
+
includeAllNonContacts: z.boolean().optional(),
|
|
87
|
+
includeAllBots: z.boolean().optional(),
|
|
88
|
+
excludeMuted: z.boolean().optional(),
|
|
89
|
+
excludeRead: z.boolean().optional(),
|
|
90
|
+
excludeArchived: z.boolean().optional(),
|
|
91
|
+
},
|
|
92
|
+
}, async ({ name, includeChannels, excludeChannels, emoticon, includeAllBroadcasts, includeAllGroups, includeAllContacts, includeAllNonContacts, includeAllBots, excludeMuted, excludeRead, excludeArchived, }) => {
|
|
93
|
+
const client = await telegramClientPromise;
|
|
94
|
+
const includeAll = {};
|
|
95
|
+
if (includeAllBroadcasts) {
|
|
96
|
+
includeAll.broadcasts = true;
|
|
97
|
+
}
|
|
98
|
+
if (includeAllGroups) {
|
|
99
|
+
includeAll.groups = true;
|
|
100
|
+
}
|
|
101
|
+
if (includeAllContacts) {
|
|
102
|
+
includeAll.contacts = true;
|
|
103
|
+
}
|
|
104
|
+
if (includeAllNonContacts) {
|
|
105
|
+
includeAll.nonContacts = true;
|
|
106
|
+
}
|
|
107
|
+
if (includeAllBots) {
|
|
108
|
+
includeAll.bots = true;
|
|
109
|
+
}
|
|
110
|
+
const exclude = {};
|
|
111
|
+
if (excludeMuted) {
|
|
112
|
+
exclude.muted = true;
|
|
113
|
+
}
|
|
114
|
+
if (excludeRead) {
|
|
115
|
+
exclude.read = true;
|
|
116
|
+
}
|
|
117
|
+
if (excludeArchived) {
|
|
118
|
+
exclude.archived = true;
|
|
119
|
+
}
|
|
120
|
+
const folder = await createTelegramFolder(client, {
|
|
121
|
+
name,
|
|
122
|
+
includeChannels,
|
|
123
|
+
excludeChannels,
|
|
124
|
+
emoticon,
|
|
125
|
+
includeAll: Object.keys(includeAll).length > 0 ? includeAll : undefined,
|
|
126
|
+
exclude: Object.keys(exclude).length > 0 ? exclude : undefined,
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
content: [{ type: "text", text: JSON.stringify(folder, null, 2) }],
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
server.registerTool("telegram_get_folders", {
|
|
133
|
+
description: "Returns the list of Telegram chat folders (tabs) configured in the user's account.",
|
|
134
|
+
inputSchema: {},
|
|
135
|
+
}, async () => {
|
|
136
|
+
const client = await telegramClientPromise;
|
|
137
|
+
const folders = await fetchFolders(client);
|
|
138
|
+
return {
|
|
139
|
+
content: [{ type: "text", text: JSON.stringify(folders, null, 2) }],
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
server.registerTool("telegram_get_dialogs", {
|
|
143
|
+
description: "Returns dialogs (channels, groups, chats) the user is subscribed to. Optionally filter by Telegram folder.",
|
|
144
|
+
inputSchema: {
|
|
145
|
+
limit: z
|
|
146
|
+
.number()
|
|
147
|
+
.int()
|
|
148
|
+
.positive()
|
|
149
|
+
.max(500)
|
|
150
|
+
.optional()
|
|
151
|
+
.describe("Max dialogs to return (default 100, max 500)"),
|
|
152
|
+
folder: folderSchema
|
|
153
|
+
.optional()
|
|
154
|
+
.describe("Folder id or name. Omit for all chats."),
|
|
155
|
+
},
|
|
156
|
+
}, async ({ limit, folder }) => {
|
|
157
|
+
const client = await telegramClientPromise;
|
|
158
|
+
const dialogs = await fetchDialogs(client, limit ?? 100, folder);
|
|
159
|
+
return {
|
|
160
|
+
content: [{ type: "text", text: JSON.stringify(dialogs, null, 2) }],
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
server.registerTool("telegram_get_messages", {
|
|
164
|
+
description: "Returns recent messages from a single channel or chat. Each message includes a `url` field linking to the original Telegram post — always cite these links when summarizing for the user.",
|
|
165
|
+
inputSchema: {
|
|
166
|
+
channelId: z
|
|
167
|
+
.string()
|
|
168
|
+
.min(1)
|
|
169
|
+
.describe("Numeric ID or @username of the channel or chat"),
|
|
170
|
+
limit: z
|
|
171
|
+
.number()
|
|
172
|
+
.int()
|
|
173
|
+
.positive()
|
|
174
|
+
.max(100)
|
|
175
|
+
.optional()
|
|
176
|
+
.describe("Messages to fetch (default 20, max 100)"),
|
|
177
|
+
sinceHours: z
|
|
178
|
+
.number()
|
|
179
|
+
.int()
|
|
180
|
+
.positive()
|
|
181
|
+
.max(168)
|
|
182
|
+
.optional()
|
|
183
|
+
.describe("Only messages from last N hours (max 168)"),
|
|
184
|
+
},
|
|
185
|
+
}, async ({ channelId, limit, sinceHours }) => {
|
|
186
|
+
const client = await telegramClientPromise;
|
|
187
|
+
const messages = await fetchMessages(client, channelId, limit ?? 20, sinceHours);
|
|
188
|
+
return {
|
|
189
|
+
content: [{ type: "text", text: JSON.stringify(messages, null, 2) }],
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
server.registerTool("telegram_get_recent_from_folder", {
|
|
193
|
+
description: "Fetches recent messages from all channels and groups in a Telegram folder, sorted by date descending. Each message includes a `url` field — always cite source links when summarizing for the user.",
|
|
194
|
+
inputSchema: {
|
|
195
|
+
folder: folderSchema,
|
|
196
|
+
sinceHours: z
|
|
197
|
+
.number()
|
|
198
|
+
.int()
|
|
199
|
+
.positive()
|
|
200
|
+
.max(168)
|
|
201
|
+
.optional()
|
|
202
|
+
.describe("Last N hours (default 24, max 168)"),
|
|
203
|
+
limitPerChannel: z
|
|
204
|
+
.number()
|
|
205
|
+
.int()
|
|
206
|
+
.positive()
|
|
207
|
+
.max(100)
|
|
208
|
+
.optional()
|
|
209
|
+
.describe("Max messages per channel (default 50, max 100)"),
|
|
210
|
+
},
|
|
211
|
+
}, async ({ folder, sinceHours, limitPerChannel }) => {
|
|
212
|
+
const client = await telegramClientPromise;
|
|
213
|
+
const messages = await fetchRecentFromFolder(client, folder, sinceHours ?? 24, limitPerChannel ?? 50);
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: "text", text: JSON.stringify(messages, null, 2) }],
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
server.registerTool("telegram_send_message", {
|
|
219
|
+
description: "Send a formatted text message to a Telegram user, group, or channel. Accepts @username, numeric id, or \"me\" (Saved Messages). Supports Markdown and HTML. Long plain text is split automatically; formatted messages must fit in 4096 chars.",
|
|
220
|
+
inputSchema: {
|
|
221
|
+
chatId: z
|
|
222
|
+
.string()
|
|
223
|
+
.min(1)
|
|
224
|
+
.describe('Recipient: @username, numeric id, or "me" for Saved Messages'),
|
|
225
|
+
text: z
|
|
226
|
+
.string()
|
|
227
|
+
.min(1)
|
|
228
|
+
.max(50000)
|
|
229
|
+
.describe("Message body. Use Markdown links like [label](https://t.me/...) for digests."),
|
|
230
|
+
format: z
|
|
231
|
+
.enum(["plain", "markdown", "html"])
|
|
232
|
+
.optional()
|
|
233
|
+
.describe('Formatting: "markdown" (default), "html", or "plain"'),
|
|
234
|
+
},
|
|
235
|
+
}, async ({ chatId, text, format }) => {
|
|
236
|
+
const client = await telegramClientPromise;
|
|
237
|
+
const result = await sendTelegramMessage(client, chatId, text, {
|
|
238
|
+
format: format ?? "markdown",
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
server.registerTool("telegram_get_recent_from_channels", {
|
|
245
|
+
description: "Fetches messages from multiple channels at once and returns them sorted by date descending. Each message includes a `url` field — always cite source links when summarizing for the user.",
|
|
246
|
+
inputSchema: {
|
|
247
|
+
channelIds: z
|
|
248
|
+
.array(z.string().min(1))
|
|
249
|
+
.min(1)
|
|
250
|
+
.max(50)
|
|
251
|
+
.describe("List of IDs or @usernames (max 50)"),
|
|
252
|
+
sinceHours: z
|
|
253
|
+
.number()
|
|
254
|
+
.int()
|
|
255
|
+
.positive()
|
|
256
|
+
.max(168)
|
|
257
|
+
.optional()
|
|
258
|
+
.describe("Last N hours (default 24, max 168)"),
|
|
259
|
+
limitPerChannel: z
|
|
260
|
+
.number()
|
|
261
|
+
.int()
|
|
262
|
+
.positive()
|
|
263
|
+
.max(100)
|
|
264
|
+
.optional()
|
|
265
|
+
.describe("Max messages per channel (default 50, max 100)"),
|
|
266
|
+
},
|
|
267
|
+
}, async ({ channelIds, sinceHours, limitPerChannel }) => {
|
|
268
|
+
const client = await telegramClientPromise;
|
|
269
|
+
const messages = await fetchRecentFromChannels(client, channelIds, sinceHours ?? 24, limitPerChannel ?? 50);
|
|
270
|
+
return {
|
|
271
|
+
content: [{ type: "text", text: JSON.stringify(messages, null, 2) }],
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
async function main() {
|
|
275
|
+
const transport = new StdioServerTransport();
|
|
276
|
+
await server.connect(transport);
|
|
277
|
+
}
|
|
278
|
+
main().catch((error) => {
|
|
279
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
280
|
+
console.error(`MCP server failed to start: ${message}`);
|
|
281
|
+
process.exit(1);
|
|
282
|
+
});
|
|
283
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,MAAM,gBAAgB,GAAG,CAAC;KACvB,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KACxB,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,GAAG,CAAC;KACR,QAAQ,CAAC,mCAAmC,CAAC,CAAC;AAEjD,MAAM,YAAY,GAAG,CAAC;KACnB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;KAC5C,QAAQ,CAAC,oFAAoF,CAAC,CAAC;AAElG,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;AAC5B,MAAM,qBA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C;IACF,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,KAAK,CAAC,+BAA+B,OAAO,EAAE,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { normalizeChannelRef } from "./peers.js";
|
|
2
|
+
export async function archiveChats(telegramClient, channelIds) {
|
|
3
|
+
const peers = channelIds.map((channelId) => normalizeChannelRef(channelId));
|
|
4
|
+
await telegramClient.archiveChats(peers);
|
|
5
|
+
}
|
|
6
|
+
export async function unarchiveChats(telegramClient, channelIds) {
|
|
7
|
+
const peers = channelIds.map((channelId) => normalizeChannelRef(channelId));
|
|
8
|
+
await telegramClient.unarchiveChats(peers);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=chats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chats.js","sourceRoot":"","sources":["../../src/telegram/chats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAA8B,EAC9B,UAAoB;IAEpB,MAAM,KAAK,GAAoB,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAC1D,mBAAmB,CAAC,SAAS,CAAC,CAC/B,CAAC;IACF,MAAM,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,cAA8B,EAC9B,UAAoB;IAEpB,MAAM,KAAK,GAAoB,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAC1D,mBAAmB,CAAC,SAAS,CAAC,CAC/B,CAAC;IACF,MAAM,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC"}
|