Telesender is a command-line tool that allows you to send messages, photos, videos, and files to Telegram chats directly from your terminal. It operates in the Unix philosophy, accepting command-line arguments for account configuration and reading messages from stdin
.
- Send plain text and Markdown-formatted messages.
- Send photos, videos, and files with optional captions.
- Support for multiline messages and captions.
- Works with your personal Telegram account via the Telegram API.
- List available chats for easy selection.
- Supports individual and group chats.
- Python 3.6 or later.
- Telethon library.
pip install telethon
Clone the repository:
git clone https://github.com/smartynov/telesender.git
cd telesender
Make the script executable:
chmod +x telesender
-
Obtain Telegram API Credentials:
- Go to my.telegram.org/apps.
- Log in with your Telegram account.
- Create a new application to get your API ID and API Hash.
-
Authenticate with Telesender:
- The first time you run Telesender, it will prompt for your phone number and send you a code via Telegram to authenticate.
--api-id
: Your Telegram API ID (required).--api-hash
: Your Telegram API Hash (required).--chat-id
: The ID of the target chat (required unless using--list-chats
).--list-chats
: List recent chats and their IDs.
To list your recent chats and obtain their IDs:
./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --list-chats
- Single-Line Messages: Write your message on a single line.
- Multiline Messages: Enclose your message or caption within double quotes (
"
). - Message Types:
- text (default)
- markdown
- photo
- video
- file
Syntax:
[message_type]:[file_path]:[content]
- message_type: The type of message (optional for text messages).
- file_path: Path to the file (required for
photo
,video
,file
). - content: The message text or caption. Use double quotes for multiline content.
Examples:
-
Plain Text Message:
Hello, this is a single-line message.
-
Multiline Text Message:
"This is a multiline text message."
-
Markdown Message:
markdown:"This is **bold** and _italic_ text."
-
Photo with Caption:
photo:/path/to/photo.jpg:"This is a multiline caption for the photo."
-
Video with Caption:
video:/path/to/video.mp4:"Check out this awesome video!"
Create a messages.txt
file:
Hello, this is a single-line message.
"This is
a multiline message."
markdown:"This is **bold** and _italic_ text."
photo:/path/to/photo.jpg:"This is a
multiline caption
for the photo."
Send messages using:
./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --chat-id TARGET_CHAT_ID < messages.txt
cat <<EOF | ./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --chat-id TARGET_CHAT_ID
Hello, this is a single-line message.
"This is
a multiline message."
markdown:"This is **bold** and _italic_ text."
photo:/path/to/photo.jpg:"This is a
multiline caption
for the photo."
EOF
Sending a Single-Line Text Message:
echo "Hello, World!" | ./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --chat-id CHAT_ID
Sending a Multiline Text Message:
echo '"This is a
multiline message."' | ./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --chat-id CHAT_ID
Sending a Markdown Message:
echo 'markdown:"This is **bold** and _italic_."' | ./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --chat-id CHAT_ID
Sending a Photo with Caption:
echo 'photo:/path/to/photo.jpg:"This is a
multiline caption."' | ./telesender --api-id YOUR_API_ID --api-hash YOUR_API_HASH --chat-id CHAT_ID
- Invalid Input: The script will output error messages to
stderr
if it encounters invalid message formats or missing parameters. - File Not Found: If a specified file does not exist, an error will be printed to
stderr
. - Telegram API Errors: Any errors from the Telegram API will be caught and displayed.
- API Credentials: Keep your
api_id
andapi_hash
confidential. - Session File: The script creates a
telesender.session
file containing your session data. Protect this file to prevent unauthorized access.
Contributions are welcome! Feel free to open issues or submit pull requests for enhancements and bug fixes.
This project is licensed under the MIT License.
- Built using the Telethon library.
- Inspired by the need for simple, Unix-style command-line tools for Telegram.