Update app.py
Browse files
app.py
CHANGED
|
@@ -258,13 +258,14 @@ def process_order_flow(user_id: str, message: str) -> str:
|
|
| 258 |
return ""
|
| 259 |
|
| 260 |
# --- User Profile Functions ---
|
|
|
|
| 261 |
async def get_or_create_user_profile(user_id: str, phone_number: str = None) -> UserProfile:
|
| 262 |
"""Retrieve an existing profile or create a new one with user_id and phone_number."""
|
| 263 |
async with async_session() as session:
|
| 264 |
result = await session.execute(
|
| 265 |
-
|
| 266 |
)
|
| 267 |
-
profile = result.
|
| 268 |
if profile is None:
|
| 269 |
profile = UserProfile(
|
| 270 |
user_id=user_id,
|
|
@@ -279,9 +280,9 @@ async def update_user_last_interaction(user_id: str):
|
|
| 279 |
"""Update the user's last interaction timestamp."""
|
| 280 |
async with async_session() as session:
|
| 281 |
result = await session.execute(
|
| 282 |
-
|
| 283 |
)
|
| 284 |
-
profile = result.
|
| 285 |
if profile:
|
| 286 |
profile.last_interaction = datetime.utcnow()
|
| 287 |
await session.commit()
|
|
|
|
| 258 |
return ""
|
| 259 |
|
| 260 |
# --- User Profile Functions ---
|
| 261 |
+
|
| 262 |
async def get_or_create_user_profile(user_id: str, phone_number: str = None) -> UserProfile:
|
| 263 |
"""Retrieve an existing profile or create a new one with user_id and phone_number."""
|
| 264 |
async with async_session() as session:
|
| 265 |
result = await session.execute(
|
| 266 |
+
select(UserProfile).where(UserProfile.user_id == user_id)
|
| 267 |
)
|
| 268 |
+
profile = result.scalars().first()
|
| 269 |
if profile is None:
|
| 270 |
profile = UserProfile(
|
| 271 |
user_id=user_id,
|
|
|
|
| 280 |
"""Update the user's last interaction timestamp."""
|
| 281 |
async with async_session() as session:
|
| 282 |
result = await session.execute(
|
| 283 |
+
select(UserProfile).where(UserProfile.user_id == user_id)
|
| 284 |
)
|
| 285 |
+
profile = result.scalars().first()
|
| 286 |
if profile:
|
| 287 |
profile.last_interaction = datetime.utcnow()
|
| 288 |
await session.commit()
|