TLGBot - Telegram Bot Python Library
![License](https://img.shields.io/badge/license-MIT-blue.svg)
TLGBot is a Python library for creating Telegram bots with ease. This library simplifies the interaction with the Telegram Bot API, allowing you to send messages, edit group descriptions, and more.
Installation
You can install TLGBot using pip:
pip install tlgbot
Getting Started
-
Create a Telegram bot and obtain the API token. You can do this by talking to the BotFather on Telegram.
-
Import the TLGBot class and create an instance with your API token.
from tlgbot import TLGBot
bot = TLGBot('YOUR_API_TOKEN')
Use the library's functions to interact with your bot.
Usage
Sending a Message
Send a text message to a chat by specifying the chat ID and message text:
chat_id = 'YOUR_CHAT_ID'
message = 'Hello, Telegram!'
bot.send_message(chat_id, message)
Sending a Photo
Send a photo to a chat by specifying the chat ID, the path to the photo file, and an optional caption:
chat_id = 'YOUR_CHAT_ID'
photo_path = 'path/to/your/photo.jpg'
caption = 'Check out this cool photo!'
bot.send_photo(chat_id, photo_path, caption)
Editing Group Description
Edit the description of a group chat by specifying the chat ID and the new description:
chat_id = 'YOUR_CHAT_ID'
new_description = 'This is our updated group description.'
if bot.edit_about(chat_id, new_description):
print('Group description edited successfully.')
else:
print('Error editing group description.')
Responding to Last Message
Reply to the last message in a chat by specifying the chat ID and the reply message:
chat_id = 'YOUR_CHAT_ID'
reply_message = 'Thanks for your message!'
bot.reply_last_msg(chat_id, reply_message)
EXAMPLE PRODUCTION CODE
from tlgbot import TLGBot
token = 'Your_Bot_Token'
chat_id = TLGBot.last_id(token)
if chat_id is not None:
print(f'Último chat ID: {chat_id}')
response_message = 'Hello test'
TLGBot.send_message(TLGBot(token), chat_id, response_message)
print('Mensaje enviado exitosamente.')
else:
print('No se pudo obtener el chat ID.')
License
This library is available under the MIT license.
Support
If you have any questions, suggestions, or need help with this library, please create an issue on the Github Repository.