Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logistics AI Chatbot

A sophisticated AI-powered logistics chatbot built with .NET 8 and Clean Architecture, demonstrating enterprise-grade AI agent capabilities for delivery and shipping management.

πŸ—οΈ Architecture

This project follows Clean Architecture principles with clear separation of concerns:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      PRESENTATION LAYER                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Telegram Bot (Program.cs)                   β”‚   β”‚
β”‚  β”‚        Handles user interactions and commands            β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     INFRASTRUCTURE LAYER                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   EF Core    β”‚  β”‚  Semantic    β”‚  β”‚   Telegram.Bot       β”‚  β”‚
β”‚  β”‚   SQLite     β”‚  β”‚   Kernel     β”‚  β”‚   Integration        β”‚  β”‚
β”‚  β”‚  DbContext   β”‚  β”‚   OpenAI     β”‚  β”‚   Service            β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      APPLICATION LAYER                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚    DTOs      β”‚  β”‚   Services   β”‚  β”‚   Semantic Kernel    β”‚  β”‚
β”‚  β”‚  (Data       β”‚  β”‚  (Order,     β”‚  β”‚     Plugins          β”‚  β”‚
β”‚  β”‚  Transfer)   β”‚  β”‚   Cost,      β”‚  β”‚   (Logistics,        β”‚  β”‚
β”‚  β”‚              β”‚  β”‚   AI Agent)  β”‚  β”‚    FAQ)              β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        DOMAIN LAYER                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Entities   β”‚  β”‚    Value     β”‚  β”‚    Interfaces        β”‚  β”‚
β”‚  β”‚  (Order,     β”‚  β”‚   Objects    β”‚  β”‚   (IOrderRepo,       β”‚  β”‚
β”‚  β”‚   Client,    β”‚  β”‚  (Dimensions,β”‚  β”‚    IClientRepo,      β”‚  β”‚
β”‚  β”‚   Status)    β”‚  β”‚   Address)   β”‚  β”‚    IUnitOfWork)      β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Dependency Flow

Presentation β†’ Infrastructure β†’ Application β†’ Domain
     ↓              ↓               ↓            ↓
  Bot UI        EF Core +       Business      Core
              Semantic Kernel     Logic      Entities

Key Principle: Dependencies flow inward. The Domain layer has no external dependencies.

πŸš€ Features

1. Create Delivery Order

  • AI extracts shipment details from natural language
  • Supports origin/destination cities, weight, dimensions, cargo type
  • Automatic cost calculation and order number generation
  • Persisted to SQLite database

2. Delivery Cost Calculator

  • AI-powered parsing of casual cost queries
  • Distance-based calculation (using Haversine formula)
  • Weight and volume coefficients
  • Cargo type multipliers (Documents, Fragile, Oversized, Standard)
  • Detailed cost breakdown

3. Order Status Tracking

  • Query orders by order number
  • Full status history with timestamps
  • Estimated delivery date

4. FAQ Consultant

  • Semantic Kernel powered Q&A
  • Topics: shipping times, international delivery, packaging, prohibited items, insurance, etc.
  • Graceful fallback to human manager suggestion

5. Smart Query Filtering

  • Distinguishes business queries from casual chat
  • Polite responses to non-business messages
  • Reduces manager workload (key client requirement!)

πŸ“‹ Tech Stack

Technology Version Purpose
.NET 8.0 Framework
Semantic Kernel 1.70.0 AI Orchestration
OpenAI API GPT-4o-mini LLM Backend
Telegram.Bot 22.8.1 Telegram Integration
Entity Framework Core 8.0.11 ORM
SQLite - Database
Serilog 8.0.0 Logging
xUnit + Moq Latest Testing

πŸ› οΈ Setup Instructions

Prerequisites

  • .NET 8.0 SDK
  • OpenAI API Key
  • Telegram Bot Token (from @BotFather)

Local Development

  1. Clone the repository

    git clone <repository-url>
    cd LogisticsChatbot
  2. Configure API Keys

    Edit src/Presentation/appsettings.Development.json:

    {
      "OpenAI": {
        "ApiKey": "sk-your-openai-api-key-here",
        "ModelId": "gpt-4o-mini"
      },
      "TelegramBot": {
        "BotToken": "your-telegram-bot-token-here"
      }
    }
  3. Restore packages and build

    dotnet restore
    dotnet build
  4. Run the application

    cd src/Presentation
    dotnet run
  5. Run tests

    dotnet test

Docker Deployment

  1. Create environment file

    cp .env.example .env

    Edit .env with your API keys:

    OPENAI_API_KEY=sk-your-key
    TELEGRAM_BOT_TOKEN=your-token
    
  2. Build and run with Docker Compose

    docker-compose up -d --build
  3. View logs

    docker-compose logs -f

πŸ’¬ Bot Commands

Command Description
/start Welcome message with introduction
/new_order Start creating a new delivery order
/calculate Calculate delivery cost
/status <order> Check order status
/myorders View all your orders
/help Show available commands

πŸ“ Example Conversations

Use Case 1: Create Delivery Order

User: I need to ship 15kg of fragile electronics from Moscow to Berlin

Bot: βœ… Order created successfully!

πŸ“¦ Order Number: ORD-20240115-4521
πŸ“ Route: Moscow β†’ Berlin
βš–οΈ Weight: 15 kg
πŸ“‹ Cargo Type: Fragile
πŸ’° Total Cost: $287.50
πŸ“… Estimated Delivery: January 22, 2024

Save your order number to track your shipment!

Use Case 2: Calculate Delivery Cost

User: How much to send 5kg of documents from London to Paris?

Bot: Cost Breakdown:
─────────────────────────────
Base cost: $10.00
Distance (London β†’ Paris): $173.51
Weight (5 kg Γ— $5/kg): $25.00
Cargo type multiplier (Documents): Γ—0.80
Volume multiplier: Γ—1.00
─────────────────────────────
TOTAL: $166.81

Use Case 3: Check Order Status

User: /status ORD-20240115-4521

Bot: πŸ“¦ Order Status: ORD-20240115-4521
─────────────────────────────
Current Status: Package is in transit
Estimated Delivery: January 22, 2024

πŸ“œ Status History:
  β€’ Jan 15, 10:30 - Order created
  β€’ Jan 16, 08:00 - Package picked up
  β€’ Jan 17, 14:25 - In transit

Use Case 4: FAQ Query

User: What items can't I ship internationally?

Bot: β›” Prohibited Items:
β€’ Explosives and flammable materials
β€’ Illegal drugs and narcotics
β€’ Weapons and ammunition
β€’ Live animals
β€’ Perishable food items
β€’ Hazardous chemicals
β€’ Counterfeit goods

Contact our support for specific item inquiries.

Use Case 5: Non-Business Query Filtering

User: Hey, what's the weather like today?

Bot: Hello! I appreciate the friendly chat! 😊
While I can't help with weather forecasts, I'm here to assist
you with all your shipping needs. Would you like to:
β€’ Ship a package?
β€’ Calculate delivery costs?
β€’ Track an existing order?

Just let me know how I can help!

πŸ§ͺ Testing

The project includes comprehensive unit tests for the Application layer:

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run specific test class
dotnet test --filter "FullyQualifiedName~CostCalculatorServiceTests"

Test Coverage

  • CostCalculatorServiceTests - Cost calculation logic
  • OrderServiceTests - Order CRUD operations
  • LogisticsPluginTests - Semantic Kernel plugin functions
  • FaqPluginTests - FAQ knowledge base

πŸ“ Project Structure

LogisticsChatbot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Domain/                    # Core business entities
β”‚   β”‚   β”œβ”€β”€ Entities/
β”‚   β”‚   β”‚   β”œβ”€β”€ Client.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ Order.cs
β”‚   β”‚   β”‚   └── StatusHistory.cs
β”‚   β”‚   β”œβ”€β”€ Enums/
β”‚   β”‚   β”‚   β”œβ”€β”€ CargoType.cs
β”‚   β”‚   β”‚   └── OrderStatus.cs
β”‚   β”‚   β”œβ”€β”€ Interfaces/
β”‚   β”‚   β”‚   β”œβ”€β”€ IClientRepository.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ IOrderRepository.cs
β”‚   β”‚   β”‚   └── IUnitOfWork.cs
β”‚   β”‚   └── ValueObjects/
β”‚   β”‚       β”œβ”€β”€ Address.cs
β”‚   β”‚       └── Dimensions.cs
β”‚   β”‚
β”‚   β”œβ”€β”€ Application/               # Business logic & AI
β”‚   β”‚   β”œβ”€β”€ DTOs/
β”‚   β”‚   β”œβ”€β”€ Interfaces/
β”‚   β”‚   β”œβ”€β”€ Plugins/              # Semantic Kernel plugins
β”‚   β”‚   β”‚   β”œβ”€β”€ LogisticsPlugin.cs
β”‚   β”‚   β”‚   └── FaqPlugin.cs
β”‚   β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”‚   β”œβ”€β”€ AIAgentService.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ CostCalculatorService.cs
β”‚   β”‚   β”‚   └── OrderService.cs
β”‚   β”‚   └── DependencyInjection.cs
β”‚   β”‚
β”‚   β”œβ”€β”€ Infrastructure/            # External concerns
β”‚   β”‚   β”œβ”€β”€ AI/
β”‚   β”‚   β”‚   β”œβ”€β”€ OpenAISettings.cs
β”‚   β”‚   β”‚   └── SemanticKernelConfiguration.cs
β”‚   β”‚   β”œβ”€β”€ Data/
β”‚   β”‚   β”‚   β”œβ”€β”€ Configurations/
β”‚   β”‚   β”‚   β”œβ”€β”€ Repositories/
β”‚   β”‚   β”‚   β”œβ”€β”€ LogisticsDbContext.cs
β”‚   β”‚   β”‚   └── UnitOfWork.cs
β”‚   β”‚   β”œβ”€β”€ Telegram/
β”‚   β”‚   β”‚   β”œβ”€β”€ TelegramBotService.cs
β”‚   β”‚   β”‚   └── TelegramBotSettings.cs
β”‚   β”‚   └── DependencyInjection.cs
β”‚   β”‚
β”‚   └── Presentation/              # Entry point
β”‚       β”œβ”€β”€ Program.cs
β”‚       β”œβ”€β”€ appsettings.json
β”‚       └── appsettings.Development.json
β”‚
β”œβ”€β”€ tests/
β”‚   └── Application.Tests/         # Unit tests
β”‚
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ .env.example
└── README.md

πŸ”§ Configuration

Environment Variables

Variable Description Required
OPENAI_API_KEY OpenAI API key Yes
OPENAI_MODEL_ID Model ID (default: gpt-4o-mini) No
TELEGRAM_BOT_TOKEN Telegram bot token Yes
ConnectionStrings__DefaultConnection SQLite connection string No

Supported OpenAI Models

  • gpt-4o-mini (default, recommended for cost-efficiency)
  • gpt-4o (higher quality, higher cost)
  • gpt-4-turbo
  • gpt-3.5-turbo

πŸ”’ Security Notes

  • Never commit API keys to version control
  • Use environment variables in production
  • The .gitignore excludes sensitive files
  • SQLite database files are excluded from git

πŸ“„ License

This project is created for portfolio demonstration purposes.

🀝 Contributing

This is a portfolio project. Feel free to fork and adapt for your needs.


Built with ❀️ using .NET 8, Semantic Kernel, and Clean Architecture

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages