A package to interact with a Telegram group by sending and receiving messages
Project description
TerminalBot
TerminalBot is a powerful and easy-to-use Python package for interacting with Telegram groups. Whether you need to automate message sending, receive and process messages, or create complex workflows, TerminalBot provides a simple and effective solution.
Features
- Easy Installation: Quickly install TerminalBot using pip.
- Simple API: Easy-to-use functions for sending and receiving messages.
- Command Line Interface: Convenient CLI for quick operations without writing code.
- State Tracking: Automatically tracks the last processed message to avoid duplicates.
- Configurable: Easily configure your bot with a JSON file for persistent state management.
Benefits
- Automation: Automate your workflows by integrating TerminalBot with other systems.
- Efficiency: Save time by handling repetitive tasks through automated messaging.
- Reliability: Ensure messages are only processed once with state tracking.
- Flexibility: Use TerminalBot in your Python scripts or from the command line.
- Scalability: Scale your operations by leveraging the power of Telegram bots for large groups.
Why Use TerminalBot?
- Simplicity: With a straightforward API and CLI, TerminalBot is easy to use even for beginners.
- Versatility: Suitable for various use cases, including notifications, alerts, customer support, and more.
- Integration: Seamlessly integrate with other Python packages and tools to build comprehensive solutions.
- Community Support: Join a growing community of users who leverage TerminalBot for their projects.
Installation
You can install terminalbot
using pip:
pip install terminalbot
Usage Examples
Using TerminalBot from the Command Line
Receive a message
message=$(terminalbot --token "token" --id "@username")
echo "message is : $message"
- Replace with your bot token and with your group chat ID.
Receive and automatically send a response
message=$(terminalbot --token "token" --id "@username" --message-receive "Your message received")
echo "message is: $message"
- This command will automatically send the specified response message after receiving a message.
Send a message
terminalbot --token "token" --id "@username" --message "Hello world"
echo "Your message sent to the Telegram group"
- This command will automatically send the specified message to the Telegram group.
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")
Thank You
Thank you for using TerminalBot! We hope this package makes your interaction with Telegram groups easier and more efficient. If you have any suggestions or feature requests, please don't hesitate to reach out.
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
terminalbot-1.1.4.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for terminalbot-1.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 619d92ce4a37447d61cdc95636e617b2e962eb576d2682e98d742a45bd60033d |
|
MD5 | c3461971f003d0b112f2750dc9d468c1 |
|
BLAKE2b-256 | 3d7f3600f65e54bfebfb285397d2805e9e074a28dcb26b6e2039c840f701056a |