Skip to content

JDGonzal/AI-Chatbot-Code-Challenge

Repository files navigation

AI-Powered Chatbot Order Status Service: End-to-End Code Challenge

AI_Chatbot_Code_Challenge(20250723)

Important

Problem Description

I am creating a custom chat app to interact with my clients. The chatbot must be polite, maintain focus on delivering an excellent customer experience, and provide accurate, specific information about the chosen product. Each team should select a different product for their chatbot to support (e.g., a SaaS analytics tool, an e-commerce platform, or a fleet-management system).

The technical details are into this README.md

🎥 Demo Video

AI Chatbot Demo

Watch the AI Chatbot in action processing financial queries with authentication and real-time data retrieval

Part 1: User Stories & MVP Definition

  1. As Stock Market User I need to know the last "United States Indices":
    {"username":"Admin","question":"What are the United States Indices?"}
  2. As Stock Market User I need to know the last "Most Active Stocks":
    {"username":"Admin","question":"What are the Most Active Stocks?"}
  3. As Stock Market User I need to know the last "Top Gainers":
    {"username":"Admin","question":"What are the Top Gainers?"}
  4. As Stock Market User I need to know the last "United States Sector Summary"
    {"username":"Admin","question":"What is the list Sector Summary?"}

The site to do this request and scraping is:

Part 2: Project Kick-off & Scaffolding

  • Project will use Node.js/Express
  • This will be the directory layout:
    Layout of the project
  • Commit to git using the tree definiction as:
    • feature: This feature branch isolates the new code or changes related to that specific functionality.
    • hotfix: To isolate the fixes from the main (master) development line.

Part 3: Authentication & Session Management

Objective: Secure your chatbot with user/password login.

The URL of the API, is this:
https://webapp-ai-chatbot-cdg8a7cpetckeja2.westeurope-01.azurewebsites.net/

  1. The user creation must be with the API using:
    » Method: POST
    » URL: api/auth/register
    » Body: {"username":"NewName", "password": "abcd1234"}
  2. The user login to get the token:
    » Method: POST
    » URL: api/auth/login
    » Body: {"username":"NewName", "password": "abcd1234"}
  3. The check of validation (Optional):
    » Method: GET
    » URL: api/chat/can-access
    » Body: {"username":"NewName"}
    » Header: x-auth-token=<token>
  4. Chat with Chatbot:
    » Method: POST
    » URL: api/chat
    » Body: {"username":"NewName","question":"What are the Most Active Stocks?"}
    » Header: x-auth-token=<token>

Click here to get the Postman JSON file to import

Part 4: Building the Core Chat API

Objective: Implement the /chat endpoint and integrate with an LLM API

After the user validation with the token, those are the steps:

  1. Scraping and text extraction
    For of FINANCE_URLS and fetchAndExtractText()
  2. Chunking
    ChunkText();
  3. Embeddings of the chunks
    embedChunks();
  4. Vectorizing in Pinecone
    upsertEmbeddings();
  5. Embedding of the question and search
    embedChunks([q]) and searchSimilarChunks()
  6. OpenAI Validation and Improvement
    validateAndImproveChunks() - Validates and improves chunk quality
  7. OpenAI Response Generation
    generateResponseFromChunks() - Generates coherent responses using OpenAI

Part 5: Simulating RAG (Knowledge Base Retrieval)

Objective: Augment replies with product context.

Part 6: Automated Testing ✅ COMPLETED

Objective: Generate and run unit/integration tests.

Implementation: Comprehensive Jest test suite with 45+ tests covering authentication flows, LLM integration, and retrieval logic. All external services (OpenAI, Pinecone, web scraping) are properly mocked for fast, reliable testing.

Usage:

npm install
npm test                    # Run all tests
npm run test:coverage      # Run with coverage report
npm run test:watch         # Development watch mode

📖 Detailed Testing Documentation - Complete guide to the test suite, coverage details, and test scenarios.

Part 7: CI/CD Pipeline Setup

Objective: Automate build, test, and deploy.

Part 8: Cloud Deployment & Env Configuration

Objective: Deploy your containerized chatbot to the cloud.

🧪 Testing Infrastructure

The project includes a comprehensive automated testing suite:

  • Unit Tests: Controllers, middleware, and services
  • Integration Tests: Complete API endpoints with authentication
  • Mocked Services: OpenAI, Pinecone, and web scraping services
  • Coverage: 80%+ lines, functions, branches, and statements
  • CI/CD Ready: No external dependencies for testing

Quick Start:

npm test

For detailed testing information, see Testing Documentation.

Bonus Extensions

  • Swap JWT for OAuth2 or SSO integration.
  • Implement a front-end chat widget that handles login and chat sessions.
  • Add observability: logs, metrics, and a health check endpoint.

Delivery