AntiChatBot is a Python desktop application designed to automate the initial interaction phase with website chat widgets. It aims to bypass automated bot responses and directly request a connection with a human operator. The application uses Selenium for web automation, a configuration file (config.json) for site settings, and optionally integrates with a Telegram bot via Redis for operator notifications and CAPTCHA solving assistance.
- Graphical User Interface (GUI): Built with Tkinter for site selection and status monitoring.
- Configuration Driven: Uses
config.jsonfor site URLs, selectors, bot phrases, etc. - Web Automation: Uses Selenium to interact with web chats.
- Human Emulation: Basic scrolling and mouse movements.
- Improved Operator Detection: Checks all new messages for operator patterns, uses site-specific patterns and configurable bot phrases.
- Unique Responses: Cycles through available operator request templates to avoid repetition.
- Multi-step Chat Opening: Handles sites requiring multiple button clicks to initiate chat (e.g., cookie consent, post-open buttons).
- Manual Step Handling: Pauses for user input on pre-chat forms.
- Browser Persistence: Option to keep the browser window open after an operator is found.
- (Optional) Telegram Integration via Redis:
- Sends notifications to your Telegram when an operator connects.
- Sends CAPTCHA images to your Telegram and waits for you to send back the solution.
- Support for multiple sites: Pre-configured for Tele2, Beeline, Yota.
- Loads configurations from
config.jsonand secrets from.env. - The GUI appears.
- A separate
telegram_bot.pyscript connects to Telegram and listens to Redis channels. - User selects a site and clicks "Начать диалог".
- Selenium browser starts, navigates, and handles preliminary button clicks (e.g., cookies).
- User might need to log in manually in the browser.
- The app clicks the main chat button and any subsequent required buttons (e.g., "Пока нет" on Yota).
- User Interaction (Form): GUI prompts user (
ACTION REQUIRED) to fill the pre-chat form in the browser, if applicable. - User fills the form and clicks "Продолжить (после формы)" in the GUI.
- The app sends an initial message.
- The app enters a loop:
- Waits for responses (reduced wait time).
- If CAPTCHA detected: Publishes the image data to Redis.
telegram_bot.pyreceives it, sends the image to the user via Telegram. The main app waits for the user to send the solution text to the Telegram bot.telegram_bot.pypublishes the solution back via Redis. The main app receives it and sends it to the web chat. - Checks all new messages: Iterates through all new messages received since the last check.
- If operator message detected in any new message: Publishes a notification to Redis.
telegram_bot.pyreceives it and sends a notification to the user via Telegram. The main app loop finishes, leaving the browser window open. - If only bot messages detected: Chooses a unique, not recently used template from
response_templatesand sends it.
- Loop continues until operator found or max attempts reached.
- Status updates displayed in GUI.
- Contains
_defaultsfor common patterns (operator/bot phrases, response templates, emulation). - Contains a
sitessection where each key is a site name (e.g.,Tele2,Beeline,Yota):login_url: Chat/login page URL.cookie_consent_button_selector(Optional): CSS selector for the cookie consent button.chat_button_selector: CSS selector for the primary chat initiation button.post_chat_open_button_selector(Optional): CSS selector for a button that needs to be clicked after the main chat button (e.g., "Пока нет" on Yota).selectors: Dictionary of CSS selectors for chat interaction:input_field: The text input area.send_button: The message send button.messages_area: The container for all messages.individual_message: Selector for a single message bubble/element.text_content_selector(Optional): A more specific selector withinindividual_messageto extract only the message text (useful for sites like Beeline where the default text includes sender/time).
operator_join_patterns(Optional): List of site-specific regex patterns indicating an operator joined. Overrides_defaults.bot_indicator_phrases(Optional): List of site-specific phrases indicating a bot message. Checked beforeoperator_join_patterns. Overrides_defaults.max_operator_request_attempts(Optional): Maximum attempts to request an operator. Overrides_defaults.
Note: Accurate selectors are crucial. Use browser developer tools (F12) to find them.
-
Prerequisites:
- Python 3.8+
- Google Chrome browser
- Docker Desktop (Windows/macOS) or Docker Engine (Linux) installed and running.
-
Redis Setup (using Docker):
- Redis is used for communication between the GUI, Chat Service, and the Telegram Bot.
- The easiest way to run Redis is using the provided
docker-compose.ymlfile. - Open your terminal in the project root directory and run:
docker-compose up -d
- This will start a Redis container in the background.
- To check logs:
docker-compose logs redis - To stop:
docker-compose down - Ensure Redis is running via Docker Compose before starting the application components.
-
Clone the repository:
git clone <your-repository-url> cd AntiChatBot
-
Create and activate a virtual environment (recommended):
python -m venv venv # On Windows .\venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies:
# Ensure you have the job queue extra for the Telegram bot python -m pip install --upgrade "python-telegram-bot[job-queue]" pip install -r requirements.txt
(Installs Selenium, webdriver-manager, redis-py, python-dotenv, python-telegram-bot, etc.)
-
(Optional but Recommended) Telegram Bot Setup:
- Open Telegram and talk to
BotFather. - Create a new bot using
/newbotcommand and follow instructions. - Copy the BOT TOKEN provided by BotFather.
- Talk to
userinfobot(or similar) in Telegram to get your numerical USER ID. - Create a file named
.envin the project root directory. - Add the following lines to
.env, replacing the placeholders with your actual token and ID:TELEGRAM_BOT_TOKEN=12345:your_actual_bot_token_here TELEGRAM_USER_ID=987654321 # Optional: Specify Redis connection if not localhost:6379 # REDIS_HOST=your_redis_host # REDIS_PORT=your_redis_port
- Ensure
.envis listed in your.gitignorefile!
- Open Telegram and talk to
-
Configure
config.json:- Add/modify entries in the
sitessection. Pay close attention to all CSS selectors. Use the optional selectors (cookie_consent_button_selector,post_chat_open_button_selector,text_content_selector) as needed for specific site behavior. - Refine
operator_join_patternsandbot_indicator_phrasesin_defaultsor add site-specific overrides for better accuracy.
- Add/modify entries in the
The application now runs as three separate components that communicate via Redis. You will need three separate terminal windows open in the project root directory.
-
Start Redis:
- Make sure Docker Desktop is running.
- In one terminal, run:
docker-compose up -d
- Leave this running. You only need to do this once unless you stop it with
docker-compose down.
-
Start the Chat Service:
- Open a second terminal.
- Activate the virtual environment:
# Windows .\venv\Scripts\activate # macOS/Linux source venv/bin/activate
- Run the Chat Service script. This service listens for session requests from the GUI and manages the browser automation.
python chat_service.py
- Keep this terminal running.
-
(Optional) Start the Telegram Bot:
- If you configured the
.envfile for Telegram integration, open a third terminal. - Activate the virtual environment.
- Run the Telegram Bot script. This bot handles CAPTCHA requests and operator notifications.
python telegram_bot.py
- Keep this terminal running.
- Important: Send the
/startcommand to your bot in Telegram at least once to initiate the chat if you haven't already.
- If you configured the
-
Start the GUI Client:
- Open a fourth terminal (or reuse one if not running the Telegram bot).
- Activate the virtual environment.
- Run the GUI script. This is the user interface you interact with.
python gui.py
-
Interact with the GUI:
- Select the desired website from the dropdown.
- Click "Начать диалог".
- The Chat Service (running in its terminal) will launch a Chrome browser window.
- Follow the status updates in the GUI.
- If prompted with
ACTION REQUIRED / ТРЕБУЕТСЯ ДЕЙСТВИЕ:- Switch to the browser window.
- Fill any required pre-chat forms and submit the form on the website.
- Switch back to the AntiChatBot GUI and click "Продолжить (после формы)".
-
Monitor the process:
- The application will attempt to reach an operator.
- If CAPTCHA appears: (Requires Telegram Bot running) You will receive the image in Telegram. Reply to the bot with the text from the image.
- If operator connects: (Requires Telegram Bot running) You will receive a notification in Telegram. The main GUI will also indicate success. The browser window controlled by the Chat Service will remain open.
-
Closing:
- To stop a session, simply close the GUI window. This will send a signal to the Chat Service to attempt a clean shutdown of that specific session.
- If the operator was found or the GUI was closed manually, the Chat Service will leave the browser open.
- If the session failed (timeout, errors, operator not found without manual closure), the Chat Service will automatically close the browser for that session.
- To stop all components: Close the GUI window, press
Ctrl+Cin thechat_service.pyandtelegram_bot.pyterminals, and rundocker-compose downin the terminal where you started Redis.