import io
import typing
from divera.api.v2 import message as _message
from divera.models import Message as _Message
from . import PullModel as _PullModel
[docs]class Message(
_Message,
):
path: typing.List = [
'data',
'message',
'items',
]
path_to_sorting: typing.List = None
[docs] @staticmethod
def get_all(
):
return _PullModel.get_all(
model=Message,
)
[docs] def get(
self,
obj=None,
object_id=None,
):
request = _message.Get(
obj=obj or (Message(id=int(object_id)) if object_id is not None else None) or self,
)
request.process_result = lambda result: Message(data=result['data'])
return request
[docs] def create(
self,
obj=None,
):
"""
The message needs to have the message_channel_id and text argument filled. parent_id is optional.
"""
request = _message.Create(
obj=obj or self,
)
def process_result(
result,
):
self.data = {
**result['data'],
**{
'attachments': self.data['attachments'], # do not overwrite attachments
}
}
return self
request.process_result = process_result
yield request
for attachment in self.attachments or []:
if issubclass(type(attachment), io.IOBase):
yield self.add_attachment(
attachment,
)
# return the most up-to-date version of this object last
yield self.get()
[docs] def delete(
self,
obj=None,
):
"""
The message needs to have the message_channel_id and text argument filled. parent_id is optional.
"""
request = _message.Delete(
obj=obj or self,
)
return request