Skip to content

ChrisPham03/Chat-Bot-Assistant-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Salon Booking Chatbot

A purpose-built, containerized Rasa chatbot designed to assist customers with salon bookings, cancellations, and rescheduling, as well as to answer frequently asked questions.

This project is built to run in a custom, multi-container Docker environment, specifically compiled to be fully compatible with Apple Silicon (arm64) hardware.


Core Features

  • Appointment Booking: A multi-step form that collects user details (service, date, time, name, contact).
  • Appointment Cancellation: A custom action (action_cancel_appointment) that locates a user's booking and removes it.
  • Advanced Validation: Custom Python logic in actions.py validates user input against business rules, such as:
    • Checking for valid business hours.
    • Preventing double-bookings.
    • Handling date-only inputs (e.g., "next Saturday") vs. full timestamps.
  • FAQ Handling: Responds to simple queries like opening hours (ask_hours).
  • Persistent Storage: Saves and manages appointments in a appointments.json file, made persistent via a Docker Named Volume.

Technology Stack

  • Backend: Rasa, Python 3.10
  • NLU: Duckling (for time, date, and phone-number entity extraction)
  • Containerization: Docker & Docker Compose
  • Frontend Widget: React, Axios
  • Testing Dashboard: Flask (Provides a calendar view of appointments.json)

Project Architecture

This project is a full-stack application composed of two main parts within this repository:

  1. salon-bot/: The complete Rasa backend. It is managed by docker-compose.yml, which orchestrates four services:
    • rasa: The main Rasa server for NLU and dialogue.
    • action-server: Runs all custom Python logic from actions/actions.py.
    • duckling: The entity extraction service.
    • dashboard: A simple Flask server that provides a test calendar UI.
  2. salon-widget-ui/: A standalone React application that provides a modern chat interface to interact with the Rasa backend.

The Apple Silicon (arm64) Challenge: A Project Case Study

A primary challenge of this project was deploying on an Apple Silicon Mac. Official Docker images for Rasa and Duckling are built for the amd64 (Intel/AMD) architecture, which is incompatible with Apple's arm64 chips. This caused low-level AVX instructions errors, making the standard setup unusable.

The solution involved abandoning pre-built images and engineering a custom, multi-container environment from the ground up.

  1. Custom Rasa Image: The main Dockerfile uses a python:3.10-slim (arm64) base image and installs Rasa from source. This ensures all Python dependencies, including TensorFlow, are compiled natively for arm64.
  2. Custom Duckling Image: The duckling/Dockerfile builds Duckling from its Haskell source. This required patching the build process to solve two issues:
    • OS Dependency: The build used an old Debian "Buster" image, which required redirecting apt-get to the archive repositories.
    • Compiler Dependency: The build was pinned to a specific GHC (Haskell compiler) version, which was sourced from an older base image.
  3. Docker Networking Fix: A bug in Docker's internal DNS service prevented the rasa container from resolving the duckling container. This was solved by adding an explicit links directive in the docker-compose.yml file.
  4. File Permission Fix: The Action Server container was unable to write to the appointments.json file due to a Docker file-sharing bug. This was definitively solved by moving the file into a Docker Named Volume (salon-data), which grants the container proper ownership.

Getting Started

Prerequisites

Installation

  1. Clone the Repository

    git clone https://github.com/ChrisPham03/Chat-Bot-Assistant-.git
    cd Chat-Bot-Assistant-
  2. Create a .gitignore file To keep your repository clean, create a file named .gitignore in the project root (Chat-Bot-Assistant-) and add the following:

    # Rasa cache and models
    salon-bot/.rasa/cache/
    salon-bot/models/
    salon-bot/results/
    
    # Python cache
    salon-bot/__pycache__/
    salon-bot/actions/__pycache__/
    
    # Node modules
    salon-widget-ui/node_modules/
    
    # OS-specific
    .DS_Store

How to Run the Application

This project requires two separate terminal processes to run the backend and frontend.

Part 1: Run the Backend (Rasa)

  1. Navigate into the backend directory:

    cd salon-bot
  2. Build the Custom Images This command builds the custom rasa and duckling images. You only need to re-run this if you change Dockerfile, requirements.txt, or the duckling/ source.

    docker-compose build
  3. Train Your First Model This command runs a one-off container to train your NLU model.

    docker-compose run --rm rasa train
  4. Start All Services This command starts the Rasa server, Action Server, Duckling, and the Flask Dashboard in detached mode.

    docker-compose up -d

Part 2: Run the Frontend (React Chat Widget)

  1. Open a new terminal and navigate to the root folder (Chat-Bot-Assistant-).

  2. Navigate into the frontend directory:

    cd salon-widget-ui
  3. Install Dependencies

    npm install
  4. Start the React App

    npm start

How to Interact with Your Bot

Option 1: React Chat Widget (Recommended)

Once both the backend and frontend are running, open your browser and go to: http://localhost:3000

You will see the chat widget and can interact with your bot live.

Option 2: Test Dashboard Calendar

You can view the appointments saved in appointments.json on a simple calendar. This dashboard is started by docker-compose up.

Visit the Flask dashboard in your browser (check your docker-compose.yml for the exposed port, e.g., http://localhost:5001).

Option 3: cURL (API Testing)

You can send messages directly to the Rasa server's REST API.

Full Booking Flow Example:

# 1. Start the conversation
curl -X POST http://localhost:5006/webhooks/rest/webhook \
  -H "Content-Type: application/json" \
  -d '{"sender": "test_user", "message": "I want to book a Men''s Cut on next saturday"}'

# 2. Bot will ask for a time. Respond:
curl -X POST http://localhost:5006/webhooks/rest/webhook \
  -H "Content-Type: application/json" \
  -d '{"sender": "test_user", "message": "How about 4pm"}'

# 3. Bot will ask for a name. Respond:
curl -X POST http://localhost:5006/webhooks/rest/webhook \
  -H "Content-Type: application/json" \
  -d '{"sender": "test_user", "message": "My name is Susan"}'

# 4. Bot will ask for contact info. Respond:
curl -X POST http://localhost:5006/webhooks/rest/webhook \
  -H "Content-Type: application/json" \
  -d '{"sender": "test_user", "message": "555-555-1234"}'

Check the Database: To confirm the booking was saved, you can "look inside" the container's volume:

docker exec salon-bot-action-server-1 cat /data/appointments.json

Option 4: Rasa Shell (Debug Mode)

The best way to debug the NLU/dialogue flow is in the terminal.

# Make sure you are in the salon-bot/ directory
docker-compose run --rm rasa shell --debug

About

A purpose-built chatbot designed to assist customers with salon bookings, cancellations, and rescheduling, as well as to answer frequently asked questions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors