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