The bot is built using the aiogram library for interacting with the Telegram Bot API. It also utilizes the pyshorteners library to shorten URLs.
-
Commands:
/start
: This command initiates the conversation with the bot and provides a brief introduction./help
: Displays instructions on how to use the bot.
-
Message Handlers:
- Direct Message Handler: If a user sends a URL directly to the bot, it replies with the shortened URL.
- Inline Handler: Users can use the bot inline in any chat by typing
@tinyURLrobot
followed by a URL. The bot will provide the shortened URL as an inline query result.
-
URL Handling: The bot accepts URLs of any type, whether they start with "http:https://", "https://", or even without a prefix. It automatically appends "http:https://" if missing before shortening the URL.
Overall, this bot provides a convenient way to shorten URLs within Telegram, offering both direct message support, mention mode, and inline query functionality for seamless integration into any chat.
-
Set up a Telegram Bot:
- Talk to the BotFather on Telegram to create a new bot and obtain the API token.
- Copy the API token into the
token
variable in thelink_shortener.py
file.
-
Install Required Libraries:
pip install aiogram pip install pyshorteners
-
Run the Bot:
python link_shortener.py