@ebowwa/channel-telegram 1.15.4 → 1.15.6

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.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Telegram Command Adapter
3
+ *
4
+ * Bridges @ebowwa/channel-command definitions to Telegram bot handlers.
5
+ */
6
+ import type TelegramBot from 'node-telegram-bot-api';
7
+ import type { CommandDefinition as ChannelCommandDefinition } from '@ebowwa/channel-command';
8
+ import type { ConversationMemory } from './conversation-memory';
9
+ import type { Tool } from './types';
10
+ /**
11
+ * Convert channel-command definition to Telegram handler
12
+ */
13
+ export declare function createTelegramHandler(def: ChannelCommandDefinition, memory: ConversationMemory, tools: Tool[]): (bot: TelegramBot) => void;
14
+ /**
15
+ * Register multiple channel-command definitions with Telegram bot
16
+ */
17
+ export declare function registerChannelCommands(bot: TelegramBot, commands: ChannelCommandDefinition[], memory: ConversationMemory, tools: Tool[]): void;
18
+ //# sourceMappingURL=command-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-adapter.d.ts","sourceRoot":"","sources":["../src/command-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EACV,iBAAiB,IAAI,wBAAwB,EAG9C,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,IAAI,EAAE,GACZ,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAiD5B;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,wBAAwB,EAAE,EACpC,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,IAAI,EAAE,GACZ,IAAI,CAKN"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Telegram Command Adapter
3
+ *
4
+ * Bridges @ebowwa/channel-command definitions to Telegram bot handlers.
5
+ */
6
+ /**
7
+ * Convert channel-command definition to Telegram handler
8
+ */
9
+ export function createTelegramHandler(def, memory, tools) {
10
+ return (bot) => {
11
+ // Find telegram aliases
12
+ const telegramAliases = def.aliases.filter(a => a.channel === 'telegram');
13
+ for (const alias of telegramAliases) {
14
+ // Create regex pattern for the alias
15
+ const pattern = new RegExp(`^${escapeRegex(alias.alias)}(?:\\s+(.*))?$`);
16
+ bot.onText(pattern, async (msg, match) => {
17
+ const chatId = msg.chat.id;
18
+ const inputText = match?.[1] || '';
19
+ // Build context
20
+ const ctx = {
21
+ channel: 'telegram',
22
+ channelId: String(chatId),
23
+ input: alias.alias + (inputText ? ' ' + inputText : ''),
24
+ args: parseArgs(inputText),
25
+ message: msg,
26
+ sessionId: String(msg.from?.id),
27
+ timestamp: new Date(),
28
+ correlationId: crypto.randomUUID(),
29
+ memory,
30
+ tools: tools,
31
+ config: {},
32
+ reply: async (message, options) => {
33
+ const parseMode = options;
34
+ await bot.sendMessage(chatId, message, {
35
+ parse_mode: parseMode?.parse_mode,
36
+ });
37
+ },
38
+ };
39
+ try {
40
+ const result = await def.handler(ctx.args, ctx);
41
+ if (result.message && ctx.reply) {
42
+ await ctx.reply(result.message, { parse_mode: result.format === 'markdown' ? 'Markdown' : undefined });
43
+ }
44
+ else if (result.error && ctx.reply) {
45
+ await ctx.reply(`Error: ${result.error}`);
46
+ }
47
+ }
48
+ catch (error) {
49
+ console.error(`Command ${alias.alias} failed:`, error);
50
+ await bot.sendMessage(chatId, `Command failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
51
+ }
52
+ });
53
+ }
54
+ };
55
+ }
56
+ /**
57
+ * Register multiple channel-command definitions with Telegram bot
58
+ */
59
+ export function registerChannelCommands(bot, commands, memory, tools) {
60
+ for (const cmd of commands) {
61
+ const handler = createTelegramHandler(cmd, memory, tools);
62
+ handler(bot);
63
+ }
64
+ }
65
+ /**
66
+ * Parse simple space-separated args
67
+ */
68
+ function parseArgs(input) {
69
+ const params = {};
70
+ if (!input.trim())
71
+ return params;
72
+ const parts = input.split(/\s+/);
73
+ for (let i = 0; i < parts.length; i++) {
74
+ const part = parts[i];
75
+ if (part.includes('=')) {
76
+ const [key, value] = part.split('=');
77
+ params[key] = value;
78
+ }
79
+ else {
80
+ // Positional
81
+ params._positional = params._positional || [];
82
+ params._positional.push(part);
83
+ }
84
+ }
85
+ // If only positional, join as message
86
+ if (params._positional && Object.keys(params).length === 1) {
87
+ params.message = params._positional.join(' ');
88
+ delete params._positional;
89
+ }
90
+ return params;
91
+ }
92
+ /**
93
+ * Escape special regex characters
94
+ */
95
+ function escapeRegex(str) {
96
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
97
+ }
98
+ //# sourceMappingURL=command-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-adapter.js","sourceRoot":"","sources":["../src/command-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,GAA6B,EAC7B,MAA0B,EAC1B,KAAa;IAEb,OAAO,CAAC,GAAgB,EAAE,EAAE;QAC1B,wBAAwB;QACxB,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;QAE1E,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;YACpC,qCAAqC;YACrC,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAEzE,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,G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,CAAC;QAEtB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACrC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,aAAa;YACb,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;YAC7C,MAAM,CAAC,WAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,sCAAsC;IACtC,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,CAAC,OAAO,GAAI,MAAM,CAAC,WAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC"}
@@ -1,21 +1,16 @@
1
1
  /**
2
2
  * Command index - Single source of truth for commands
3
3
  *
4
- * Each command exports a CommandDefinition with:
5
- * - command: name (without /)
6
- * - description: for Telegram menu
7
- * - register: function to set up handler
4
+ * Uses @ebowwa/channel-command for channel-agnostic definitions
5
+ * and adapts them for Telegram.
8
6
  */
9
7
  import type TelegramBot from 'node-telegram-bot-api';
10
- import { registerResourcesCommand } from './resources';
11
- import { registerStartCommand } from './start';
12
- import { registerStatusCommand } from './status';
13
- import { registerHelpCommand } from './help';
8
+ import type { CommandRegistrar } from './types';
9
+ import type { ConversationMemory } from '../conversation-memory';
10
+ import type { Tool } from '../types';
14
11
  import { registerGitCommand } from './git';
15
12
  import { registerDopplerCommand } from './doppler';
16
13
  import { registerLogsCommand } from './logs';
17
- import { registerClearCommand } from './clear';
18
- import { registerToolsCommand } from './tools';
19
14
  import { registerCancelCommand, isCancelled, clearCancel } from './cancel';
20
15
  import { registerPauseCommand, isPaused, waitWhilePaused, clearPause } from './pause';
21
16
  import { registerResumeCommand } from './resume';
@@ -23,12 +18,15 @@ import { registerQuietCommand } from './quiet';
23
18
  import { isQuiet, clearQuiet } from '@ebowwa/channel-core';
24
19
  import { registerVerboseCommand } from './verbose';
25
20
  import { register as registerRestartCommand } from './restart';
21
+ import { registerResourcesCommand } from './resources';
22
+ import { registerPromptCommand } from './prompt';
23
+ declare const registerSettingsCommand: CommandRegistrar;
26
24
  export type { CommandDefinition, CommandRegistrar, CommandContext } from './types';
27
- export { registerStartCommand, registerStatusCommand, registerHelpCommand, registerGitCommand, registerDopplerCommand, registerLogsCommand, registerClearCommand, registerToolsCommand, registerResourcesCommand, registerCancelCommand, registerPauseCommand, registerResumeCommand, registerQuietCommand, registerVerboseCommand, registerRestartCommand, isCancelled, clearCancel, isPaused, waitWhilePaused, clearPause, isQuiet, clearQuiet, };
25
+ export { registerGitCommand, registerDopplerCommand, registerLogsCommand, registerResourcesCommand, registerCancelCommand, registerPauseCommand, registerResumeCommand, registerQuietCommand, registerVerboseCommand, registerRestartCommand, registerPromptCommand, registerSettingsCommand, isCancelled, clearCancel, isPaused, waitWhilePaused, clearPause, isQuiet, clearQuiet, };
28
26
  /**
29
27
  * Register all command handlers with the bot
30
28
  */
31
- export declare function registerAllCommands(bot: TelegramBot, memory: import('../conversation-memory').ConversationMemory, tools: import('../index').Tool[]): void;
29
+ export declare function registerAllCommands(bot: TelegramBot, memory: ConversationMemory, tools: Tool[]): void;
32
30
  /**
33
31
  * Get menu entries for Telegram's command suggestions
34
32
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;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D,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,QAAQ,IAAI,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAoB,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD,QAAA,MAAM,uBAAuB,EAAE,gBAA2E,CAAC;AAG3G,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGnF,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,QAAQ,EACR,eAAe,EACf,UAAU,EACV,OAAO,EACP,UAAU,GACX,CAAC;AAmBF;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,IAAI,EAAE,GACZ,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAmBhF"}
@@ -1,22 +1,15 @@
1
1
  /**
2
2
  * Command index - Single source of truth for commands
3
3
  *
4
- * Each command exports a CommandDefinition with:
5
- * - command: name (without /)
6
- * - description: for Telegram menu
7
- * - register: function to set up handler
4
+ * Uses @ebowwa/channel-command for channel-agnostic definitions
5
+ * and adapts them for Telegram.
8
6
  */
9
- // Import command definitions
10
- import { resourcesCommand, registerResourcesCommand } from './resources';
11
- // Legacy imports (to be migrated)
12
- import { registerStartCommand } from './start';
13
- import { registerStatusCommand } from './status';
14
- import { registerHelpCommand } from './help';
7
+ import { BUILTIN_COMMANDS, } from '@ebowwa/channel-command';
8
+ import { registerChannelCommands } from '../command-adapter';
9
+ // Legacy imports (Telegram-specific, not yet migrated)
15
10
  import { registerGitCommand } from './git';
16
11
  import { registerDopplerCommand } from './doppler';
17
12
  import { registerLogsCommand } from './logs';
18
- import { registerClearCommand } from './clear';
19
- import { registerToolsCommand } from './tools';
20
13
  import { registerCancelCommand, isCancelled, clearCancel } from './cancel';
21
14
  import { registerPauseCommand, isPaused, waitWhilePaused, clearPause } from './pause';
22
15
  import { registerResumeCommand } from './resume';
@@ -24,32 +17,35 @@ import { registerQuietCommand } from './quiet';
24
17
  import { isQuiet, clearQuiet } from '@ebowwa/channel-core';
25
18
  import { registerVerboseCommand } from './verbose';
26
19
  import { register as registerRestartCommand } from './restart';
20
+ import { resourcesCommand, registerResourcesCommand } from './resources';
21
+ import { registerPromptCommand } from './prompt';
22
+ import { register as registerSettingsCmd } from './settings';
23
+ const registerSettingsCommand = (bot, _memory, tools) => registerSettingsCmd(bot, tools);
27
24
  // Export legacy functions for backwards compatibility
28
- export { registerStartCommand, registerStatusCommand, registerHelpCommand, registerGitCommand, registerDopplerCommand, registerLogsCommand, registerClearCommand, registerToolsCommand, registerResourcesCommand, registerCancelCommand, registerPauseCommand, registerResumeCommand, registerQuietCommand, registerVerboseCommand, registerRestartCommand, isCancelled, clearCancel, isPaused, waitWhilePaused, clearPause, isQuiet, clearQuiet, };
25
+ export { registerGitCommand, registerDopplerCommand, registerLogsCommand, registerResourcesCommand, registerCancelCommand, registerPauseCommand, registerResumeCommand, registerQuietCommand, registerVerboseCommand, registerRestartCommand, registerPromptCommand, registerSettingsCommand, isCancelled, clearCancel, isPaused, waitWhilePaused, clearPause, isQuiet, clearQuiet, };
29
26
  // Command definitions with descriptions (for menu)
30
27
  const COMMAND_DEFS = [
31
- // Migrated to CommandDefinition pattern
32
- resourcesCommand,
33
- // TODO: Migrate these to CommandDefinition pattern
34
- { command: 'start', description: 'Start the bot', register: registerStartCommand },
35
- { command: 'help', description: 'Show available commands', register: registerHelpCommand },
36
- { command: 'status', description: 'Check bot status', register: registerStatusCommand },
28
+ // Telegram-specific commands (not yet migrated)
37
29
  { command: 'git', description: 'Check git status', register: registerGitCommand },
38
30
  { command: 'doppler', description: 'Check Doppler secrets', register: registerDopplerCommand },
39
31
  { command: 'logs', description: 'View recent logs', register: registerLogsCommand },
40
- { command: 'clear', description: 'Clear conversation history', register: registerClearCommand },
41
- { command: 'tools', description: 'List available tools', register: registerToolsCommand },
42
32
  { command: 'cancel', description: 'Stop current task', register: registerCancelCommand },
43
33
  { command: 'pause', description: 'Pause execution', register: registerPauseCommand },
44
34
  { command: 'resume', description: 'Resume execution', register: registerResumeCommand },
45
35
  { command: 'quiet', description: 'Hide tool logging', register: registerQuietCommand },
46
36
  { command: 'verbose', description: 'Show tool logging', register: registerVerboseCommand },
47
37
  { command: 'restart', description: 'Restart the bot service', register: registerRestartCommand },
38
+ resourcesCommand,
39
+ { command: 'prompt', description: 'Manage system prompt', register: registerPromptCommand },
40
+ { command: 'settings', description: 'Show bot configuration', register: registerSettingsCommand },
48
41
  ];
49
42
  /**
50
43
  * Register all command handlers with the bot
51
44
  */
52
45
  export function registerAllCommands(bot, memory, tools) {
46
+ // Register channel-agnostic commands from @ebowwa/channel-command
47
+ registerChannelCommands(bot, BUILTIN_COMMANDS, memory, tools);
48
+ // Register Telegram-specific commands
53
49
  for (const def of COMMAND_DEFS) {
54
50
  def.register(bot, memory, tools);
55
51
  }
@@ -58,6 +54,20 @@ export function registerAllCommands(bot, memory, tools) {
58
54
  * Get menu entries for Telegram's command suggestions
59
55
  */
60
56
  export function getCommandMenu() {
61
- return COMMAND_DEFS.map(({ command, description }) => ({ command, description }));
57
+ // Combine channel-command definitions with local ones
58
+ const channelMenu = BUILTIN_COMMANDS
59
+ .filter(cmd => cmd.channels.includes('telegram'))
60
+ .map(cmd => {
61
+ const telegramAlias = cmd.aliases.find(a => a.channel === 'telegram');
62
+ const command = telegramAlias?.alias.replace(/^\//, '') || cmd.id.name;
63
+ return { command, description: cmd.description };
64
+ });
65
+ const localMenu = COMMAND_DEFS.map(({ command, description }) => ({ command, description }));
66
+ // Merge and dedupe
67
+ const menuMap = new Map();
68
+ for (const item of [...channelMenu, ...localMenu]) {
69
+ menuMap.set(item.command, item);
70
+ }
71
+ return Array.from(menuMap.values());
62
72
  }
63
73
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,6BAA6B;AAC7B,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEzE,kCAAkC;AAClC,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,qBAAqB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW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,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,sDAAsD;IACtD,MAAM,WAAW,GAAG,gBAAgB;SACjC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SAChD,GAAG,CAAC,GAAG,CAAC,EAAE;QACT,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC;QACvE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;IACnD,CAAC,CAAC,CAAC;IAEL,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IAE7F,mBAAmB;IACnB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoD,CAAC;IAC5E,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AACtC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { isQuiet } from "../index.js";
2
- import { unlinkSync, existsSync } from "node:fs";
2
+ import { unlinkSync, existsSync, readFileSync, writeFileSync } from "node:fs";
3
3
  const PROMPT_FILE = "/root/seed/custom-prompt.md";
4
4
  const DEFAULT_PROMPT = `You are {{nodeName}} — a 24/7 AI assistant.
5
5
 
@@ -80,8 +80,12 @@ export function registerPromptCommand(bot, memory, tools) {
80
80
  async function viewPrompt(bot, chatId) {
81
81
  let promptContent = "";
82
82
  try {
83
- const file = Bun.file(PROMPT_FILE);
84
- promptContent = await file.text();
83
+ if (existsSync(PROMPT_FILE)) {
84
+ promptContent = readFileSync(PROMPT_FILE, "utf-8");
85
+ }
86
+ else {
87
+ promptContent = DEFAULT_PROMPT;
88
+ }
85
89
  }
86
90
  catch {
87
91
  // Fallback to default
@@ -96,20 +100,25 @@ async function viewPrompt(bot, chatId) {
96
100
  });
97
101
  }
98
102
  async function setCustomPrompt(newPrompt, bot, chatId) {
99
- await Bun.write(PROMPT_FILE, newPrompt);
103
+ writeFileSync(PROMPT_FILE, newPrompt, "utf-8");
100
104
  await bot.sendMessage(chatId, `Custom prompt saved (${newPrompt.length} chars).\nUse /prompt reset to restore default.`, { parse_mode: "Markdown" });
101
105
  }
102
106
  async function appendToPrompt(appendText, bot, chatId) {
103
107
  let currentPrompt = "";
104
108
  try {
105
- currentPrompt = await Bun.file(PROMPT_FILE).text();
109
+ if (existsSync(PROMPT_FILE)) {
110
+ currentPrompt = readFileSync(PROMPT_FILE, "utf-8");
111
+ }
112
+ else {
113
+ currentPrompt = DEFAULT_PROMPT;
114
+ }
106
115
  }
107
116
  catch {
108
117
  // No custom prompt, just default
109
118
  currentPrompt = DEFAULT_PROMPT;
110
119
  }
111
120
  const updatedPrompt = currentPrompt + "\n\n" + appendText;
112
- await Bun.write(PROMPT_FILE, updatedPrompt);
121
+ writeFileSync(PROMPT_FILE, updatedPrompt, "utf-8");
113
122
  await bot.sendMessage(chatId, `Prompt updated. Appended: ${appendText.length} chars.`, {
114
123
  parse_mode: "Markdown",
115
124
  });
@@ -117,14 +126,19 @@ async function appendToPrompt(appendText, bot, chatId) {
117
126
  async function prependToPrompt(prependText, bot, chatId) {
118
127
  let currentPrompt = "";
119
128
  try {
120
- currentPrompt = await Bun.file(PROMPT_FILE).text();
129
+ if (existsSync(PROMPT_FILE)) {
130
+ currentPrompt = readFileSync(PROMPT_FILE, "utf-8");
131
+ }
132
+ else {
133
+ currentPrompt = DEFAULT_PROMPT;
134
+ }
121
135
  }
122
136
  catch {
123
137
  // No custom prompt, just default
124
138
  currentPrompt = DEFAULT_PROMPT;
125
139
  }
126
140
  const updatedPrompt = prependText + "\n\n" + currentPrompt;
127
- await Bun.write(PROMPT_FILE, updatedPrompt);
141
+ writeFileSync(PROMPT_FILE, updatedPrompt, "utf-8");
128
142
  await bot.sendMessage(chatId, `Prompt updated. Prepended: ${prependText.length} chars.`, {
129
143
  parse_mode: "Markdown",
130
144
  });
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAElD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBtB,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,GAAgB,EAChB,MAA0B,EAC1B,KAAa;IAEb,kHAAkH;IAClH,GAAG,CAAC,MAAM,CAAC,wDAAwD,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACxF,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAEvC,IAAI,OA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,EAAE,GAAgB,EAAE,MAAc;IAClF,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,CAAC;QACH,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5B,aAAa,GAAG,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,aAAa,GAAG,cAAc,CAAC;QACjC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,iCAAiC;QACjC,aAAa,GAAG,cAAc,CAAC;IACjC,CAAC;IACD,MAAM,aAAa,GAAG,WAAW,GAAG,MAAM,GAAG,aAAa,CAAC;IAC3D,aAAa,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,GAAG,CAAC,WAAW,CACnB,MAAM,EACN,8BAA8B,WAAW,CAAC,MAAM,SAAS,EAAE;QAC3D,UAAU,EAAE,UAAU;KACvB,CACA,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,GAAgB,EAAE,MAAc;IACzD,IAAI,CAAC;QACH,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5B,UAAU,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC;QACD,MAAM,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,0BAA0B,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;IACxF,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,yBAAyB,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;IACvF,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebowwa/channel-telegram",
3
- "version": "1.15.4",
3
+ "version": "1.15.6",
4
4
  "description": "Pure Telegram protocol adapter implementing ChannelConnector",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,14 +40,16 @@
40
40
  "url": "https://github.com/ebowwa/codespaces/issues"
41
41
  },
42
42
  "dependencies": {
43
+ "@ebowwa/channel-command": "^1.0.3",
43
44
  "@ebowwa/channel-core": "^1.15.0",
44
45
  "@ebowwa/channel-types": "^0.2.3",
45
46
  "node-telegram-bot-api": "^0.66.0"
46
47
  },
47
48
  "devDependencies": {
48
- "@types/bun": "latest",
49
+ "@types/bun": "^1.3.10",
49
50
  "@types/node": "^22.19.11",
50
51
  "@types/node-telegram-bot-api": "^0.64.13",
52
+ "bun-types": "^1.3.10",
51
53
  "typescript": "^5.9.3"
52
54
  },
53
55
  "ownership": {
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Telegram Command Adapter
3
+ *
4
+ * Bridges @ebowwa/channel-command definitions to Telegram bot handlers.
5
+ */
6
+
7
+ import type TelegramBot from 'node-telegram-bot-api';
8
+ import type {
9
+ CommandDefinition as ChannelCommandDefinition,
10
+ CommandContext,
11
+ CommandParams,
12
+ } from '@ebowwa/channel-command';
13
+ import type { ConversationMemory } from './conversation-memory';
14
+ import type { Tool } from './types';
15
+
16
+ /**
17
+ * Convert channel-command definition to Telegram handler
18
+ */
19
+ export function createTelegramHandler(
20
+ def: ChannelCommandDefinition,
21
+ memory: ConversationMemory,
22
+ tools: Tool[]
23
+ ): (bot: TelegramBot) => void {
24
+ return (bot: TelegramBot) => {
25
+ // Find telegram aliases
26
+ const telegramAliases = def.aliases.filter(a => a.channel === 'telegram');
27
+
28
+ for (const alias of telegramAliases) {
29
+ // Create regex pattern for the alias
30
+ const pattern = new RegExp(`^${escapeRegex(alias.alias)}(?:\\s+(.*))?$`);
31
+
32
+ bot.onText(pattern, async (msg, match) => {
33
+ const chatId = msg.chat.id;
34
+ const inputText = match?.[1] || '';
35
+
36
+ // Build context
37
+ const ctx: CommandContext = {
38
+ channel: 'telegram',
39
+ channelId: String(chatId),
40
+ input: alias.alias + (inputText ? ' ' + inputText : ''),
41
+ args: parseArgs(inputText),
42
+ message: msg as unknown as CommandContext['message'],
43
+ sessionId: String(msg.from?.id),
44
+ timestamp: new Date(),
45
+ correlationId: crypto.randomUUID(),
46
+ memory,
47
+ tools: tools as unknown[],
48
+ config: {},
49
+ reply: async (message: string, options?: unknown) => {
50
+ const parseMode = options as { parse_mode?: string } | undefined;
51
+ await bot.sendMessage(chatId, message, {
52
+ parse_mode: parseMode?.parse_mode as TelegramBot.ParseMode | undefined,
53
+ });
54
+ },
55
+ };
56
+
57
+ try {
58
+ const result = await def.handler(ctx.args, ctx);
59
+
60
+ if (result.message && ctx.reply) {
61
+ await ctx.reply(result.message, { parse_mode: result.format === 'markdown' ? 'Markdown' : undefined });
62
+ } else if (result.error && ctx.reply) {
63
+ await ctx.reply(`Error: ${result.error}`);
64
+ }
65
+ } catch (error) {
66
+ console.error(`Command ${alias.alias} failed:`, error);
67
+ await bot.sendMessage(chatId, `Command failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
68
+ }
69
+ });
70
+ }
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Register multiple channel-command definitions with Telegram bot
76
+ */
77
+ export function registerChannelCommands(
78
+ bot: TelegramBot,
79
+ commands: ChannelCommandDefinition[],
80
+ memory: ConversationMemory,
81
+ tools: Tool[]
82
+ ): void {
83
+ for (const cmd of commands) {
84
+ const handler = createTelegramHandler(cmd, memory, tools);
85
+ handler(bot);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Parse simple space-separated args
91
+ */
92
+ function parseArgs(input: string): CommandParams {
93
+ const params: CommandParams = {};
94
+
95
+ if (!input.trim()) return params;
96
+
97
+ const parts = input.split(/\s+/);
98
+
99
+ for (let i = 0; i < parts.length; i++) {
100
+ const part = parts[i];
101
+
102
+ if (part.includes('=')) {
103
+ const [key, value] = part.split('=');
104
+ params[key] = value;
105
+ } else {
106
+ // Positional
107
+ params._positional = params._positional || [];
108
+ (params._positional as string[]).push(part);
109
+ }
110
+ }
111
+
112
+ // If only positional, join as message
113
+ if (params._positional && Object.keys(params).length === 1) {
114
+ params.message = (params._positional as string[]).join(' ');
115
+ delete params._positional;
116
+ }
117
+
118
+ return params;
119
+ }
120
+
121
+ /**
122
+ * Escape special regex characters
123
+ */
124
+ function escapeRegex(str: string): string {
125
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
126
+ }
@@ -1,27 +1,24 @@
1
1
  /**
2
2
  * Command index - Single source of truth for commands
3
3
  *
4
- * Each command exports a CommandDefinition with:
5
- * - command: name (without /)
6
- * - description: for Telegram menu
7
- * - register: function to set up handler
4
+ * Uses @ebowwa/channel-command for channel-agnostic definitions
5
+ * and adapts them for Telegram.
8
6
  */
9
7
 
10
8
  import type TelegramBot from 'node-telegram-bot-api';
9
+ import {
10
+ BUILTIN_COMMANDS,
11
+ registerBuiltinCommands as registerChannelBuiltinCommands,
12
+ } from '@ebowwa/channel-command';
13
+ import { registerChannelCommands } from '../command-adapter';
11
14
  import type { CommandDefinition, CommandRegistrar } from './types';
15
+ import type { ConversationMemory } from '../conversation-memory';
16
+ import type { Tool } from '../types';
12
17
 
13
- // Import command definitions
14
- import { resourcesCommand, registerResourcesCommand } from './resources';
15
-
16
- // Legacy imports (to be migrated)
17
- import { registerStartCommand } from './start';
18
- import { registerStatusCommand } from './status';
19
- import { registerHelpCommand } from './help';
18
+ // Legacy imports (Telegram-specific, not yet migrated)
20
19
  import { registerGitCommand } from './git';
21
20
  import { registerDopplerCommand } from './doppler';
22
21
  import { registerLogsCommand } from './logs';
23
- import { registerClearCommand } from './clear';
24
- import { registerToolsCommand } from './tools';
25
22
  import { registerCancelCommand, isCancelled, clearCancel } from './cancel';
26
23
  import { registerPauseCommand, isPaused, waitWhilePaused, clearPause } from './pause';
27
24
  import { registerResumeCommand } from './resume';
@@ -29,20 +26,19 @@ import { registerQuietCommand } from './quiet';
29
26
  import { isQuiet, clearQuiet } from '@ebowwa/channel-core';
30
27
  import { registerVerboseCommand } from './verbose';
31
28
  import { register as registerRestartCommand } from './restart';
29
+ import { resourcesCommand, registerResourcesCommand } from './resources';
30
+ import { registerPromptCommand } from './prompt';
31
+ import { register as registerSettingsCmd } from './settings';
32
+ const registerSettingsCommand: CommandRegistrar = (bot, _memory, tools) => registerSettingsCmd(bot, tools);
32
33
 
33
34
  // Export types
34
35
  export type { CommandDefinition, CommandRegistrar, CommandContext } from './types';
35
36
 
36
37
  // Export legacy functions for backwards compatibility
37
38
  export {
38
- registerStartCommand,
39
- registerStatusCommand,
40
- registerHelpCommand,
41
39
  registerGitCommand,
42
40
  registerDopplerCommand,
43
41
  registerLogsCommand,
44
- registerClearCommand,
45
- registerToolsCommand,
46
42
  registerResourcesCommand,
47
43
  registerCancelCommand,
48
44
  registerPauseCommand,
@@ -50,6 +46,8 @@ export {
50
46
  registerQuietCommand,
51
47
  registerVerboseCommand,
52
48
  registerRestartCommand,
49
+ registerPromptCommand,
50
+ registerSettingsCommand,
53
51
  isCancelled,
54
52
  clearCancel,
55
53
  isPaused,
@@ -61,24 +59,19 @@ export {
61
59
 
62
60
  // Command definitions with descriptions (for menu)
63
61
  const COMMAND_DEFS: CommandDefinition[] = [
64
- // Migrated to CommandDefinition pattern
65
- resourcesCommand,
66
-
67
- // TODO: Migrate these to CommandDefinition pattern
68
- { command: 'start', description: 'Start the bot', register: registerStartCommand },
69
- { command: 'help', description: 'Show available commands', register: registerHelpCommand },
70
- { command: 'status', description: 'Check bot status', register: registerStatusCommand },
62
+ // Telegram-specific commands (not yet migrated)
71
63
  { command: 'git', description: 'Check git status', register: registerGitCommand },
72
64
  { command: 'doppler', description: 'Check Doppler secrets', register: registerDopplerCommand },
73
65
  { command: 'logs', description: 'View recent logs', register: registerLogsCommand },
74
- { command: 'clear', description: 'Clear conversation history', register: registerClearCommand },
75
- { command: 'tools', description: 'List available tools', register: registerToolsCommand },
76
66
  { command: 'cancel', description: 'Stop current task', register: registerCancelCommand },
77
67
  { command: 'pause', description: 'Pause execution', register: registerPauseCommand },
78
68
  { command: 'resume', description: 'Resume execution', register: registerResumeCommand },
79
69
  { command: 'quiet', description: 'Hide tool logging', register: registerQuietCommand },
80
70
  { command: 'verbose', description: 'Show tool logging', register: registerVerboseCommand },
81
71
  { command: 'restart', description: 'Restart the bot service', register: registerRestartCommand },
72
+ resourcesCommand,
73
+ { command: 'prompt', description: 'Manage system prompt', register: registerPromptCommand },
74
+ { command: 'settings', description: 'Show bot configuration', register: registerSettingsCommand },
82
75
  ];
83
76
 
84
77
  /**
@@ -86,9 +79,13 @@ const COMMAND_DEFS: CommandDefinition[] = [
86
79
  */
87
80
  export function registerAllCommands(
88
81
  bot: TelegramBot,
89
- memory: import('../conversation-memory').ConversationMemory,
90
- tools: import('../index').Tool[]
82
+ memory: ConversationMemory,
83
+ tools: Tool[]
91
84
  ): void {
85
+ // Register channel-agnostic commands from @ebowwa/channel-command
86
+ registerChannelCommands(bot, BUILTIN_COMMANDS, memory, tools);
87
+
88
+ // Register Telegram-specific commands
92
89
  for (const def of COMMAND_DEFS) {
93
90
  def.register(bot, memory, tools);
94
91
  }
@@ -98,5 +95,22 @@ export function registerAllCommands(
98
95
  * Get menu entries for Telegram's command suggestions
99
96
  */
100
97
  export function getCommandMenu(): Array<{ command: string; description: string }> {
101
- return COMMAND_DEFS.map(({ command, description }) => ({ command, description }));
98
+ // Combine channel-command definitions with local ones
99
+ const channelMenu = BUILTIN_COMMANDS
100
+ .filter(cmd => cmd.channels.includes('telegram'))
101
+ .map(cmd => {
102
+ const telegramAlias = cmd.aliases.find(a => a.channel === 'telegram');
103
+ const command = telegramAlias?.alias.replace(/^\//, '') || cmd.id.name;
104
+ return { command, description: cmd.description };
105
+ });
106
+
107
+ const localMenu = COMMAND_DEFS.map(({ command, description }) => ({ command, description }));
108
+
109
+ // Merge and dedupe
110
+ const menuMap = new Map<string, { command: string; description: string }>();
111
+ for (const item of [...channelMenu, ...localMenu]) {
112
+ menuMap.set(item.command, item);
113
+ }
114
+
115
+ return Array.from(menuMap.values());
102
116
  }
@@ -12,7 +12,7 @@ import TelegramBot from "node-telegram-bot-api";
12
12
  import { ConversationMemory } from "../conversation-memory.js";
13
13
  import type { Tool } from "../types.js";
14
14
  import { isQuiet } from "../index.js";
15
- import { unlinkSync, existsSync } from "node:fs";
15
+ import { unlinkSync, existsSync, readFileSync, writeFileSync } from "node:fs";
16
16
 
17
17
  const PROMPT_FILE = "/root/seed/custom-prompt.md";
18
18
 
@@ -102,8 +102,11 @@ export function registerPromptCommand(
102
102
  async function viewPrompt(bot: TelegramBot, chatId: number): Promise<void> {
103
103
  let promptContent = "";
104
104
  try {
105
- const file = Bun.file(PROMPT_FILE);
106
- promptContent = await file.text();
105
+ if (existsSync(PROMPT_FILE)) {
106
+ promptContent = readFileSync(PROMPT_FILE, "utf-8");
107
+ } else {
108
+ promptContent = DEFAULT_PROMPT;
109
+ }
107
110
  } catch {
108
111
  // Fallback to default
109
112
  promptContent = DEFAULT_PROMPT;
@@ -120,7 +123,7 @@ async function viewPrompt(bot: TelegramBot, chatId: number): Promise<void> {
120
123
  }
121
124
 
122
125
  async function setCustomPrompt(newPrompt: string, bot: TelegramBot, chatId: number): Promise<void> {
123
- await Bun.write(PROMPT_FILE, newPrompt);
126
+ writeFileSync(PROMPT_FILE, newPrompt, "utf-8");
124
127
  await bot.sendMessage(
125
128
  chatId,
126
129
  `Custom prompt saved (${newPrompt.length} chars).\nUse /prompt reset to restore default.`,
@@ -131,13 +134,17 @@ async function setCustomPrompt(newPrompt: string, bot: TelegramBot, chatId: numb
131
134
  async function appendToPrompt(appendText: string, bot: TelegramBot, chatId: number): Promise<void> {
132
135
  let currentPrompt = "";
133
136
  try {
134
- currentPrompt = await Bun.file(PROMPT_FILE).text();
137
+ if (existsSync(PROMPT_FILE)) {
138
+ currentPrompt = readFileSync(PROMPT_FILE, "utf-8");
139
+ } else {
140
+ currentPrompt = DEFAULT_PROMPT;
141
+ }
135
142
  } catch {
136
143
  // No custom prompt, just default
137
144
  currentPrompt = DEFAULT_PROMPT;
138
145
  }
139
146
  const updatedPrompt = currentPrompt + "\n\n" + appendText;
140
- await Bun.write(PROMPT_FILE, updatedPrompt);
147
+ writeFileSync(PROMPT_FILE, updatedPrompt, "utf-8");
141
148
  await bot.sendMessage(
142
149
  chatId,
143
150
  `Prompt updated. Appended: ${appendText.length} chars.`, {
@@ -149,13 +156,17 @@ async function appendToPrompt(appendText: string, bot: TelegramBot, chatId: numb
149
156
  async function prependToPrompt(prependText: string, bot: TelegramBot, chatId: number): Promise<void> {
150
157
  let currentPrompt = "";
151
158
  try {
152
- currentPrompt = await Bun.file(PROMPT_FILE).text();
159
+ if (existsSync(PROMPT_FILE)) {
160
+ currentPrompt = readFileSync(PROMPT_FILE, "utf-8");
161
+ } else {
162
+ currentPrompt = DEFAULT_PROMPT;
163
+ }
153
164
  } catch {
154
165
  // No custom prompt, just default
155
166
  currentPrompt = DEFAULT_PROMPT;
156
167
  }
157
168
  const updatedPrompt = prependText + "\n\n" + currentPrompt;
158
- await Bun.write(PROMPT_FILE, updatedPrompt);
169
+ writeFileSync(PROMPT_FILE, updatedPrompt, "utf-8");
159
170
  await bot.sendMessage(
160
171
  chatId,
161
172
  `Prompt updated. Prepended: ${prependText.length} chars.`, {
package/src/plugin.ts CHANGED
@@ -198,7 +198,25 @@ const createOutboundAdapter = (
198
198
  });
199
199
  }
200
200
  }
201
- } catch (error) {
201
+ } catch (error: any) {
202
+ // Handle entity parse errors by retrying without formatting
203
+ if (error?.message?.includes("can't parse entities")) {
204
+ console.log("[TelegramPlugin] Entity parse error in updateStream, retrying without formatting");
205
+ try {
206
+ if (!stream.messageId) {
207
+ const result = await bot.sendMessage(chatId, text);
208
+ stream.messageId = result.message_id;
209
+ } else {
210
+ await bot.editMessageText(text, {
211
+ chat_id: chatId,
212
+ message_id: stream.messageId,
213
+ });
214
+ }
215
+ } catch (retryError) {
216
+ console.error(`[TelegramPlugin] updateStream fallback failed: ${(retryError as Error).message}`);
217
+ }
218
+ return;
219
+ }
202
220
  console.error(`[TelegramOutbound] Stream update error: ${(error as Error).message}`);
203
221
  }
204
222
  },
@@ -231,8 +249,26 @@ const createOutboundAdapter = (
231
249
  parse_mode: options?.parseMode as "Markdown" | "HTML",
232
250
  });
233
251
  }
234
- } catch (error) {
235
- console.error(`[TelegramOutbound] Stream finalize error: ${(error as Error).message}`);
252
+ } catch (error: any) {
253
+ // Handle entity parse errors by retrying without formatting
254
+ if (error?.message?.includes("can't parse entities")) {
255
+ console.log("[TelegramPlugin] Entity parse error in finalizeStream, retrying without formatting");
256
+ try {
257
+ if (account.nativeStreaming) {
258
+ const result = await bot.sendMessage(chatId, finalText);
259
+ messageId = result.message_id;
260
+ } else if (stream.messageId) {
261
+ await bot.editMessageText(finalText, {
262
+ chat_id: chatId,
263
+ message_id: stream.messageId,
264
+ });
265
+ }
266
+ } catch (retryError) {
267
+ console.error(`[TelegramPlugin] finalizeStream fallback failed: ${(retryError as Error).message}`);
268
+ }
269
+ } else {
270
+ console.error(`[TelegramOutbound] Stream finalize error: ${(error as Error).message}`);
271
+ }
236
272
  } finally {
237
273
  activeStreams.delete(streamId);
238
274
  }