feat(bot,wizard): smart message filtering, encrypted standalone wizard, and file persistence
This commit is contained in:
@@ -198,9 +198,17 @@ async def render(ctx, chat_id, draft, fresh: bool = True, note: str | None = Non
|
||||
reply_to: int | None = None) -> None:
|
||||
from app.config import settings
|
||||
|
||||
from app.security import create_draft_token
|
||||
|
||||
payload = draft.payload
|
||||
missing = compute_quote_missing(payload)
|
||||
wizard_url = f"{settings.FRONTEND_URL}/wizard?draft={draft.id}"
|
||||
token = create_draft_token(
|
||||
draft.id,
|
||||
chat_id=chat_id,
|
||||
secret=settings.DRAFT_TOKEN_SECRET,
|
||||
expires_in=settings.DRAFT_TOKEN_EXPIRE_SECONDS,
|
||||
)
|
||||
wizard_url = f"{settings.FRONTEND_URL.rstrip('/')}/review?token={token}"
|
||||
text = quote_review_text(payload, missing, status_note=note)
|
||||
text += f"\n\n🖥 مشاهده و تکمیل در ویزارد:\n{wizard_url}"
|
||||
keyboard = _keyboard(payload, str(draft.id), wizard_url=wizard_url)
|
||||
@@ -302,9 +310,29 @@ async def commit(ctx, chat_id, user, draft, only_resolved: bool = False) -> None
|
||||
ctx.pending.pop(chat_id, None)
|
||||
ctx.resolver.invalidate()
|
||||
|
||||
quote_id = (created or {}).get("id") or ""
|
||||
# If a proforma file was attached, persist it to the created ERP quote
|
||||
proforma_info = payload.get("proforma")
|
||||
if quote_id and proforma_info and proforma_info.get("saved_path"):
|
||||
try:
|
||||
from pathlib import Path
|
||||
p_path = Path(proforma_info["saved_path"])
|
||||
if p_path.exists():
|
||||
file_bytes = p_path.read_bytes()
|
||||
await ctx.api.upload_quote_file(
|
||||
quote_id,
|
||||
"proforma",
|
||||
proforma_info.get("file_name") or "proforma.pdf",
|
||||
file_bytes,
|
||||
mime_type=proforma_info.get("mime_type") or "application/pdf",
|
||||
actor_id=user.actor_id,
|
||||
)
|
||||
logger.info("Successfully uploaded proforma to quote %s", quote_id)
|
||||
except Exception as e:
|
||||
logger.warning("Could not upload draft proforma to quote %s: %s", quote_id, e)
|
||||
|
||||
if draft.review_message_id:
|
||||
try:
|
||||
quote_id = (created or {}).get("id") or ""
|
||||
msg = f"✅ این پیشنهاد در سیستم با موفقیت ثبت نهایی شد.\nشناسه پیشنهاد: {quote_id}"
|
||||
await ctx.edit(chat_id, draft.review_message_id, msg, reply_markup=None)
|
||||
await draft_store.set_bale_updated_at(draft.id)
|
||||
|
||||
Reference in New Issue
Block a user