Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
Add paired Telegram messaging tool
M Shehzen0b3482e15e6d
diff --git a/src/capabilities/index.ts b/src/capabilities/index.tsindex 0f15cd44..940a5a3c 100644--- a/src/capabilities/index.ts+++ b/src/capabilities/index.ts@@ -6,5 +6,6 @@ export { createWriteFileTool } from './filesystem/write-file.js';export { createCreateFileTool } from './filesystem/create-file.js';export { createListDirTool } from './filesystem/list-dir.js';export { createDeleteFileTool } from './filesystem/delete-file.js';+export { createSendMessageTool } from './messaging/send-message.js';export { createRunCommandTool } from './shell/run-command.js';-export { BLOCKED_COMMANDS, AUTO_APPROVED_COMMANDS, NEEDS_APPROVAL_COMMANDS } from './shell/blocklist.js';\ No newline at end of file+export { BLOCKED_COMMANDS, AUTO_APPROVED_COMMANDS, NEEDS_APPROVAL_COMMANDS } from './shell/blocklist.js';diff --git a/src/capabilities/messaging/send-message.ts b/src/capabilities/messaging/send-message.tsnew file mode 100644index 00000000..6ee79c46--- /dev/null+++ b/src/capabilities/messaging/send-message.ts@@ -0,0 +1,27 @@+import { tool } from 'ai';+import { z } from 'zod';++export function createSendMessageTool(+ sendMessage: (content: string) => Promise<void>,+) {+ return tool({+ description:+ 'Send a message to the paired user through the configured outbound channel. Currently this sends only to the paired Telegram owner. Use this only when the user explicitly asks you to send something to Telegram or asks for scheduled results to be sent there.',+ parameters: z.object({+ content: z.string().describe('The message content to send to the paired Telegram owner'),+ }),+ execute: async ({ content }) => {+ const trimmed = content.trim();+ if (!trimmed) {+ return 'Error: Message content cannot be empty.';+ }++ try {+ await sendMessage(trimmed);+ return 'Message sent to the paired Telegram owner.';+ } catch (err: any) {+ return `Error sending message: ${err.message}`;+ }+ },+ });+}diff --git a/src/capabilities/registry.ts b/src/capabilities/registry.tsindex 46626a8c..437693a4 100644--- a/src/capabilities/registry.ts+++ b/src/capabilities/registry.ts@@ -7,6 +7,7 @@ import { createListDirTool } from './filesystem/list-dir.js';import { createDeleteFileTool } from './filesystem/delete-file.js';import { createEditFileTool } from './filesystem/edit-file.js';import { createSendFileTool } from './filesystem/send-file.js';+import { createSendMessageTool } from './messaging/send-message.js';import { createRunCommandTool } from './shell/run-command.js';import { createApproveCommandTool } from './shell/approve-command.js';import { createInstallSkillTool } from './skills/install-skill.js';@@ -43,6 +44,7 @@ export class CapabilityRegistry {private scheduler?: Scheduler;private tokenBudget?: TokenBudget;private sendFileHandler?: (filePath: string) => Promise<void>;+ private sendMessageHandler?: (content: string) => Promise<void>;private currentChannelId = 'cli';private currentChannelType = 'cli';private chatCommandContext?: ChatCommandContext;@@ -75,6 +77,10 @@ export class CapabilityRegistry {this.sendFileHandler = handler;}+ setSendMessageHandler(handler: (content: string) => Promise<void>): void {+ this.sendMessageHandler = handler;+ }+registerAll(): void {const manifest = this.permissions.getManifest();@@ -93,6 +99,11 @@ export class CapabilityRegistry {logger.info('Filesystem tools registered');}+ if (this.sendMessageHandler) {+ this.tools.send_message = createSendMessageTool(this.sendMessageHandler);+ logger.info('Messaging tool registered');+ }+if (manifest.capabilities.shell.enabled) {this.tools.run_command = createRunCommandTool(this.permissions);this.tools.approve_command = createApproveCommandTool(this.permissions);@@ -143,4 +154,4 @@ export class CapabilityRegistry {getSkillContext(): string {return this.skillLoader?.getSkillSummariesText() || '';}-}\ No newline at end of file+}diff --git a/src/index.ts b/src/index.tsindex 4f260c08..4378e0e7 100644--- a/src/index.ts+++ b/src/index.ts@@ -571,6 +571,22 @@ async function runAgent(isDaemon: boolean = false): Promise<void> {}});+ capabilities.setSendMessageHandler(async (content: string) => {+ const telegram = channels.get('telegram');+ const pairedChatId = config.channels.telegram.pairedChatId;+ const pairedUserId = config.channels.telegram.pairedUserId;++ if (!config.channels.telegram.enabled || !telegram) {+ throw new Error('Telegram is not configured. Add a bot token in setup or run `mercury doctor`.');+ }++ if (pairedChatId == null || pairedUserId == null) {+ throw new Error('Telegram is not paired. Complete the pairing flow with /start or /pair from the Telegram owner account.');+ }++ await telegram.send(content, `telegram:${pairedChatId}`);+ });+capabilities.registerAll();const agent = new Agent(diff --git a/src/utils/manual.ts b/src/utils/manual.tsindex 8a7d7790..a035962b 100644--- a/src/utils/manual.ts+++ b/src/utils/manual.ts@@ -19,6 +19,7 @@ export function getManual(): string {['edit_file', 'Replace specific text in a file', 'path, old_string, new_string'],['list_dir', 'List directory contents', 'path'],['delete_file', 'Delete a file', 'path'],+ ['send_message', 'Send a message to the paired Telegram owner', 'content'],['run_command', 'Execute a shell command', 'command'],['approve_command', 'Permanently approve a command type', 'command (e.g. "curl")'],['fetch_url', 'Fetch a URL and return content', 'url, format? (text/markdown)'],