A Telegram bot that walks a user through buying a car insurance policy. It reads the user's documents from photos with Mindee (OCR / document AI), talks to the user through an LLM (Groq, model openai/gpt-oss-20b by default) and issues a policy at a fixed price.
The conversation is a simple state machine (Models/BotState.cs), kept in memory per chat:
/start— the bot introduces itself and asks for a photo of the passport.- The photo is sent to Mindee; the extracted data is shown to the user for confirmation (
Yes/No). - The bot asks for a photo of the vehicle registration document and confirms the extracted data the same way.
- The bot quotes the fixed price — 100 USD — and asks the user to accept it.
- After acceptance the LLM generates the final insurance policy message.
If the user answers No, the bot asks for a better photo (or explains that the price is fixed). Every bot reply is generated by the LLM from a short prompt, so the wording is natural and varies.
- .NET 8 (ASP.NET Core host with a
BackgroundServicefor long polling) - Telegram.Bot
- Mindee .NET SDK — passport and vehicle document extraction
- Groq API (OpenAI-compatible
chat/completions) viaHttpClient - Dependency injection with interfaces for every service (
IMindeeService,IGroqService,ISessionService) - Docker (multi-stage build)
Models/
BotState.cs – steps of the conversation
UserSession.cs – per-chat state and extracted data
Services/
TelegramBotHostedService.cs – receives updates and drives the state machine
MindeeService.cs – document recognition
GroqService.cs – LLM replies and the final policy text
InMemorySessionService.cs – session storage
Program.cs – configuration check and DI registration
The bot needs three keys. Never commit real keys — appsettings.json contains only placeholders. Pass them as environment variables (the __ separator maps to BotConfiguration:...):
| Variable | Where to get it |
|---|---|
BotConfiguration__BotToken |
@BotFather in Telegram |
BotConfiguration__MindeeApiKey |
platform.mindee.com |
BotConfiguration__GroqApiKey |
console.groq.com |
Optionally, BotConfiguration__GroqModel selects another Groq model. The Mindee model IDs for the passport and vehicle documents are set in Services/MindeeService.cs.
Locally (.NET 8 SDK):
export BotConfiguration__BotToken="..."
export BotConfiguration__MindeeApiKey="..."
export BotConfiguration__GroqApiKey="..."
dotnet runWith Docker:
docker build -t car-insurance-bot .
docker run --rm \
-e BotConfiguration__BotToken="..." \
-e BotConfiguration__MindeeApiKey="..." \
-e BotConfiguration__GroqApiKey="..." \
car-insurance-bot- Sessions are stored in memory, so they are lost when the bot restarts.
- The price is fixed and no real payment is processed — this is a demo / test-task project.