A sophisticated AI-powered logistics chatbot built with .NET 8 and Clean Architecture, demonstrating enterprise-grade AI agent capabilities for delivery and shipping management.
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) β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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.
- 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
- 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
- Query orders by order number
- Full status history with timestamps
- Estimated delivery date
- Semantic Kernel powered Q&A
- Topics: shipping times, international delivery, packaging, prohibited items, insurance, etc.
- Graceful fallback to human manager suggestion
- Distinguishes business queries from casual chat
- Polite responses to non-business messages
- Reduces manager workload (key client requirement!)
| 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 |
- .NET 8.0 SDK
- OpenAI API Key
- Telegram Bot Token (from @BotFather)
-
Clone the repository
git clone <repository-url> cd LogisticsChatbot
-
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" } } -
Restore packages and build
dotnet restore dotnet build
-
Run the application
cd src/Presentation dotnet run -
Run tests
dotnet test
-
Create environment file
cp .env.example .env
Edit
.envwith your API keys:OPENAI_API_KEY=sk-your-key TELEGRAM_BOT_TOKEN=your-token -
Build and run with Docker Compose
docker-compose up -d --build
-
View logs
docker-compose logs -f
| 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 |
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!
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
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
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.
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!
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"CostCalculatorServiceTests- Cost calculation logicOrderServiceTests- Order CRUD operationsLogisticsPluginTests- Semantic Kernel plugin functionsFaqPluginTests- FAQ knowledge base
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
| 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 |
gpt-4o-mini(default, recommended for cost-efficiency)gpt-4o(higher quality, higher cost)gpt-4-turbogpt-3.5-turbo
- Never commit API keys to version control
- Use environment variables in production
- The
.gitignoreexcludes sensitive files - SQLite database files are excluded from git
This project is created for portfolio demonstration purposes.
This is a portfolio project. Feel free to fork and adapt for your needs.
Built with β€οΈ using .NET 8, Semantic Kernel, and Clean Architecture