Skip to content

vengomatto/telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot - vengomattoBot

A simple Telegram bot in Python that can send and receive messages.

📋 Prerequisites

  • Python 3.x
  • uv - Fast Python package manager
  • Libraries: requests, python-dotenv

🚀 Installation

  1. Install dependencies:
uv pip install requests python-dotenv

or if you have a pyproject.toml or requirements.txt:

uv pip sync requirements.txt
  1. Configure environment variables:

    • Copy the .env.example file to .env:
      cp .env.example .env
    • Edit the .env file and insert your values:
      • TELEGRAM_BOT_TOKEN: Your bot token (get it from @BotFather)
      • TELEGRAM_CHAT_ID: Your chat ID (get it from @getidsbot)

    Example .env:

    TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
    TELEGRAM_CHAT_ID=123456789
    

💻 Usage

Running with uv

You can run the script directly with uv:

uv run main.py

Send a message

Send the default message:

uv run main.py

Send a custom message:

uv run main.py -m "Your custom message"

or

uv run main.py --message "Your custom message"

Receive messages (Listen mode)

To put the bot in listening mode and receive messages:

uv run main.py -l

or

uv run main.py --listen

The bot will remain running and respond to received messages. To stop it, press Ctrl+C.

🤖 Bot commands

When the bot is in listen mode, it responds to the following commands:

  • /start - Welcome message
  • /help - Show the list of available commands
  • Any other message - The bot will echo the received message

📝 Examples

# Send "Hello, I'm vengomattoBot!" (default message)
uv run main.py

# Send a custom message
uv run main.py -m "Hello from Python!"

# Start the bot in listen mode
uv run main.py -l

🔧 Customization

You can customize the bot's responses by modifying the listen_for_messages() function in main.py. Add new conditions to handle custom commands:

if text.lower() == '/yourcommand':
    send_message("Your custom response")

📄 Help

To see all available options:

uv run main.py -h

⚠️ Security notes

  • DO NOT share the .env file publicly
  • The .env file is already included in .gitignore to avoid accidentally committing it
  • Use .env.example as a template for other developers
  • NEVER commit tokens and credentials to the repository

📚 Main functions

  • send_message(message) - Send a message to the specified chat
  • get_updates(offset) - Retrieve updates from Telegram
  • listen_for_messages() - Listen for new messages and respond automatically

🔗 Useful links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages