mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-20 23:43:07 +00:00
Compare commits
1 Commits
kenneth/te
...
kenneth/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7cb39c269 |
@@ -51,15 +51,6 @@ if (!TOKEN) {
|
||||
}
|
||||
const INBOX_DIR = join(STATE_DIR, 'inbox')
|
||||
|
||||
// Last-resort safety net — without these the process dies silently on any
|
||||
// unhandled promise rejection. With them it logs and keeps serving tools.
|
||||
process.on('unhandledRejection', err => {
|
||||
process.stderr.write(`telegram channel: unhandled rejection: ${err}\n`)
|
||||
})
|
||||
process.on('uncaughtException', err => {
|
||||
process.stderr.write(`telegram channel: uncaught exception: ${err}\n`)
|
||||
})
|
||||
|
||||
const bot = new Bot(TOKEN)
|
||||
let botUsername = ''
|
||||
|
||||
@@ -381,6 +372,11 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
||||
items: { type: 'string' },
|
||||
description: 'Absolute file paths to attach. Images send as photos (inline preview); other types as documents. Max 50MB each.',
|
||||
},
|
||||
format: {
|
||||
type: 'string',
|
||||
enum: ['text', 'markdownv2'],
|
||||
description: "Rendering mode. 'markdownv2' enables Telegram formatting (bold, italic, code, links). Caller must escape special chars per MarkdownV2 rules. Default: 'text' (plain, no escaping needed).",
|
||||
},
|
||||
},
|
||||
required: ['chat_id', 'text'],
|
||||
},
|
||||
@@ -407,6 +403,11 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
||||
chat_id: { type: 'string' },
|
||||
message_id: { type: 'string' },
|
||||
text: { type: 'string' },
|
||||
format: {
|
||||
type: 'string',
|
||||
enum: ['text', 'markdownv2'],
|
||||
description: "Rendering mode. 'markdownv2' enables Telegram formatting (bold, italic, code, links). Caller must escape special chars per MarkdownV2 rules. Default: 'text' (plain, no escaping needed).",
|
||||
},
|
||||
},
|
||||
required: ['chat_id', 'message_id', 'text'],
|
||||
},
|
||||
@@ -423,6 +424,8 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
||||
const text = args.text as string
|
||||
const reply_to = args.reply_to != null ? Number(args.reply_to) : undefined
|
||||
const files = (args.files as string[] | undefined) ?? []
|
||||
const format = (args.format as string | undefined) ?? 'text'
|
||||
const parseMode = format === 'markdownv2' ? 'MarkdownV2' as const : undefined
|
||||
|
||||
assertAllowedChat(chat_id)
|
||||
|
||||
@@ -449,6 +452,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
||||
(replyMode === 'all' || i === 0)
|
||||
const sent = await bot.api.sendMessage(chat_id, chunks[i], {
|
||||
...(shouldReplyTo ? { reply_parameters: { message_id: reply_to } } : {}),
|
||||
...(parseMode ? { parse_mode: parseMode } : {}),
|
||||
})
|
||||
sentIds.push(sent.message_id)
|
||||
}
|
||||
@@ -491,10 +495,13 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
||||
}
|
||||
case 'edit_message': {
|
||||
assertAllowedChat(args.chat_id as string)
|
||||
const editFormat = (args.format as string | undefined) ?? 'text'
|
||||
const editParseMode = editFormat === 'markdownv2' ? 'MarkdownV2' as const : undefined
|
||||
const edited = await bot.api.editMessageText(
|
||||
args.chat_id as string,
|
||||
Number(args.message_id),
|
||||
args.text as string,
|
||||
...(editParseMode ? [{ parse_mode: editParseMode }] : []),
|
||||
)
|
||||
const id = typeof edited === 'object' ? edited.message_id : args.message_id
|
||||
return { content: [{ type: 'text', text: `edited (id: ${id})` }] }
|
||||
@@ -586,7 +593,7 @@ async function handleInbound(
|
||||
|
||||
// image_path goes in meta only — an in-content "[image attached — read: PATH]"
|
||||
// annotation is forgeable by any allowlisted sender typing that string.
|
||||
mcp.notification({
|
||||
void mcp.notification({
|
||||
method: 'notifications/claude/channel',
|
||||
params: {
|
||||
content: text,
|
||||
@@ -599,25 +606,12 @@ async function handleInbound(
|
||||
...(imagePath ? { image_path: imagePath } : {}),
|
||||
},
|
||||
},
|
||||
}).catch(err => {
|
||||
process.stderr.write(`telegram channel: failed to deliver inbound to Claude: ${err}\n`)
|
||||
})
|
||||
}
|
||||
|
||||
// Without this, any throw in a message handler stops polling permanently
|
||||
// (grammy's default error handler calls bot.stop() and rethrows).
|
||||
bot.catch(err => {
|
||||
process.stderr.write(`telegram channel: handler error (polling continues): ${err.error}\n`)
|
||||
})
|
||||
|
||||
bot.start({
|
||||
void bot.start({
|
||||
onStart: info => {
|
||||
botUsername = info.username
|
||||
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
||||
},
|
||||
}).catch(err => {
|
||||
// bot.start() only rejects if polling can't begin or dies unrecoverably —
|
||||
// bad token, 409 conflict, network gone. Log it so the user isn't left
|
||||
// wondering why messages stopped arriving.
|
||||
process.stderr.write(`telegram channel: polling stopped: ${err}\n`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user