diff --git a/fbchat/_client.py b/fbchat/_client.py index eaac9ed..309aad2 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -703,36 +703,6 @@ class Client: SEND METHODS """ - def unsend(self, mid): - """Unsend message by it's ID (removes it for everyone). - - Args: - mid: :ref:`Message ID ` of the message to unsend - """ - data = {"message_id": mid} - j = self._payload_post("/messaging/unsend_message/?dpr=1", data) - - def react_to_message(self, message_id, reaction): - """React to a message, or removes reaction. - - Args: - message_id: :ref:`Message ID ` to react to - reaction (MessageReaction): Reaction emoji to use, if None removes reaction - - Raises: - FBchatException: If request failed - """ - data = { - "action": "ADD_REACTION" if reaction else "REMOVE_REACTION", - "client_mutation_id": "1", - "actor_id": self._session.user_id, - "message_id": str(message_id), - "reaction": reaction.value if reaction else None, - } - data = {"doc_id": 1491398900900362, "variables": json.dumps({"data": data})} - j = self._payload_post("/webgraphql/mutation", data) - _util.handle_graphql_errors(j) - def edit_plan(self, plan, new_plan): """Edit a plan. diff --git a/fbchat/_message.py b/fbchat/_message.py index 7936043..926a4a4 100644 --- a/fbchat/_message.py +++ b/fbchat/_message.py @@ -3,6 +3,7 @@ import json from string import Formatter from ._core import log, attrs_default, Enum from . import _util, _session, _attachment, _location, _file, _quick_reply, _sticker +from typing import Optional class EmojiSize(Enum): @@ -82,7 +83,7 @@ class Message: #: The session to use when making requests. session = attr.ib(None, type=_session.Session) #: The message ID - id = attr.ib(None) + id = attr.ib(None, converter=str) #: The actual message text = attr.ib(None) @@ -115,6 +116,28 @@ class Message: #: Whether the message was forwarded forwarded = attr.ib(False) + def unsend(self): + """Unsend the message (removes it for everyone).""" + data = {"message_id": self.id} + j = self.session._payload_post("/messaging/unsend_message/?dpr=1", data) + + def react(self, reaction: Optional[MessageReaction]): + """React to the message, or removes reaction. + + Args: + reaction: Reaction emoji to use, if None removes reaction + """ + data = { + "action": "ADD_REACTION" if reaction else "REMOVE_REACTION", + "client_mutation_id": "1", + "actor_id": self.session.user_id, + "message_id": self.id, + "reaction": reaction.value if reaction else None, + } + data = {"doc_id": 1491398900900362, "variables": json.dumps({"data": data})} + j = self.session._payload_post("/webgraphql/mutation", data) + _util.handle_graphql_errors(j) + @classmethod def from_fetch(cls, thread, message_id: str) -> "Message": """Fetch `Message` object from the given message id.