This project implements an appointment booking assistant using WebSockets and OpenAI's GPT-4 model. The bot can manage conversations to book appointments, handle user messages, and keep track of session states.
- WebSocket-based real-time communication
- State management for user sessions
- Integration with OpenAI's GPT-4 for natural language understanding
- Dynamic response generation based on user inputs
- Mock data for departments, doctors, and available times
.
├── main.go # Main application entry point
├── .env # Environment variables file
├── go.mod # Go module file
└── go.sum # Go dependencies file
- Go 1.22.5+
- Docker (for running in a containerized environment, optional)
-
Clone the repository:
git clone https://github.com/your-username/appointment-booking-bot.git cd appointment-booking-bot
-
Create a
.env
file in the project root directory with your OpenAI API key:OPENAI_API_KEY=your-openai-api-key
-
Install dependencies:
go mod tidy
-
Start the application:
go run main.go
-
The server will start on port
8080
. Connect to it using a WebSocket client atws://localhost:8080/ws
.
OPENAI_API_KEY
: Your OpenAI API key.
The bot manages user sessions to book appointments with the following states:
start
: Initial state.awaiting_client_status
: Asking if the user is a new or existing client.awaiting_email_new
: Asking for the email address of a new client.awaiting_email_existing
: Asking for the email address of an existing client.awaiting_name
: Asking for the name of a new client.awaiting_department
: Asking for the department for the appointment.fetch_doctor_department
: Fetching available doctors for the selected department.awaiting_doctor
: Asking for the preferred doctor.awaiting_time
: Asking for the preferred appointment time.awaiting_address_option
: Asking if the user wants to provide a pickup address.awaiting_address
: Asking for the pickup address.completed
: Final state when the appointment is successfully booked.
User: start
Bot: Hello, are you a new client or existing client? Please respond with 'new' or 'existing'.
User: new
Bot: Please provide your email address.
User: user@example.com
Bot: Please provide your name.
User: John Doe
Bot: Which department would you like to book an appointment with? Available departments are: A - Cardio, B - Ortho, C - Neuro, D - Gync, E - General.
User: B
Bot: Available doctors in Ortho department: A - Dr. Jagadeesh MS, B - Dr. Ravikiran MS, C - Dr. Haitham MS. Please select a doctor.
User: A
Bot: Available times for appointments are: A - 09:00, B - 10:00, C - 11:00, D - 12:00. Please select a time.
User: B
Bot: Would you like to provide an address for pickup? (yes/no)
User: yes
Bot: Please provide your address.
User: 123 Main St
Bot: Your appointment has been booked successfully!
github.com/gorilla/websocket
: WebSocket library for Go.github.com/joho/godotenv
: Library to load environment variables from a.env
file.github.com/sashabaranov/go-openai
: Go client for OpenAI API.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- OpenAI for their powerful GPT-4 model.
- Gorilla WebSocket library for handling WebSocket connections.
For any questions or suggestions, please reach out to your-email@example.com.