@ebowwa/channel-telegram 1.12.6 → 1.13.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.
Files changed (49) hide show
  1. package/README.md +78 -44
  2. package/dist/commands/index.d.ts +1 -0
  3. package/dist/commands/index.d.ts.map +1 -1
  4. package/dist/commands/index.js +3 -0
  5. package/dist/commands/index.js.map +1 -1
  6. package/dist/commands/restart.d.ts +7 -0
  7. package/dist/commands/restart.d.ts.map +1 -0
  8. package/dist/commands/restart.js +29 -0
  9. package/dist/commands/restart.js.map +1 -0
  10. package/dist/commands/settings.d.ts +8 -0
  11. package/dist/commands/settings.d.ts.map +1 -0
  12. package/dist/commands/settings.js +16 -0
  13. package/dist/commands/settings.js.map +1 -0
  14. package/dist/index.d.ts +83 -29
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +350 -712
  17. package/dist/index.js.map +1 -1
  18. package/package.json +8 -12
  19. package/src/commands/index.ts +3 -0
  20. package/src/commands/restart.ts +41 -0
  21. package/src/commands/settings.ts +24 -0
  22. package/src/index.ts +415 -823
  23. package/dist/mcp/client.d.ts +0 -50
  24. package/dist/mcp/client.d.ts.map +0 -1
  25. package/dist/mcp/client.js +0 -150
  26. package/dist/mcp/client.js.map +0 -1
  27. package/dist/mcp/index.d.ts +0 -5
  28. package/dist/mcp/index.d.ts.map +0 -1
  29. package/dist/mcp/index.js +0 -5
  30. package/dist/mcp/index.js.map +0 -1
  31. package/src/api/fetch-retry.js +0 -96
  32. package/src/api/keys.js +0 -25
  33. package/src/commands/cancel.js +0 -120
  34. package/src/commands/clear.js +0 -59
  35. package/src/commands/doppler.js +0 -118
  36. package/src/commands/git.js +0 -126
  37. package/src/commands/help.js +0 -74
  38. package/src/commands/index.js +0 -65
  39. package/src/commands/logs.js +0 -81
  40. package/src/commands/pause.js +0 -133
  41. package/src/commands/resources.js +0 -87
  42. package/src/commands/resume.js +0 -95
  43. package/src/commands/start.js +0 -68
  44. package/src/commands/status.js +0 -62
  45. package/src/commands/tools.js +0 -67
  46. package/src/commands/toolsoutput.js +0 -85
  47. package/src/commands/types.js +0 -5
  48. package/src/mcp/client.ts +0 -188
  49. package/src/mcp/index.ts +0 -5
package/README.md CHANGED
@@ -1,58 +1,92 @@
1
- # GLM Daemon Telegram Bot
1
+ # @ebowwa/channel-telegram
2
2
 
3
- Telegram adapter for GLM Daemon with ButlerAgent personality.
3
+ Pure Telegram protocol adapter implementing `ChannelConnector` from `@ebowwa/channel-types`.
4
4
 
5
- ## Setup
5
+ ## Purpose
6
6
 
7
- 1. **Install dependencies:**
8
- ```bash
9
- bun install
10
- ```
7
+ This package handles ONLY Telegram protocol operations:
8
+ - Message polling and delivery
9
+ - Typing indicators
10
+ - Long message chunking
11
+ - Access control
12
+ - Message normalization to `ChannelMessage` format
11
13
 
12
- 2. **Configure Doppler secrets:**
13
- ```
14
- TELEGRAM_BOT_TOKEN=<your-bot-token>
15
- TELEGRAM_TEST_CHAT_ID=<your-chat-id> # Optional, for test message
16
- GLM_API_KEY=<your-api-key>
17
- DOPPLER_TOKEN=<your-doppler-token>
18
- ```
14
+ **Intelligence (GLM, tools, memory) is provided by the consumer/daemon.**
19
15
 
20
- 3. **Build:**
21
- ```bash
22
- bun run build
23
- ```
16
+ ## Usage
24
17
 
25
- 4. **Run:**
26
- ```bash
27
- bun run start
28
- ```
18
+ ```typescript
19
+ import { createTelegramChannel, createTelegramConfigFromEnv } from "@ebowwa/channel-telegram";
29
20
 
30
- Or with Doppler:
31
- ```bash
32
- doppler run -- bun run start
33
- ```
21
+ const config = createTelegramConfigFromEnv();
22
+ const channel = createTelegramChannel(config);
34
23
 
35
- ## Getting Telegram Credentials
24
+ // Set message handler - daemon provides intelligence
25
+ channel.onMessage(async (message) => {
26
+ console.log(`Received: ${message.text} from ${message.sender.displayName}`);
36
27
 
37
- 1. **Create a bot:**
38
- - Message [@BotFather](https://t.me/botfather) on Telegram
39
- - Send `/newbot`
40
- - Follow the prompts
41
- - Copy the bot token (format: `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`)
28
+ // Process with your LLM/tools/memory here
29
+ const response = await yourLLM.process(message);
42
30
 
43
- 2. **Get your Chat ID:**
44
- - Message [@userinfobot](https://t.me/userinfobot) on Telegram
45
- - It will reply with your chat ID
46
- - Add this to Doppler as `TELEGRAM_TEST_CHAT_ID`
31
+ return {
32
+ content: { text: response },
33
+ replyTo: { messageId: message.messageId, channelId: message.channelId },
34
+ };
35
+ });
47
36
 
48
- ## Features
37
+ await channel.start();
38
+ ```
49
39
 
50
- - ✅ Natural conversation with ButlerAgent personality
51
- - ✅ Context-aware responses (remembers username, name)
52
- - ✅ Long message chunking (4096 char limit)
53
- - ✅ Error handling with graceful fallbacks
54
- - ✅ Test message on startup
40
+ ## Configuration
55
41
 
56
- ## Deployment
42
+ Environment variables:
57
43
 
58
- See `TICKET.md` for deployment details.
44
+ ```
45
+ TELEGRAM_BOT_TOKEN=<your-bot-token>
46
+ TELEGRAM_TEST_CHAT_ID=<chat-id> # Optional, for startup notification
47
+ TELEGRAM_ALLOWED_USERS=<user-ids> # Optional, comma-separated
48
+ TELEGRAM_ALLOWED_CHATS=<chat-ids> # Optional, comma-separated
49
+ ```
50
+
51
+ ## API
52
+
53
+ ### `TelegramChannel`
54
+
55
+ Implements `ChannelConnector`:
56
+
57
+ - `start()` - Start polling for messages
58
+ - `stop()` - Stop polling
59
+ - `onMessage(handler)` - Set message handler
60
+ - `send(response)` - Send response to channel
61
+ - `isConnected()` - Check connection status
62
+
63
+ Additional helpers:
64
+
65
+ - `sendMessage(chatId, text, options)` - Send simple message
66
+ - `sendTyping(chatId)` - Send typing indicator
67
+ - `startTypingIndicator(chatId)` - Continuous typing indicator
68
+ - `stopTypingIndicator(chatId)` - Stop typing indicator
69
+ - `isAllowed(userId, chatId)` - Check access
70
+ - `getBot()` - Get underlying TelegramBot instance
71
+
72
+ ## Architecture
73
+
74
+ ```
75
+ ┌─────────────────┐
76
+ │ Telegram API │
77
+ └────────┬────────┘
78
+
79
+ ┌────────▼────────┐
80
+ │ channel-telegram│ ← Pure protocol adapter
81
+ │ - Polling │
82
+ │ - Normalization│
83
+ │ - Chunking │
84
+ └────────┬────────┘
85
+ │ ChannelMessage
86
+ ┌────────▼────────┐
87
+ │ GLM Daemon │ ← Provides intelligence
88
+ │ - LLM │
89
+ │ - Tools/MCP │
90
+ │ - Memory │
91
+ └─────────────────┘
92
+ ```
@@ -16,6 +16,7 @@ export { registerResumeCommand } from './resume';
16
16
  export { registerQuietCommand, isQuiet, clearQuiet } from './quiet';
17
17
  export { registerVerboseCommand } from './verbose';
18
18
  export { registerInnerthoughtsCommand } from './innerthoughts';
19
+ export { register as registerRestartCommand } from './restart';
19
20
  export type { CommandRegistrar, CommandContext } from './types';
20
21
  import type TelegramBot from 'node-telegram-bot-api';
21
22
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,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AM,SAAS,CAAC;AACtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,QAAQ,IAAI,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAG/D,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEhE,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AAkBrD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,OAAO,wBAAwB,EAAE,kBAAkB,EAC3D,KAAK,EAAE,OAAO,UAAU,EAAE,IAAI,EAAE,GAC/B,IAAI,CAiBN"}
@@ -16,6 +16,8 @@ export { registerResumeCommand } from './resume';
16
16
  export { registerQuietCommand, isQuiet, clearQuiet } from './quiet';
17
17
  export { registerVerboseCommand } from './verbose';
18
18
  export { registerInnerthoughtsCommand } from './innerthoughts';
19
+ export { register as registerRestartCommand } from './restart';
20
+ import { register as importedRegisterRestart } from './restart';
19
21
  import { registerStartCommand } from './start';
20
22
  import { registerStatusCommand } from './status';
21
23
  import { registerHelpCommand } from './help';
@@ -50,5 +52,6 @@ export function registerAllCommands(bot, memory, tools) {
50
52
  registerQuietCommand(bot, memory, tools);
51
53
  registerVerboseCommand(bot, memory, tools);
52
54
  registerInnerthoughtsCommand(bot, memory, tools);
55
+ importedRegisterRestart(bot, tools);
53
56
  }
54
57
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAA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C,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7C,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC1C,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC1C,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3C,4BAA4B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * /restart command - Restart the Telegram bot systemd service
3
+ */
4
+ import TelegramBot from "node-telegram-bot-api";
5
+ import type { Tool } from "../index.js";
6
+ export declare function register(bot: TelegramBot, tools: Tool[]): void;
7
+ //# sourceMappingURL=restart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restart.d.ts","sourceRoot":"","sources":["../../src/commands/restart.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAEhD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAgC9D"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * /restart command - Restart the Telegram bot systemd service
3
+ */
4
+ import { execSync } from "child_process";
5
+ export function register(bot, tools) {
6
+ bot.onText(/\/restart(?:@[\w]+)?(?:\s+(.+))?/, async (msg, match) => {
7
+ const chatId = msg.chat.id;
8
+ const serviceName = match?.[1]?.trim() || "telegram-bot";
9
+ try {
10
+ // Restart the systemd service
11
+ execSync(`sudo systemctl restart ${serviceName}`, {
12
+ timeout: 30000,
13
+ encoding: "utf-8"
14
+ });
15
+ await bot.sendMessage(chatId, `Restarting ${serviceName} service...\n\n` +
16
+ `The bot will restart momentarily. You should see a startup message soon.`);
17
+ }
18
+ catch (error) {
19
+ if (error.message?.includes("systemctl: command not found")) {
20
+ await bot.sendMessage(chatId, "This command only works on Linux systems with systemd.\n\n" +
21
+ "On macOS, use: brew services restart telegram-bot");
22
+ }
23
+ else {
24
+ await bot.sendMessage(chatId, `Error restarting service:\n${error.message}`);
25
+ }
26
+ }
27
+ });
28
+ }
29
+ //# sourceMappingURL=restart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restart.js","sourceRoot":"","sources":["../../src/commands/restart.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,UAAU,QAAQ,CAAC,GAAgB,EAAE,KAAa;IACtD,GAAG,CAAC,MAAM,CAAC,kCAAkC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAClE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,cAAc,CAAC;QAEzD,IAAI,CAAC;YACH,8BAA8B;YAC9B,QAAQ,CAAC,0BAA0B,WAAW,EAAE,EAAE;gBAChD,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAC;YAEH,MAAM,GAAG,CAAC,WAAW,CACnB,MAAM,EACN,cAAc,WAAW,iBAAiB;gBAC1C,0EAA0E,CAC3E,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,8BAA8B,CAAC,EAAE,CAAC;gBAC5D,MAAM,GAAG,CAAC,WAAW,CACnB,MAAM,EACN,4DAA4D;oBAC5D,mDAAmD,CACpD,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,CAAC,WAAW,CACnB,MAAM,EACN,8BAA8B,KAAK,CAAC,OAAO,EAAE,CAC9C,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * /settings command - Configure bot settings
3
+ * TODO: Implement full settings UI
4
+ */
5
+ import TelegramBot from "node-telegram-bot-api";
6
+ import type { Tool } from "../index.js";
7
+ export declare function register(bot: TelegramBot, tools: Tool[]): void;
8
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/commands/settings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAe9D"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * /settings command - Configure bot settings
3
+ * TODO: Implement full settings UI
4
+ */
5
+ export function register(bot, tools) {
6
+ bot.onText(/\/settings/, async (msg) => {
7
+ const chatId = msg.chat.id;
8
+ await bot.sendMessage(chatId, "*Settings*\n\n" +
9
+ "Current configuration:\n" +
10
+ "- Model: GLM-4.7\n" +
11
+ "- Tools: " + tools.length + " available\n" +
12
+ "- MCP: " + (process.env.MCP_ENABLED === "true" ? "Enabled" : "Disabled") + "\n\n" +
13
+ "Settings will be configurable in a future update.", { parse_mode: "Markdown" });
14
+ });
15
+ }
16
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/commands/settings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,UAAU,QAAQ,CAAC,GAAgB,EAAE,KAAa;IACtD,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAE3B,MAAM,GAAG,CAAC,WAAW,CACnB,MAAM,EACN,gBAAgB;YAChB,0BAA0B;YAC1B,oBAAoB;YACpB,WAAW,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc;YAC3C,SAAS,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,MAAM;YAClF,mDAAmD,EACnD,EAAE,UAAU,EAAE,UAAU,EAAE,CAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,47 +1,101 @@
1
1
  /**
2
- * GLM Daemon Telegram Bot
2
+ * @ebowwa/channel-telegram
3
3
  *
4
- * Full-featured Telegram bot with GLM-4.7 AI, git status, Doppler integration
4
+ * Telegram channel adapter implementing ChannelConnector.
5
5
  *
6
- * Features:
7
- * - GLM-4.7 AI responses via Z.AI API
8
- * - 429 rate limit handling with exponential backoff
9
- * - /git command for git status + GitHub auth
10
- * - /doppler command for Doppler secrets status
11
- * - Rolling API key support
6
+ * This package handles:
7
+ * - Telegram protocol operations (polling, message delivery)
8
+ * - Built-in commands (/start, /help, /status, etc.)
9
+ * - Typing indicators, message chunking, access control
10
+ * - Message normalization to ChannelMessage format
11
+ *
12
+ * Intelligence (GLM, tools, memory) can be provided by:
13
+ * 1. This package (standalone mode with built-in tools)
14
+ * 2. External daemon/consumer (adapter mode via onMessage handler)
12
15
  */
13
- export interface Tool {
14
- name: string;
15
- description: string;
16
- parameters: Record<string, unknown>;
17
- handler: (args: Record<string, unknown>) => Promise<string>;
16
+ import TelegramBot from "node-telegram-bot-api";
17
+ import { type ChannelId, type ChannelResponse, type ChannelCapabilities, type MessageHandler } from "@ebowwa/channel-types";
18
+ import { ConversationMemory } from "./conversation-memory.js";
19
+ import type { Tool } from "./types.js";
20
+ export { ConversationMemory } from "./conversation-memory.js";
21
+ export { registerAllCommands, isQuiet } from "./commands/index.js";
22
+ export type { Tool } from "./types.js";
23
+ export interface TelegramConfig {
24
+ botToken: string;
25
+ testChatId?: string;
26
+ allowedUsers?: number[];
27
+ allowedChats?: number[];
28
+ /** Optional tools for command handlers (e.g., /tools command) */
29
+ tools?: Tool[];
30
+ /** Optional conversations file path */
31
+ conversationsFile?: string;
18
32
  }
19
- export declare class TelegramGLMBot {
33
+ export declare function createTelegramConfigFromEnv(): TelegramConfig;
34
+ export declare class TelegramChannel {
35
+ readonly id: ChannelId;
36
+ readonly label = "Telegram";
37
+ readonly capabilities: ChannelCapabilities;
20
38
  private bot;
39
+ private config;
21
40
  private memory;
41
+ private tools;
42
+ private messageHandler?;
22
43
  private typingIntervals;
23
- constructor(token: string);
44
+ private connected;
45
+ constructor(config: TelegramConfig);
46
+ start(): Promise<void>;
47
+ stop(): Promise<void>;
24
48
  /**
25
- * Start periodic typing indicator for a chat
26
- * Telegram typing indicator lasts ~5 seconds, so refresh every 3 seconds
49
+ * Set the message handler. The daemon/consumer provides intelligence.
27
50
  */
28
- private startTypingIndicator;
51
+ onMessage(handler: MessageHandler): void;
29
52
  /**
30
- * Stop periodic typing indicator for a chat
53
+ * Send a response back to Telegram.
31
54
  */
32
- private stopTypingIndicator;
55
+ send(response: ChannelResponse): Promise<void>;
56
+ isConnected(): boolean;
33
57
  /**
34
- * Send message, splitting if too long for Telegram (4096 char limit)
58
+ * Get the underlying TelegramBot instance for advanced operations.
35
59
  */
36
- private sendLongMessage;
37
- start(): Promise<void>;
38
- getGLMResponse(chatId: number, userMessage: string, userName: string): Promise<string>;
39
- sendTestMessage(chatId: number): Promise<void>;
40
- stop(): Promise<void>;
60
+ getBot(): TelegramBot;
61
+ /**
62
+ * Get the conversation memory.
63
+ */
64
+ getMemory(): ConversationMemory;
65
+ /**
66
+ * Send a simple text message.
67
+ */
68
+ sendMessage(chatId: number, text: string, options?: TelegramBot.SendMessageOptions): Promise<void>;
69
+ /**
70
+ * Send typing indicator.
71
+ */
72
+ sendTyping(chatId: number): Promise<void>;
41
73
  /**
42
- * Check for crash recovery - analyze previous session and report
43
- * Always sends a startup message (crash or normal)
74
+ * Start continuous typing indicator (until response is ready).
44
75
  */
45
- checkCrashAndReport(chatId: number): Promise<void>;
76
+ startTypingIndicator(chatId: number): void;
77
+ /**
78
+ * Stop typing indicator.
79
+ */
80
+ stopTypingIndicator(chatId: number): void;
81
+ /**
82
+ * Check if user/chat is allowed.
83
+ */
84
+ isAllowed(userId?: number, chatId?: number): boolean;
85
+ private setupMessageHandlers;
86
+ /**
87
+ * Register Telegram command menu
88
+ */
89
+ private registerCommands;
90
+ /**
91
+ * Normalize Telegram message to ChannelMessage format.
92
+ */
93
+ private createChannelMessage;
94
+ private extractChatId;
95
+ /**
96
+ * Send long message by splitting into chunks.
97
+ */
98
+ private sendLongMessage;
46
99
  }
100
+ export declare function createTelegramChannel(config: TelegramConfig): TelegramChannel;
47
101
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAuBH,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CA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