23 lines
696 B
Python
23 lines
696 B
Python
from datetime import datetime
|
|
|
|
class Message:
|
|
"""Chat message in a conversation"""
|
|
|
|
TABLE_NAME = "messages"
|
|
|
|
def __init__(self, id, conversation_id, sender_id, content, created_at=None):
|
|
self.id = id
|
|
self.conversation_id = conversation_id
|
|
self.sender_id = sender_id
|
|
self.content = content
|
|
self.created_at = created_at or datetime.utcnow()
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": self.id,
|
|
"conversation_id": self.conversation_id,
|
|
"sender_id": self.sender_id,
|
|
"content": self.content,
|
|
"created_at": self.created_at.isoformat() if self.created_at else None,
|
|
}
|