chat model

 from django.db import models

from brand.models import Brand
from whatsapp.models import Contact

class Chat(models.Model):
MESSAGE_TYPES = [
('text', 'Text'),
('image', 'Image'),
('video', 'Video'),
('document', 'Document'),
('button', 'Button'),
('interactive', 'Interactive'),
]

brand = models.ForeignKey(Brand, on_delete=models.CASCADE, related_name='chats')
contact = models.ForeignKey(Contact, on_delete=models.CASCADE, related_name='chats')
message_id = models.CharField(max_length=256, unique=True, db_index=True) # WhatsApp message ID
timestamp = models.DateTimeField() # Message timestamp
message_type = models.CharField(max_length=20, choices=MESSAGE_TYPES) # Message type
content = models.TextField(null=True, blank=True) # For text messages
file_id = models.CharField(max_length=256, null=True, blank=True) # ID of media file (image, video, document)
mime_type = models.CharField(max_length=100, null=True, blank=True) # MIME type of media file
filename = models.CharField(max_length=256, null=True, blank=True) # For document file name
sha256 = models.CharField(max_length=256, null=True, blank=True) # SHA-256 hash of media file

is_outgoing = models.BooleanField(default=False) # Flag to distinguish between incoming and outgoing messages
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"Message {self.message_id} ({'Outgoing' if self.is_outgoing else 'Incoming'})"


Comments

Popular posts from this blog

Django

JS