message eerors
Browse files- App/Messages/MessagesRoute.py +2 -1
- App/Messages/Schema.py +32 -13
App/Messages/MessagesRoute.py
CHANGED
@@ -100,7 +100,8 @@ async def receive_message(message_data: MessageCreate):
|
|
100 |
if isinstance(payment, Payment):
|
101 |
await payment.create_subscription_or_balance()
|
102 |
else:
|
103 |
-
|
|
|
104 |
|
105 |
# Create a new message record with parsed_data
|
106 |
message = await Message.create(
|
|
|
100 |
if isinstance(payment, Payment):
|
101 |
await payment.create_subscription_or_balance()
|
102 |
else:
|
103 |
+
## this is not a paymemt instance it is a json response due to an error
|
104 |
+
return MessageResponse(**message_data.dict())
|
105 |
|
106 |
# Create a new message record with parsed_data
|
107 |
message = await Message.create(
|
App/Messages/Schema.py
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
# App/Messages/Schema.py
|
2 |
-
from pydantic import BaseModel, UUID4, Field, ConfigDict, condecimal, constr
|
3 |
from datetime import datetime
|
4 |
-
from typing import Optional
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
class TransactionSchema(BaseModel):
|
@@ -29,19 +33,34 @@ class MessageCreate(BaseModel):
|
|
29 |
|
30 |
|
31 |
class MessageResponse(BaseModel):
|
32 |
-
id: UUID4
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
model_config = ConfigDict(from_attributes=True)
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# class Config:
|
46 |
# orm_mode = True
|
47 |
# allow_population_by_field_name = True
|
|
|
1 |
# App/Messages/Schema.py
|
2 |
+
from pydantic import BaseModel, UUID4, Field, ConfigDict, condecimal, constr, validator
|
3 |
from datetime import datetime
|
4 |
+
from typing import Optional, Dict
|
5 |
+
import uuid
|
6 |
+
|
7 |
+
from pydantic import BaseModel, UUID4, Field, validator, ConfigDict
|
8 |
+
from uuid import uuid4, UUID
|
9 |
|
10 |
|
11 |
class TransactionSchema(BaseModel):
|
|
|
33 |
|
34 |
|
35 |
class MessageResponse(BaseModel):
|
36 |
+
id: Optional[UUID4] = Field(
|
37 |
+
default_factory=uuid.uuid4
|
38 |
+
) # Automatically generate UUID4 if not provided
|
39 |
+
device_id: Optional[str] = None
|
40 |
+
event: Optional[str] = None
|
41 |
+
message_id: Optional[str] = None
|
42 |
+
webhook_id: Optional[str] = None
|
43 |
+
message_content: Optional[str] = None
|
44 |
+
phone_number: Optional[str] = None
|
45 |
+
received_at: Optional[datetime] = None
|
46 |
+
sim_number: Optional[int] = None
|
47 |
+
parsed_data: Optional[Dict] = None # Include parsed_data in the response
|
48 |
+
created_time: Optional[datetime] = None
|
49 |
model_config = ConfigDict(from_attributes=True)
|
50 |
|
51 |
+
@validator("id", pre=True, always=True)
|
52 |
+
def validate_uuid(cls, v):
|
53 |
+
"""
|
54 |
+
Ensure all ID fields are valid UUIDs. If the input is invalid or missing,
|
55 |
+
generate a new UUID.
|
56 |
+
"""
|
57 |
+
if v is None or not isinstance(v, (UUID, str)):
|
58 |
+
return uuid4() # Generate a new UUID if not provided or invalid
|
59 |
+
try:
|
60 |
+
return UUID(v) # Validate and convert to UUID
|
61 |
+
except ValueError:
|
62 |
+
return uuid4() # Generate a new UUID if validation fails
|
63 |
+
|
64 |
# class Config:
|
65 |
# orm_mode = True
|
66 |
# allow_population_by_field_name = True
|