Skip to content

Enable Telegram channel support in telegram plugin#1003

Open
Tristan-Wilson wants to merge 2 commits intoanthropics:mainfrom
Tristan-Wilson:add-telegram-channel-post-support
Open

Enable Telegram channel support in telegram plugin#1003
Tristan-Wilson wants to merge 2 commits intoanthropics:mainfrom
Tristan-Wilson:add-telegram-channel-post-support

Conversation

@Tristan-Wilson
Copy link
Copy Markdown

@Tristan-Wilson Tristan-Wilson commented Mar 25, 2026

Summary

Adds channel_post support to the Telegram plugin, enabling bot-to-bot communication via Telegram channels.

Telegram Bot API prevents bots from seeing other bots messages in groups — this is a hard platform limitation. However, this restriction does not apply to channels, where posts arrive as channel_post updates instead of message updates. This PR adds the necessary handlers and access control to receive and send channel posts, enabling use cases like coordinating multiple Claude Code instances via a private Telegram channel.

Change 1: Channel post handlers and access control

  • Add ChannelPolicy type and channels field to Access config in access.json
  • Add channel case in gate() — placed before the ctx.from check since channel posts may lack sender info
  • Add channel_post:* handlers for text, photo, document, voice, audio, video (mirrors existing message:* handlers)
  • Adjust handleInbound() to fall back to ctx.channelPost when ctx.message is undefined, and handle missing ctx.from
  • Update assertAllowedChat() to check channels keys for outbound messages (reply, react, etc.)

Change 2: Include channel_post in polling allowed_updates

Grammy default long-polling does not subscribe to channel_post updates. Without explicitly including it in allowed_updates, the bot never receives channel posts even though the handlers are registered. This adds allowed_updates: ["message", "message_reaction", "channel_post"] to the bot.start() call.

Configuration

Add a channel to ~/.claude/channels/telegram/access.json:

{
  "channels": {
    "-100XXXXXXXXXX": { "allowFrom": [] }
  }
}
  • Empty allowFrom accepts all posts in the channel (the channel being listed is sufficient authorization)
  • To restrict to specific sender IDs, list them in allowFrom

Test plan

  • Verified outbound: bot can send messages to a channel via reply(chat_id=...)
  • Verified inbound: bot receives channel_post updates from the channel
  • Verified bot-to-bot: two Claude Code instances (each with their own Telegram bot) communicating via a private channel
  • Existing group and DM functionality unaffected

Tristan Wilson and others added 2 commits March 25, 2026 16:10
Telegram's Bot API prevents bots from seeing other bots' messages in
groups, but this restriction doesn't apply to channels. This adds
channel_post handlers so the plugin can receive messages posted to
Telegram channels, enabling bot-to-bot communication via a private
channel.

Changes:
- Add ChannelPolicy type and channels field to Access config
- Add 'channel' case in gate() (handles undefined ctx.from)
- Add channel_post handlers for text, photo, document, voice, audio, video
- Adjust handleInbound() to fall back to ctx.channelPost when ctx.message
  is undefined
- Update assertAllowedChat() to check channels

To activate, add a channel to access.json:
  { "channels": { "-100XXXXXXXXXX": { "allowFrom": [] } } }

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Without this, Grammy's long-polling doesn't subscribe to channel_post
updates, so the bot never receives messages posted to channels even
though the handlers are registered.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Tristan-Wilson Tristan-Wilson changed the title feat(telegram): add channel_post support for bot-to-bot communication Enable Telegram channel support in telegram plugin Mar 25, 2026
@Tristan-Wilson Tristan-Wilson marked this pull request as ready for review March 25, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants