Coder Social home page Coder Social logo

akgupta1337 / chatcraft Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 86 KB

ChatCraft is an simple WhatsApp chat bot project that showcases expertise in web automation, smart command parsing, and dynamic content generation.

License: MIT License

Python 100.00%
autmation python selenium-webdriver whatsapp-bot 1st-year

chatcraft's Introduction

ChatCraft: Automated WhatsApp Conversations

Description

ChatCraft is an simple WhatsApp chat bot project that showcases expertise in web automation, smart command parsing, and dynamic content generation. Leveraging external APIs, it provides real-time information such as weather updates, news, and more. The project's robust reminder system enhances user engagement by delivering timely and personalized reminders.

Usage

cd src
run main.py

Key Features

  1. Web Automation with Selenium:

    • Seamless interaction with the web version of WhatsApp using Selenium.
    • Robust element locating, waiting strategies, and browser automation.
  2. Text Processing and Command Parsing:

    • Advanced text processing techniques for extracting and parsing user commands effectively.
    • Handles diverse command formats for an improved user experience.
  3. Dynamic Responses and Chat Interactions:

    • Dynamic response generation based on user commands.
    • Interactive chat features delivering greetings, weather updates, news, jokes, quotes, and basic calculations.
  4. API Integration:

    • Integration of external APIs for real-time data retrieval.
    • Proficient in making HTTP requests, processing JSON responses, and seamlessly integrating external data.
  5. Reminder System and Time Handling:

    • Sophisticated reminder system for scheduling and delivering reminders.
    • Proficient in time-related operations, including parsing, formatting, and comparing time values.

Usage

  1. Specify Target Group/Chat:

    • Select a specific group or chat in the main function while accessing the start method of the class Auto.
  2. Specify Chrome Profile and Username:

    • Set your profile and username to avoid rescanning the QR code for WhatsApp Web.
  3. Supported Commands:

    • !help
    • !add [numbers]
    • !multiply [numbers]
    • !yell [message]
    • !info
    • !greet [name]
    • !weather [location]
    • !news [category]
    • !quote
    • !joke
    • !define [word]
    • !reminder [time(24-hour)] [message]

Code Explanation:

First, I've created two modules: ChatCraft and BotFunctions. The role of the ChatCraft class is to initialize the driver with specified chat name, profile data, and directory. It allows accessing web.whatsapp.com in an existing Chrome profile, eliminating the need to scan the QR code each time the bot runs. The start method opens the URL using the driver.get function from the Selenium module.

    def __init__(self, profile, user_name):

        self.user_name = user_name
        self.profile = profile
        self.reminders = []
        self.options = self.configure_driver_options()
        self.driver = webdriver.Chrome(options=self.options)

The get_group method is called at the end of the start method. It finds the group element based on the provided chat name, clicks on it, and initializes the text area for messages. A welcome message and emojis are then sent to the group. The start_reading method is invoked afterward.

def get_group(self):
    # Code to locate the group, initialize the text area, and send a welcome message
    # ...
    self.start_reading()

The start_reading method continuously reads messages, checks if they start with "!", and calls the get_respond method to handle user commands. It sends the appropriate response back to the chat.

def start_reading(self):
    while True:
        self.reminder()
        time.sleep(5)
        msg = self.get_chat()
        if msg.startswith("!"):
            # Code to prepare a response based on the user's command
            # ...
            self.send_input(send_msg)
        else:
            continue

The get_chat method retrieves the latest message by locating elements and returning the text of the last element.

def get_chat(self):
    # Code to retrieve the latest message
    # ...
    return str(msg)

The reminder function handles reminders specified by the user. It parses the time, calculates the difference, and sends a reminder message at the appropriate time.

elif msg.startswith("!reminder"):
    try:
        # Code to parse time, set reminders, and generate response
        # ...
confirmation_message = f"Sure! Will remind you to *{reminder_message.upper()}* in {remind_in_message}"
    return (confirmation_message, reminder_dict)

This block ensures that reminders are sent to the user based on the specified time and message. A 5-second delay is added after sending the first reminder to prevent continuous reminders for one minute.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.