Bases: Model
Represent a Telegram Message.
The raw message from the Telegram API is stored as json.
Reference:
https://core.telegram.org/bots/api#message
Source code in django_telegram_app/models.py
| class Message(models.Model):
"""Represent a Telegram Message.
The raw message from the Telegram API is stored as json.
Reference:
https://core.telegram.org/bots/api#message
"""
raw_message = models.JSONField(verbose_name=_("raw message"))
error = models.TextField(verbose_name=_("error"), null=True, blank=True)
@property
def message_truncated(self):
"""Return the message truncated to 100 characters."""
message_str = str(self.raw_message)
if len(message_str) > 100:
return message_str[:97] + "..."
return message_str
@property
def update_id(self) -> int:
"""Return the chat id from the raw message."""
return self.raw_message.get("update_id", "unknown")
def __str__(self):
"""Return the string representation of the message."""
if self.error:
return f"{self.update_id} - {self.error}"
return str(self.update_id)
class Meta:
"""Set meta options."""
verbose_name = _("message")
verbose_name_plural = _("messages")
|
message_truncated
property
Return the message truncated to 100 characters.
update_id
property
Return the chat id from the raw message.
Set meta options.
Source code in django_telegram_app/models.py
| class Meta:
"""Set meta options."""
verbose_name = _("message")
verbose_name_plural = _("messages")
|
__str__()
Return the string representation of the message.
Source code in django_telegram_app/models.py
| def __str__(self):
"""Return the string representation of the message."""
if self.error:
return f"{self.update_id} - {self.error}"
return str(self.update_id)
|