Code Monkey home page Code Monkey logo

wahgpt-bot's Introduction

WahGPT - WhatsApp Chatbot with GPT Integration

WahGPT is a WhatsApp chatbot built using the whatsapp-web.js library, allowing users to interact with an intelligent chatbot powered by GPT (ChatGPT) and create DALL路E-generated images. This README provides a comprehensive explanation of the code structure and functionality.

Features

  • WhatsApp Integration: Utilizes whatsapp-web.js to connect to the WhatsApp Web platform, enabling the bot to send and receive messages.
  • GPT Integration: Communicates with the ChatGPT API to generate responses based on user input.
  • DALL路E Integration: Generates images using the DALL路E API in response to specific commands.

Getting Started

Prerequisites

  • Node.js and npm installed on your machine.
  • WhatsApp account and a phone with an active internet connection.

Installation

  1. Clone the repository:

    git clone https://github.com/well300/WahGPT.git
  2. Navigate to the project directory:

    cd WahGPT
  3. Install dependencies:

    npm install
  4. Create a .env file in the root directory with the following content:

    CHATGPT_API_URL=https://guruapi.tech/api/chatgpt
    DALLE_API_URL=https://aemt.me/dalle

    Replace the URLs with the actual endpoints you want to use.

  5. Run the application:

    npm start
  6. Scan the QR code displayed with your WhatsApp Web to authenticate.

Code Structure

1. Initialization

The script initializes the WhatsApp client and sets up event listeners for authentication, QR code display, and readiness.

2. API URL Configuration

Environment variables are used to configure the URLs for the ChatGPT and DALL路E APIs. This allows for easy modification without altering the code.

const apiUrl = `${process.env.CHATGPT_API_URL}?text=${encodeURIComponent(text)}`;

3. Message Processing

The message event listener handles incoming messages. It checks for specific commands, interacts with APIs, and sends appropriate responses.

3.1. ChatGPT Integration

The getChatGPTResponse function makes a request to the ChatGPT API and processes the response.

3.2. DALL路E Integration

The getDALLEImage function generates images using the DALL路E API in response to the /dalle command.

4. Response Formatting

Responses are formatted with emojis based on certain conditions or keywords in the reply.

// Add emojis based on conditions or keywords in the response
if (response.toLowerCase().includes("hello")) {
  emojiResponse += " 馃憢";
} else if (response.toLowerCase().includes("thank you")) {
  emojiResponse += " 馃檹";
}

5. Error Handling

The script includes error handling to gracefully manage API errors and other exceptions.

Usage

  1. Send messages to the WhatsApp number associated with the bot.
  2. Use the /dalle command to generate DALL路E images based on text input.
  3. Experience intelligent responses generated by ChatGPT.

Contributing

Feel free to contribute by submitting issues or pull requests. Your feedback and improvements are welcomed!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Thanks to the authors of whatsapp-web.js for providing a powerful library for WhatsApp Web automation.
  • Appreciation to OpenAI for ChatGPT and DALL路E APIs.

Happy Chatting with WahGPT! 馃馃殌

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.