- 10 new JS tool classes in src/tools/ (clean, no framework deps) - tools/index.js: registry-based init with env toggles - bot/index.js: 16 tool definitions + 16 handlers (was 4) - Added glob npm dependency - Tools: bash, file_edit, file_read, file_write, glob, grep, web_search, web_fetch, git, task_create/update/list, send_message, schedule_cron, delegate_agent, run_skill
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import { logger } from '../utils/logger.js';
|
|
import axios from 'axios';
|
|
|
|
export class SendMessageTool {
|
|
constructor() {
|
|
this.name = 'send_message';
|
|
this.description = 'Send a message to Telegram chat or channel';
|
|
}
|
|
|
|
async execute(args) {
|
|
const { chat_id, message, parse_mode = 'HTML' } = args;
|
|
const botToken = process.env.TELEGRAM_BOT_TOKEN;
|
|
if (!botToken) return '❌ TELEGRAM_BOT_TOKEN not set';
|
|
|
|
const target = chat_id || process.env.TELEGRAM_CHAT_ID;
|
|
if (!target) return '❌ No chat_id provided and TELEGRAM_CHAT_ID not set';
|
|
|
|
try {
|
|
const response = await axios.post(
|
|
`https://api.telegram.org/bot${botToken}/sendMessage`,
|
|
{
|
|
chat_id: target,
|
|
text: message,
|
|
parse_mode,
|
|
disable_web_page_preview: true,
|
|
},
|
|
{ timeout: 10000 }
|
|
);
|
|
|
|
return response.data.ok
|
|
? `✅ Message sent to chat ${target}`
|
|
: `❌ Telegram error: ${JSON.stringify(response.data)}`;
|
|
} catch (e) {
|
|
return `❌ Send error: ${e.message}`;
|
|
}
|
|
}
|
|
}
|