This is a personal project that utilizes the whatsapp-web.js library and the GPT-3.5 Turbo model to automate WhatsApp messages responses and use Dall-E to generate images from prompts.
The bot was developed using the following technologies:
- NestJS - Provides a scalable architecture for server app development.
- Prisma - ORM that makes database interactions easier.
- PostgreSQL - Open source relational database.
- OpenAI API - API for natural language processing and artificial intelligence.
- TypeScript - A JavaScript superset that adds static typing to the language.
- Fastify - Used as an adapter with NestJS focusing on performance and scalability.
- Conversation utilizing the power of ChatGPT by just sending messages through WhatsApp.
- Image generation using the command
/imagine your prompt
. - Clear the message history from the database using the command
/clear
. - Get help on available commands using the command
/help
.
See the image below as an example:
To begin using the BOT, follow these steps:
-
Send a text message to the whatsapp number +55 (88) 98147-8937 or click here.
-
The message will be forwarded to the ChatGPT API for an automatic response. When using the environment, please bear in mind that all sent and received messages are stored in a database. These messages will be kept until the
/clear
command is executed to clear the history.
Additionally, while using the ChatGPT API and Dall-E, keep in mind that the terms of use of OpenAI also apply. Please ensure to review and agree with these terms before using the API.
To install and configure the API, follow the steps below:
- Create an account on OpenAI and grab your credentials. Create the
.env
file. The.env.example
file is in the root of the project. See example below:
OPENAI_API_KEY=
DATABASE_URL=
BOT_PERSONA="Bot Persona"
The DATABASE_URL
field must be filled with your database URL. By default, it is configured to use PostgreSQL.
- Install the project dependencies with the following command:
npm install
- Start the API on localhost with the command:
npm run start:dev
-
Wait for the QR Code to appear in the Terminal, on your mobile Whatsapp go to "Connected Devices" and scan the QR Code Generated.
-
Now, just send a message to your number and wait for the response.