A package to interact with a Telegram group by sending and receiving messages
Project description
terminalbot Python Package
terminalbot
is a Python package designed to facilitate interaction with Telegram messages, enabling the execution of commands received via messages and sending messages back to a Telegram group.
About
terminalbot
simplifies the integration of Telegram messaging with Python applications, providing seamless communication capabilities for executing commands and sending messages within a specified group. It leverages Telegram's API for reliable message handling and processing.
Features
- Message Reception: Receive and process messages from a specified Telegram group.
- Command Execution: Execute commands received via Telegram messages directly from Python scripts.
- Message Sending: Send custom messages to a Telegram group.
- Continuous Operation: Support for continuous message processing using a persistent loop.
Installation
You can install terminalbot
using pip:
pip install terminalbot
Usage Examples
1. Receiving Messages
import terminalbot
telegram_group = '@username'
telegram_bot = 'YOUR_BOT_TOKEN_HERE'
# Get the latest message
chat = terminalbot.get_message(telegram_bot, telegram_group)
if chat:
print(f"Message received: {chat}")
else:
print("No new messages")
2. Sending Messages
import terminalbot
telegram_group = '@username'
telegram_bot = 'YOUR_BOT_TOKEN_HERE'
# Send a message
message_to_send = "Hello from terminalbot!"
terminalbot.send_message(telegram_bot, telegram_group, message_to_send)
print(f"Sent message: {message_to_send}")
3. Receiving and Executing Commands
import terminalbot
import os
telegram_group = '@username'
telegram_bot = 'YOUR_BOT_TOKEN_HERE'
# Get the latest message and execute it as a command
chat = terminalbot.get_message(telegram_bot, telegram_group)
if chat:
print(f"Executing command: {chat}")
os.system(chat)
else:
print("No new commands")
4. Handling Continuous Loop with Message Processing
import terminalbot
import time
telegram_group = '@username'
telegram_bot = 'YOUR_BOT_TOKEN_HERE'
def main_loop(bot_token, group_chat_id):
bot = terminalbot.TelegramBot(bot_token, group_chat_id)
while True:
message = bot.get_message()
if message:
print(f"Message received: {message}")
if message.lower() == "stop terminalbot":
print("Stopping bot.")
break
os.system(message) # Example: Execute a command received via message
print(f"Executed command: {message}")
time.sleep(1)
if __name__ == '__main__':
main_loop(telegram_bot, telegram_group)
5. Receiving Messages and Sending Replies
import terminalbot
import os
telegram_group = '@username'
telegram_bot = 'YOUR_BOT_TOKEN_HERE'
# Get the latest message
chat = terminalbot.get_message(telegram_bot, telegram_group)
if chat:
# Execute the received command
os.system(chat)
# Send a reply message with the executed command
message_to_send = f"Executed command: {chat}"
terminalbot.send_message(telegram_bot, telegram_group, message_to_send)
else:
print("No new commands or messages")
Acknowledgments
Special thanks to the Telegram team for providing a robust API and to the Python community for their continuous support and feedback.
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
Hashes for terminalbot-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dfe189212c7d4a24cbe0a11fc5aabdab22bc621f58c5e782724298f4db7c84a |
|
MD5 | e78537d054c958aed78cea203b077b26 |
|
BLAKE2b-256 | 1c943ede71597ddc1c8158d5a5bcbf26fb90e31687ebc5114289de5eace70290 |