Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions botogram/objects/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ def send_contact(self, phone, first_name, last_name=None, *, reply_to=None,

return self._api.call("sendContact", args, expect=_objects().Message)

@_require_api
def delete_message(self, message):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add the docstring.

"""Delete a message from chat"""
if hasattr(message, "message_id"):
message = message.message_id

return self._api.call("deleteMessage", {
"chat_id": self.id,
"message_id": message,
})


class MessageMixin:
"""Add some methods for messages"""
Expand Down Expand Up @@ -284,6 +295,14 @@ def reply_with_contact(self, *args, **kwargs):
"""Reply with a contact to the current message"""
return self.chat.send_contact(*args, reply_to=self, **kwargs)

@_require_api
def delete(self):
"""Delete the message"""
return self._api.call("deleteMessage", {
"chat_id": self.chat.id,
"message_id": self.message_id,
})


class FileMixin:
"""Add some methods for files"""
Expand Down
18 changes: 18 additions & 0 deletions docs/api/telegram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ about its business.

.. versionadded:: 0.3

.. py:method:: delete_message(message)

Delete the message with the provided ID or :py:class:`~botogram.Message` object.
A message can be deleted only if is sent by the bot or sent in a supergroup by an user where the bot is admin.
It can also be deleted if it's one of the supported service messages.

:param message: The message to delete (can be an ID too)

.. versionadded:: 0.4

.. py:class:: botogram.Chat

This class represents a Telegram chat.
Expand Down Expand Up @@ -1274,6 +1284,14 @@ about its business.

.. versionadded:: 0.3

.. py:method:: delete()

Delete this message.
A message can be deleted only if is sent by the bot or sent in a supergroup by an user where the bot is admin.
It can also be deleted if it's one of the supported service messages.

.. versionadded:: 0.4

.. py:method:: edit_caption(caption, [extra=None])

With this method you can edit the caption of the media attached to a
Expand Down