Advanced Telegram Bot API Connector
Project description
TeleConnector
A robust Python package for seamless Telegram bot interactions with advanced file handling capabilities.
Features
- Send messages and files to Telegram chats
- Listen for incoming messages and files in real-time
- Automatic file saving with custom paths via captions
- Comprehensive error handling and validation
- Configurable timeouts for all operations
- Supports both individual chats and groups
Installation
pip install teleconnector
Quick Start
1. Sending Messages
from teleconnector import send_message
bot_token = "YOUR_BOT_TOKEN"
chat_id = "TARGET_CHAT_ID"
try:
result = send_message("Hello World!", bot_token, chat_id)
if result:
print("Message sent successfully!")
else:
print("Failed to send message!")
except Exception as e:
print(f"Error while sending: {e}")
Listen For Messages
from teleconnector import listen_for_messages
bot_token = "YOUR_BOT_TOKEN"
chat_id = "YOUR_GROUP_CHAT_ID"
try:
print("📡 Listening for new messages... (Press CTRL+C to stop)")
for message in listen_for_messages(bot_token, chat_id):
if "text" in message:
print(f"New message: {message['text']}")
else:
print("Received a message without text content:", message)
except KeyboardInterrupt:
print("\nListener stopped by user.")
except Exception as e:
print(f"Error while listening: {e}")
3. Sending File
from teleconnector import send_file
bot_token = "YOUR_BOT_TOKEN"
chat_id = "TARGET_CHAT_ID"
file_path = "/path/to/file.txt"
try:
result = send_file(file_path, bot_token, chat_id)
if result:
print(f"File sent successfully: {file_path}")
else:
print(f"Failed to send file: {file_path}")
except Exception as e:
print(f"Error while sending file: {e}")
4. Receiving and Auto-Saving Files
from teleconnector import listen_for_files
bot_token = "YOUR_BOT_TOKEN"
try:
print("📡 Listening for incoming files... (Press CTRL+C to stop)")
for file_info in listen_for_files(bot_token, save_dir=True):
if 'saved_path' in file_info:
print(f"File automatically saved to: {file_info['saved_path']}")
if 'file_name' in file_info:
print(f"Received file: {file_info['file_name']}")
else:
print(f"Received file data without a name: {file_info}")
except KeyboardInterrupt:
print("\nListener stopped by user.")
except Exception as e:
print(f"Error while listening for files: {e}")
Error Handling
The package raises specific exceptions you can catch:
from teleconnector import TelegramAPIError
try:
send_message("Test", bot_token, chat_id)
except TelegramAPIError as e:
print(f"Telegram error: {e}")
except ValueError as e:
print(f"Invalid parameters: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub. GitHub
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file teleconnector-1.1.1.tar.gz.
File metadata
- Download URL: teleconnector-1.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecdfbef2916b2b2711ed3f2001acf5500cb1dc83371d7ab5ba9f3a3cea94edf0
|
|
| MD5 |
fb51f513f97150890cd748e05c6b91cd
|
|
| BLAKE2b-256 |
b662a8af2a9d96527b7f28037a7070a0179e50720054bc10c4f1e68707eac0df
|
File details
Details for the file teleconnector-1.1.1-py3-none-any.whl.
File metadata
- Download URL: teleconnector-1.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c041f850ec18c1bb1a605a693d6d6b727ba7b44fec9a4447813dac733231e251
|
|
| MD5 |
b85e2839e261374fb46cda55bcd5a5ea
|
|
| BLAKE2b-256 |
ef9bc42393271fbf60f7956e384e86c41306cf17863e066e5a838e32e77718da
|