mirror of
https://github.com/marcogll/telegram_expenses_controller.git
synced 2026-01-13 13:25:15 +00:00
feat: Implement core application structure, AI extraction, persistence, and Telegram bot modules with updated configuration and dependencies.
This commit is contained in:
0
app/modules/__init__.py
Normal file
0
app/modules/__init__.py
Normal file
10
app/modules/admin.py
Normal file
10
app/modules/admin.py
Normal file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
Handlers for admin-only commands.
|
||||
"""
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
async def admin_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Handles an admin-specific command (stub)."""
|
||||
# You would add a permission check here
|
||||
await update.message.reply_text("Admin command is not yet implemented.")
|
||||
9
app/modules/search.py
Normal file
9
app/modules/search.py
Normal file
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
Handler for the /search command.
|
||||
"""
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
async def search(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Searches the expense database (stub)."""
|
||||
await update.message.reply_text("Search command is not yet implemented.")
|
||||
14
app/modules/start.py
Normal file
14
app/modules/start.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Handler for the /start command.
|
||||
"""
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Sends a welcome message when the /start command is issued."""
|
||||
user = update.effective_user
|
||||
await update.message.reply_html(
|
||||
rf"Hi {user.mention_html()}! Welcome to the Expense Bot. "
|
||||
"Send me a message with an expense (e.g., 'lunch 25 eur') "
|
||||
"or forward a voice message or receipt image.",
|
||||
)
|
||||
9
app/modules/status.py
Normal file
9
app/modules/status.py
Normal file
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
Handler for the /status command.
|
||||
"""
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Shows the status of the last processed expense (stub)."""
|
||||
await update.message.reply_text("Status command is not yet implemented.")
|
||||
48
app/modules/upload.py
Normal file
48
app/modules/upload.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Handler for receiving and processing user messages (text, audio, images).
|
||||
"""
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
import logging
|
||||
|
||||
from app.schema.base import RawInput
|
||||
# This is a simplified integration. In a real app, you would likely
|
||||
# have a queue or a more robust way to trigger the processing pipeline.
|
||||
from app.router import process_expense_input
|
||||
from app.persistence.db import get_db
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""
|
||||
Handles regular messages and triggers the expense processing pipeline.
|
||||
"""
|
||||
user_id = str(update.effective_user.id)
|
||||
|
||||
# This is a very simplified example.
|
||||
# A real implementation needs to handle files, voice, etc.
|
||||
if update.message.text:
|
||||
raw_input = RawInput(
|
||||
user_id=user_id,
|
||||
type="text",
|
||||
data=update.message.text
|
||||
)
|
||||
|
||||
try:
|
||||
# Get a DB session
|
||||
db_session = next(get_db())
|
||||
|
||||
# Run the processing pipeline
|
||||
result = process_expense_input(db=db_session, raw_input=raw_input)
|
||||
|
||||
if result:
|
||||
await update.message.reply_text(f"Expense saved successfully! ID: {result.id}")
|
||||
else:
|
||||
await update.message.reply_text("I couldn't fully process that. It might need manual review.")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling message: {e}", exc_info=True)
|
||||
await update.message.reply_text("Sorry, an error occurred while processing your request.")
|
||||
|
||||
else:
|
||||
await update.message.reply_text("I can currently only process text messages.")
|
||||
Reference in New Issue
Block a user