botaffiumeiro is a Telegram bot that detects Amazon, Aliexpress and other links shared in Telegram groups and automatically converts them into affiliate links using your custom Amazon Affiliate ID. This is especially useful for those who want to monetize links shared in their communities.
- Short and long link detection: The bot detects both full URLs and short links, such as amzn.to and amzn.eu.
- Affiliate link modification:
- If the link already contains an affiliate ID, it will replace it with your own.
- If no affiliate ID is present, the bot automatically adds your personalized affiliate ID.
- User exclusion: You can specify certain users to be excluded from link modifications, allowing them to share links without alteration.
- AliExpress discount codes: When AliExpress links are detected, the bot automatically adds current discount codes to the message.
- AliExpress discount commands: Users can request AliExpress discount codes using configurable commands, such as
/discounts
,/bonus
, etc. - Aliowing to delete message or not: When AliExpress links are detected, the bot automatically adds current discount codes to the message.
- Amazon
- AliExpress (special case adding discount codes)
- Awin stores (e.g., PcComponentes, Leroy Merlin)
- Admitad stores (e.g., AliExpress, GiftMio)
- Tradedoubler stores (e.g. Mediamarkt, Philips HUE)
$ docker create \
--name=botaffiumeiro \
-v /path/to/host/data:/app/data \
--restart unless-stopped \
ghcr.io/hectorzin/botaffiumeiro
Modify the /path/to/host/data/config.yaml
file with your settings.
$ docker start botaffiumeiro
Once configured and running, the bot will detect Affiliate links in any group it's added to and replace them with your affiliate links, making it easy to earn commissions from shared products.
To ensure that the bot works correctly, you need to install Python and the required libraries.
First, ensure that you have Python installed. You can download Python from the official website: Python Downloads.
Once Python is installed, you need to run the following commands to install the required Python libraries:
pip install -r requirements.txt
- Set up your Telegram Bot Token, and your Afiliates Settings in
data/config.py
. - Install Python and the required libraries.
- Run the bot on a machine with Python by executing the following command:
python botaffiumeiro.py
Once configured and running, the bot will detect Affiliate links in any group it's added to and replace them with your affiliate links, making it easy to earn commissions from shared products.
To obtain the Bot Token, follow these steps:
- Open Telegram and search for the user BotFather or click on this link: BotFather.
- Start a chat with BotFather and send the command
/start
. - Use the command
/newbot
to create a new bot. Follow the prompts to choose a name and username for your bot.- The bot name can be anything.
- The username must be unique and should end with "bot" (e.g.,
YourBotName_bot
).
- After the bot is created, BotFather will provide a Bot Token. Save this token for later use.
- If you want the bot deletes other user messages (see delete_messages parameter), you must add the bot as a group administrator
Telegram has a privacy setting for bots that prevents them from reading messages in groups unless they are mentioned directly, or the admin has configured the bot to run in No Privacy Mode. To allow the bot to read all messages, follow these steps:
- Go to BotFather:
- Open a conversation with BotFather in Telegram or click here.
- Configure the privacy mode:
- Send the command
/mybots
to BotFather. - Select your bot from the list.
- Then select Bot Settings.
- Choose Group Privacy.
- If privacy is enabled, disable it by selecting Disable Group Privacy.
- Send the command
This will allow the bot to read all messages in the group, not just the ones where it is mentioned directly.
If your bot will operate in a group, follow these steps to add it:
- Add the bot to the desired Telegram group.
- Promote the bot to Admin in the group to ensure it has the necessary permissions to read and modify messages.
You can exclude certain users from having their Amazon links modified by the bot. You can do this by defining a list of usernames or Telegram user IDs.
telegram:
excluded_users:
- "username1"
- "username2"
- 123456789
When the bot detects an AliExpress link, it will automatically reply to the message with the pre-configured discount codes. You can modify these discount codes as needed.
aliexpress:
discount_codes: |
💥 AliExpress discount codes:
💰2$ off for purchases over 20$:【IFPTKOH】
💰5$ off for purchases over 50$:【IFPT35D】
💰25$ off for purchases over 200$:【IFPQDMH】
💰50$ off for purchases over 400$:【IFP5RIN】
You can define custom commands that users can use to request AliExpress discount codes in your config.yaml
file. The following example shows how to configure discount keywords:
discount_keywords:
- discounts
- bonus
- bonuses
- aliexpress
You can also customize the bot's response messages and translate them into different languages. To do this, you can modify the message strings in the code. For example:
messages:
affiliate_link_modified: "Here is the modified link with our affiliate program:"
reply_provided_by_user: "Reply provided by"
By changing these variables, you can personalize how the bot interacts with users. This makes it easy to:
- Translate the bot's messages into any language.
- Adjust the messaging style to fit your preferences.
This parameter allows you to define what percentage of the links shared in Telegram groups will be replaced with affiliate links belonging to the software creators. However, there are a few important conditions to keep in mind:
-
Available Affiliate Links: Only links that the software creators have affiliate programs for will be eligible to be replaced.
-
Affiliate Priority: If the user does not have an affiliate link for a specific domain, but the creators of the software do, the creators' affiliate link will be used instead.
This ensures that affiliate links are always used when available, whether from the user or the software creators, while respecting the configured percentage.
We usually use Visual Studio Code to develop the project.
- Install Python >= 3.10
- Configure Python on Visual Studio Code.
- Clone or Import the project into Visual Studio Code.
- Once import, modify the
data/config.py
file with your Test settings. - Open
botaffiumeiro.py
. - Run the code (better with a Virtual Environment).
- Profit.
For testing you could directly run test with Visual Studio Code Testing tab. Or installing pytest with pip install pytest
and then run the test with python -m pytest tests/
.