mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-23 00:23:07 +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'.
|
||||||
@@ -507,61 +507,23 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
|
|
||||||
await mcp.connect(new StdioServerTransport())
|
await mcp.connect(new StdioServerTransport())
|
||||||
|
|
||||||
// Commands are DM-only. Responding in groups would: (1) leak pairing codes via
|
// When Claude Code closes the MCP connection, stdin gets EOF. Without this
|
||||||
// /status to other group members, (2) confirm bot presence in non-allowlisted
|
// the bot keeps polling forever as a zombie, holding the token and blocking
|
||||||
// groups, (3) spam channels the operator never approved. Silent drop matches
|
// the next session with 409 Conflict.
|
||||||
// the gate's behavior for unrecognized groups.
|
let shuttingDown = false
|
||||||
|
function shutdown(): void {
|
||||||
bot.command('start', async ctx => {
|
if (shuttingDown) return
|
||||||
if (ctx.chat?.type !== 'private') return
|
shuttingDown = true
|
||||||
const access = loadAccess()
|
process.stderr.write('telegram channel: shutting down\n')
|
||||||
if (access.dmPolicy === 'disabled') {
|
// bot.stop() signals the poll loop to end; the current getUpdates request
|
||||||
await ctx.reply(`This bot isn't accepting new connections.`)
|
// may take up to its long-poll timeout to return. Force-exit after 2s.
|
||||||
return
|
setTimeout(() => process.exit(0), 2000)
|
||||||
}
|
void Promise.resolve(bot.stop()).finally(() => process.exit(0))
|
||||||
await ctx.reply(
|
}
|
||||||
`This bot bridges Telegram to a Claude Code session.\n\n` +
|
process.stdin.on('end', shutdown)
|
||||||
`To pair:\n` +
|
process.stdin.on('close', shutdown)
|
||||||
`1. DM me anything — you'll get a 6-char code\n` +
|
process.on('SIGTERM', shutdown)
|
||||||
`2. In Claude Code: /telegram:access pair <code>\n\n` +
|
process.on('SIGINT', shutdown)
|
||||||
`After that, DMs here reach that session.`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
bot.command('help', async ctx => {
|
|
||||||
if (ctx.chat?.type !== 'private') return
|
|
||||||
await ctx.reply(
|
|
||||||
`Messages you send here route to a paired Claude Code session. ` +
|
|
||||||
`Text and photos are forwarded; replies and reactions come back.\n\n` +
|
|
||||||
`/start — pairing instructions\n` +
|
|
||||||
`/status — check your pairing state`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
bot.command('status', async ctx => {
|
|
||||||
if (ctx.chat?.type !== 'private') return
|
|
||||||
const from = ctx.from
|
|
||||||
if (!from) return
|
|
||||||
const senderId = String(from.id)
|
|
||||||
const access = loadAccess()
|
|
||||||
|
|
||||||
if (access.allowFrom.includes(senderId)) {
|
|
||||||
const name = from.username ? `@${from.username}` : senderId
|
|
||||||
await ctx.reply(`Paired as ${name}.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [code, p] of Object.entries(access.pending)) {
|
|
||||||
if (p.senderId === senderId) {
|
|
||||||
await ctx.reply(
|
|
||||||
`Pending pairing — run in Claude Code:\n\n/telegram:access pair ${code}`
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.reply(`Not paired. Send me a message to get a pairing code.`)
|
|
||||||
})
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -653,13 +615,5 @@ void bot.start({
|
|||||||
onStart: info => {
|
onStart: info => {
|
||||||
botUsername = info.username
|
botUsername = info.username
|
||||||
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
||||||
void bot.api.setMyCommands(
|
|
||||||
[
|
|
||||||
{ command: 'start', description: 'Welcome and setup guide' },
|
|
||||||
{ command: 'help', description: 'What this bot can do' },
|
|
||||||
{ command: 'status', description: 'Check your pairing status' },
|
|
||||||
],
|
|
||||||
{ scope: { type: 'all_private_chats' } },
|
|
||||||
).catch(() => {})
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user