@openpets/telegram-bot
v1.0.0
Published
Send messages, manage chats, handle updates and interact with users through Telegram Bot API. Supports webhooks, inline keyboards, and all bot features.
Maintainers
Readme
Telegram Bot Plugin for OpenPets
Control Telegram bots via the Bot API. Send messages, manage chats, handle updates, and interact with users through 122+ API operations.
Features
- Send Messages: Text, photos, documents, audio, video, polls, and more
- Chat Management: Manage groups, channels, and private chats
- Updates: Get updates via polling (getUpdates) or webhooks
- Inline Features: Keyboards, callbacks, inline queries
- Advanced: Games, payments, stickers, forums, reactions
Quick Start
1. Get Bot Token
Message @BotFather on Telegram:
- Send
/newbot - Follow prompts to name your bot
- Copy the token (looks like:
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11)
2. Configure
cd pets/telegram-bot
cp .env.example .env
# Edit .env and add your token3. Test Connection
bun run quickstart
# or
opencode run "test telegram bot connection"Configuration
Environment Variables
| Variable | Required | Description |
|----------|----------|-------------|
| TELEGRAM_BOT_TOKEN | ✅ Yes | Bot token from @BotFather |
Example .env
TELEGRAM_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11Usage Examples
Send a Message
send telegram message to chat 123456789 saying "Hello from OpenPets!"Get Bot Info
get telegram bot infoCheck Updates
get telegram updatesSend a Photo
send telegram photo to chat 123456789 with url https://example.com/image.jpgCreate a Poll
create telegram poll in chat 123456789 with question "What's your favorite color?" and options red, blue, greenAvailable Tools (122 Total)
Core Operations
Getting Updates:
telegram-bot-get-updates- Poll for updatestelegram-bot-set-webhook- Set webhook URLtelegram-bot-delete-webhook- Remove webhooktelegram-bot-get-webhook-info- Get webhook status
Messages:
telegram-bot-send-message- Send text messagestelegram-bot-send-photo- Send photostelegram-bot-send-document- Send documentstelegram-bot-send-audio- Send audio filestelegram-bot-send-video- Send videostelegram-bot-send-voice- Send voice messagestelegram-bot-send-animation- Send GIFs/animationstelegram-bot-send-location- Send locationstelegram-bot-send-venue- Send venuestelegram-bot-send-contact- Send contactstelegram-bot-send-poll- Create pollstelegram-bot-send-dice- Send animated dicetelegram-bot-send-media-group- Send media groups
Chat Management:
telegram-bot-get-chat- Get chat infotelegram-bot-get-chat-members- List chat memberstelegram-bot-get-chat-member-count- Get member counttelegram-bot-ban-chat-member- Ban userstelegram-bot-unban-chat-member- Unban userstelegram-bot-restrict-chat-member- Restrict userstelegram-bot-promote-chat-member- Promote userstelegram-bot-set-chat-title- Set chat titletelegram-bot-set-chat-description- Set chat descriptiontelegram-bot-set-chat-photo- Set chat phototelegram-bot-delete-chat-photo- Delete chat phototelegram-bot-pin-chat-message- Pin messagestelegram-bot-unpin-chat-message- Unpin messages
Message Operations:
telegram-bot-forward-message- Forward messagestelegram-bot-copy-message- Copy messagestelegram-bot-delete-message- Delete messagestelegram-bot-edit-message-text- Edit message texttelegram-bot-edit-message-caption- Edit captionstelegram-bot-edit-message-reply-markup- Edit keyboards
Stickers:
telegram-bot-send-sticker- Send stickerstelegram-bot-get-sticker-set- Get sticker setstelegram-bot-create-new-sticker-set- Create sticker setstelegram-bot-add-sticker-to-set- Add stickerstelegram-bot-set-sticker-emoji-list- Set sticker emojis
Bot Settings:
telegram-bot-get-me- Get bot infotelegram-bot-set-my-commands- Set bot commandstelegram-bot-get-my-commands- Get bot commandstelegram-bot-set-my-name- Set bot nametelegram-bot-get-my-name- Get bot nametelegram-bot-set-my-description- Set descriptiontelegram-bot-get-my-description- Get description
Payments:
telegram-bot-send-invoice- Send invoicestelegram-bot-create-invoice-link- Create payment linkstelegram-bot-answer-pre-checkout-query- Handle pre-checkout
Games:
telegram-bot-send-game- Send gamestelegram-bot-set-game-score- Set high scorestelegram-bot-get-game-high-scores- Get high scores
Inline Mode:
telegram-bot-answer-inline-query- Answer inline queriestelegram-bot-answer-web-app-query- Answer Web App queries
Read-Only Mode
Enable read-only mode to disable write operations:
# Environment variable
export TELEGRAM_BOT_READ_ONLY=true
# Or CLI command
pets read-only telegram-bot onIn read-only mode, only these tools are available:
- All
get*andread*operations - No
send*,set*,delete*,create*operations
Differences: Bot API vs User API
| Feature | This Plugin (Bot API) | @openpets/telegram (User API) | |---------|----------------------|------------------------------| | API | HTTP REST API | MTProto (binary protocol) | | Auth | Bot token | API ID + Hash + Phone | | Account | Bot account | Your personal account | | Access | Public chats, groups where added | All your private chats | | Setup | Token from @BotFather | API credentials from my.telegram.org |
Technical Details
- OpenAPI Spec: alserom/telegram-bot-api-spec
- API Version: 7.4 (auto-updated)
- Base URL:
https://api.telegram.org/bot<token> - Auth Method: Token in URL path (Telegram-specific)
Scripts
# Test connection
bun run quickstart
# Generate OpenAPI tools (if spec updates)
bun run generate-openapi
# Build for publishing
bun run buildResources
- Telegram Bot API Documentation
- BotFather - Create and manage bots
- Bot API Updates
- OpenAPI Spec Repository
Troubleshooting
"Unauthorized" Error
- Check your token is correct
- Ensure bot hasn't been revoked in @BotFather
"Chat Not Found"
- Bot must be added to the chat first
- For private chats, user must start the conversation
Webhook Issues
- Must use HTTPS URL
- Supported ports: 443, 80, 88, 8443
- Check
getWebhookInfofor errors
Publishing
# Validate
pets validate
# Preview
pets publish --preview
# Publish
pets publish