mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-21 11:53:08 +00:00
Compare commits
1 Commits
kenneth/te
...
kenneth/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2aa90a8387 |
@@ -304,7 +304,7 @@ function checkApprovals(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!STATIC) setInterval(checkApprovals, 5000)
|
if (!STATIC) setInterval(checkApprovals, 5000).unref()
|
||||||
|
|
||||||
// Telegram caps messages at 4096 chars. Split long replies, preferring
|
// Telegram caps messages at 4096 chars. Split long replies, preferring
|
||||||
// paragraph boundaries when chunkMode is 'newline'.
|
// paragraph boundaries when chunkMode is 'newline'.
|
||||||
@@ -372,11 +372,6 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|||||||
items: { type: 'string' },
|
items: { type: 'string' },
|
||||||
description: 'Absolute file paths to attach. Images send as photos (inline preview); other types as documents. Max 50MB each.',
|
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'],
|
required: ['chat_id', 'text'],
|
||||||
},
|
},
|
||||||
@@ -403,11 +398,6 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|||||||
chat_id: { type: 'string' },
|
chat_id: { type: 'string' },
|
||||||
message_id: { type: 'string' },
|
message_id: { type: 'string' },
|
||||||
text: { 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'],
|
required: ['chat_id', 'message_id', 'text'],
|
||||||
},
|
},
|
||||||
@@ -424,8 +414,6 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
const text = args.text as string
|
const text = args.text as string
|
||||||
const reply_to = args.reply_to != null ? Number(args.reply_to) : undefined
|
const reply_to = args.reply_to != null ? Number(args.reply_to) : undefined
|
||||||
const files = (args.files as string[] | 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)
|
assertAllowedChat(chat_id)
|
||||||
|
|
||||||
@@ -452,7 +440,6 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
(replyMode === 'all' || i === 0)
|
(replyMode === 'all' || i === 0)
|
||||||
const sent = await bot.api.sendMessage(chat_id, chunks[i], {
|
const sent = await bot.api.sendMessage(chat_id, chunks[i], {
|
||||||
...(shouldReplyTo ? { reply_parameters: { message_id: reply_to } } : {}),
|
...(shouldReplyTo ? { reply_parameters: { message_id: reply_to } } : {}),
|
||||||
...(parseMode ? { parse_mode: parseMode } : {}),
|
|
||||||
})
|
})
|
||||||
sentIds.push(sent.message_id)
|
sentIds.push(sent.message_id)
|
||||||
}
|
}
|
||||||
@@ -495,13 +482,10 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
}
|
}
|
||||||
case 'edit_message': {
|
case 'edit_message': {
|
||||||
assertAllowedChat(args.chat_id as string)
|
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(
|
const edited = await bot.api.editMessageText(
|
||||||
args.chat_id as string,
|
args.chat_id as string,
|
||||||
Number(args.message_id),
|
Number(args.message_id),
|
||||||
args.text as string,
|
args.text as string,
|
||||||
...(editParseMode ? [{ parse_mode: editParseMode }] : []),
|
|
||||||
)
|
)
|
||||||
const id = typeof edited === 'object' ? edited.message_id : args.message_id
|
const id = typeof edited === 'object' ? edited.message_id : args.message_id
|
||||||
return { content: [{ type: 'text', text: `edited (id: ${id})` }] }
|
return { content: [{ type: 'text', text: `edited (id: ${id})` }] }
|
||||||
@@ -523,6 +507,24 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
|
|
||||||
await mcp.connect(new StdioServerTransport())
|
await mcp.connect(new StdioServerTransport())
|
||||||
|
|
||||||
|
// When Claude Code closes the MCP connection, stdin gets EOF. Without this
|
||||||
|
// the bot keeps polling forever as a zombie, holding the token and blocking
|
||||||
|
// the next session with 409 Conflict.
|
||||||
|
let shuttingDown = false
|
||||||
|
function shutdown(): void {
|
||||||
|
if (shuttingDown) return
|
||||||
|
shuttingDown = true
|
||||||
|
process.stderr.write('telegram channel: shutting down\n')
|
||||||
|
// bot.stop() signals the poll loop to end; the current getUpdates request
|
||||||
|
// may take up to its long-poll timeout to return. Force-exit after 2s.
|
||||||
|
setTimeout(() => process.exit(0), 2000)
|
||||||
|
void Promise.resolve(bot.stop()).finally(() => process.exit(0))
|
||||||
|
}
|
||||||
|
process.stdin.on('end', shutdown)
|
||||||
|
process.stdin.on('close', shutdown)
|
||||||
|
process.on('SIGTERM', shutdown)
|
||||||
|
process.on('SIGINT', shutdown)
|
||||||
|
|
||||||
bot.on('message:text', async ctx => {
|
bot.on('message:text', async ctx => {
|
||||||
await handleInbound(ctx, ctx.message.text, undefined)
|
await handleInbound(ctx, ctx.message.text, undefined)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user