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.
Project description
TLGBot - Telegram Bot Python Library
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
# Replace 'YOUR_API_TOKEN' with your actual bot API token
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' # Replace with the chat ID you want to send the message to
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' # Replace with the chat ID you want to send the photo to
photo_path = 'path/to/your/photo.jpg' # Replace with the actual file path
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' # Replace with the chat ID of the group
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' # Replace with the chat ID you want to respond in
reply_message = 'Thanks for your message!'
bot.reply_last_msg(chat_id, reply_message)
EXAMPLE PRODUCTION CODE
from tlgbot import TLGBot
# Define tu token
token = 'Your_Bot_Token'
# Obtén el último chat ID utilizando la función last_id
chat_id = TLGBot.last_id(token)
if chat_id is not None:
print(f'Último chat ID: {chat_id}')
# Define un mensaje de respuesta
response_message = 'Hello test'
# Envia el mensaje al último chat ID
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.
Project details
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 tlgbot-1.1.tar.gz.
File metadata
- Download URL: tlgbot-1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8705ec870e605751b1e477f0fbe424feb47db2c3c9b6f5ac3b2ffb880f7854e5
|
|
| MD5 |
d5ec2fc5891d78ef9ad7f11858f37caf
|
|
| BLAKE2b-256 |
78af9e2268ff210350a47764e1af116687d6fdd080bf9aa601ae9b742bea73fb
|
File details
Details for the file tlgbot-1.1-py3-none-any.whl.
File metadata
- Download URL: tlgbot-1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce5fc610bdfa0ddaf9f523b982c47d6257aa28943384af0219a7d9611c29ac95
|
|
| MD5 |
7c27fb8fae250551ecba80f0555deb08
|
|
| BLAKE2b-256 |
2abfe80f6551172a13497ed0c91c12415fd7b5b3ba352d91cc58da1fac2cdd7f
|