Welcome to the Spring Boot Chatbot project! This application integrates multiple technologies and libraries to deliver a robust chatbot experience, including SMS interactions, PDF document reading, and natural language processing capabilities. Below is a detailed description of the project, including setup instructions, dependencies, and key features.
- Prerequisites
- Setup Instructions
- Configuration
- Project Structure
- Key Features
- API Endpoints
- Dependencies
- Usage
- Contributing
- License
- Java 17: Ensure that Java Development Kit (JDK) version 17 is installed on your machine.
- Maven: This project uses Maven for build and dependency management. Install Maven from here.
- Neo4j: Download and set up a Neo4j database from here.
- OpenAI API Key: Register and obtain an API key from OpenAI.
- Africastalking API Key: Register and obtain your username and API key from Africastalking.
-
Clone the repository:
git clone https://github.com/Titus-Nyandoro/Chatbot.git cd Chatbot
-
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
-
OpenAI API Key:
- Add your OpenAI API key to the
application.properties
file:
openai.api.key=your_openai_api_key
- Add your OpenAI API key to the
-
Africastalking Configuration:
- Add your Africastalking username and API key to the
application.properties
file:
africastalking.username=your_username africastalking.api.key=your_api_key africastalking.shortcode=your_sms_shortcode
- Add your Africastalking username and API key to the
-
Neo4j Database URL:
- Add your Neo4j database connection details to the
application.properties
file:
neo4j.url=bolt://localhost:7687 neo4j.username=your_neo4j_username neo4j.password=your_neo4j_password
- Add your Neo4j database connection details to the
-
System Message Configuration:
- Define the system message by modifying the
system-message.txt
file located in thesrc/main/resources
folder. This message will be used to guide the chatbot's responses.
- Define the system message by modifying the
-
Load PDF Documents:
- Add important PDF documents to the
docs
folder located insrc/main/resources
. These documents will be parsed by the chatbot for information retrieval.
- Add important PDF documents to the
The project follows a typical Spring Boot structure:
spring-boot-chatbot/
│
├── src/
│ ├── main/
│ │ ├── java/com/example/chatbot/
│ │ │ ├── config/ # Initial Configs
│ │ │ ├── controller/ # Controllers for handling API requests
│ │ │ ├── service/ # Service layer for business logic
│ │ │ ├── model/ # Domain models and DTOs
│ │ │ ├── repo/ # repositories
│ │ │ ├── service/ # Services for API processing
│ │ │ ├── utils/ # Necessary app utils
│ │ │ └── ChatbotApplication.java # Main Spring Boot application class
│ │ └── resources/
│ │ ├── application.properties # Configuration file
│ │ ├── system-message.txt # System message for the chatbot
│ │ ├── docs/ # Folder for PDF documents
│ └── test/ # Unit and integration tests
│
└── pom.xml # Maven build file
- PDF Document Reader: Integrates with Spring AI PDF Document Reader for document parsing.
- Neo4j for Vector Database: Utilizes Neo4j for efficient storage and retrieval of vector data.
- OpenAI Integration: Uses OpenAI for text embedding and completion.
- SMS Interaction: Implements SMS parsing and sending using the Africastalking library with a response limit of 144 characters.
- Endpoint:
/send
- Method:
POST
- Request Body:
SmsRequest
- Response:
SmsResponse
@PostMapping("/send")
public ResponseEntity<SmsResponse> SendSms(@RequestBody SmsRequest smsRequest) {
log.warn("Send sms {}", smsRequest);
return ResponseEntity.ok(smsService.sendSms(smsRequest));
}
- Endpoint:
/incoming
- Method:
POST
- Consumes:
application/x-www-form-urlencoded
- Request Body:
IncomingSmsDTO
@PostMapping(value = "/incoming", consumes = "application/x-www-form-urlencoded")
public void processIncomingSms(@ModelAttribute IncomingSmsDTO smsPayload) {
log.warn("Incoming sms {}", smsPayload);
smsService.processIncomingSms(smsPayload);
}
- Spring Boot: Core framework for building the application.
- Maven: For project build and dependency management.
- Spring AI PDF Document Reader: To handle PDF document reading.
- Neo4j: For vector database functionality.
- OpenAI: For embedding and text completion capabilities.
- Africastalking: For SMS functionalities limited to 144 characters.
<dependencies>
<!-- Spring Boot Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- Neo4j Dependency -->
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
</dependency>
<!-- OpenAI Dependency -->
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java-client</artifactId>
</dependency>
<!-- Africastalking Library -->
<dependency>
<groupId>com.africastalking</groupId>
<artifactId>africastalking-sms</artifactId>
</dependency>
</dependencies>
-
Sending SMS:
- Send a POST request to
/send
withSmsRequest
payload to send an SMS. - The system will respond with
SmsResponse
.
- Send a POST request to
-
Receiving SMS:
- Configure your SMS gateway to forward messages to
/incoming
. - The system will process incoming messages automatically.
- Configure your SMS gateway to forward messages to
-
Loading PDF Documents:
- Ensure that the
docs
folder undersrc/main/resources
is loaded with PDF files that contain important information. The application loops through these files to parse and use the content.
- Ensure that the
-
Configuring System Message:
- Modify the
system-message.txt
file located insrc/main/resources
to set up a customized system message for the chatbot.
- Modify the
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes. Ensure your code adheres to the project’s coding standards and includes relevant tests.
This project is licensed under the MIT License - see the LICENSE file for details.