File size: 960 Bytes
01a1238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# App/Messages/Model.py
from tortoise import fields, models
from uuid import uuid4
from datetime import datetime
from tortoise.models import Model


class Message(Model):
    id = fields.UUIDField(pk=True, default=uuid4)
    device_id = fields.CharField(max_length=100, null=True)
    event = fields.CharField(max_length=100, null=True)
    message_id = fields.CharField(
        max_length=100, null=True
    )  # Corresponds to 'id' in the JSON
    webhook_id = fields.CharField(max_length=100, null=True)
    message_content = fields.TextField()
    phone_number = fields.CharField(max_length=20)
    received_at = fields.DatetimeField()
    sim_number = fields.IntField(null=True)
    parsed_data = fields.JSONField(null=True)  # New field for parsed data
    created_time = fields.DatetimeField(auto_now_add=True)

    class Meta:
        table = "messages"

    def __str__(self):
        return f"Message from {self.phone_number} at {self.received_at}"