RewardFlow is an intelligent travel rewards assistant that helps users find the best way to redeem their miles and points. It combines structured database queries (for award charts) with RAG (Retrieval-Augmented Generation) for general knowledge, all accessible via a Telegram bot.
The system consists of two main services:
-
Go Gateway (
go-gateway):- Role: The central brain and API server.
- Responsibilities:
- Handles Telegram webhooks.
- Intention Router: Uses OpenAI to classify user intent (e.g., "Award Search" vs "Knowledge Query") and extract slots (Origin, Destination, Cabin).
- Context Management: Maintains user session state to handle follow-up questions (e.g., "what about business class?").
- Database: Queries PostgreSQL for award availability.
- Tech Stack: Go (Gin), PostgreSQL.
-
Python RAG (
python-rag):- Role: The knowledge engine.
- Responsibilities:
- Ingests markdown files into a vector database (Pinecone).
- Answers natural language questions using RAG.
- Strict Mode: Only answers based on internal knowledge; refuses to hallucinate or use general web info.
- Tech Stack: Python (FastAPI), OpenAI, Pinecone.
- Docker & Docker Compose
makengrok(for exposing local server to Telegram)- OpenAI API Key
- Telegram Bot Token
Create a .env file or export these variables:
export OPENAI_API_KEY="sk-..."
export TELEGRAM_BOT_TOKEN="123456:ABC-..."
# Optional: Pinecone keys if using RAG
# export PINECONE_API_KEY="..."
# export PINECONE_INDEX="..."make startThis will build and start:
go-gateway(port 8080)python-rag(port 8000)postgres(port 5433)redis(port 6379)
Populate the database with award charts and ingest the knowledge base:
make setup-allExpose your local server:
ngrok http 8080Register the webhook with Telegram:
curl -F "url=https://<YOUR-NGROK-URL>/telegram/webhook" https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhookThe bot remembers your conversation. You don't need to repeat yourself.
- User: "miles from singapore to malaysia"
- Bot: Shows Economy awards for SIN-KUL
- User: "what about business class?"
- Bot: Shows Business awards for SIN-KUL (remembers the route)
- User: "what about air canada?"
- Bot: Checks Air Canada availability for the same route
Search by country names, not just airport codes.
- User: "miles to Thailand"
- Bot: Searches flights to BKK, HKT, CNX, etc.
- User: "from Japan to UK"
- Bot: Searches HND/NRT to LHR/LGW
If you omit the origin, it assumes Singapore (SIN).
- User: "miles to bangkok"
- Bot: Searches SIN -> BKK
The bot is configured to never hallucinate.
- User: "how to transfer MR to krisflyer" -> Answers from your KB
- User: "who won the world cup?" -> "I don't have this information in my knowledge base."
- Edit
data/award_charts.csv. - Run:
make reload-data
- Add markdown files to
kb/. - Run:
(Or
make reload-data
make force-ingest-kbto force a full re-scan).
go-gateway/: Main application logic.internal/router/: LLM routing and slot extraction.internal/handlers/: Telegram and API handlers.internal/store/: Database queries.
python-rag/: RAG service.app/services/: Embedding and retrieval logic.
data/: CSV files for database seeding.kb/: Markdown files for knowledge base.