From 42c1d26b2e986c8e6498c7d083c4267cd1b25a33 Mon Sep 17 00:00:00 2001 From: Manvydas Kriauciunas Date: Fri, 6 Oct 2017 16:31:25 +0200 Subject: [PATCH] new feature to support @mention in sendMessage --- fbchat/client.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 8f341a86..0e067e46 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -896,7 +896,8 @@ def _doSendRequest(self, data): return message_id - def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER): + def sendMessage(self, message, mention=None, thread_id=None, + thread_type=ThreadType.USER): """ Sends a message to a thread @@ -904,6 +905,9 @@ def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER): :param thread_id: User/Group ID to send to. See :ref:`intro_threads` :param thread_type: See :ref:`intro_threads` :type thread_type: models.ThreadType + :mention is in this format {userID : (start, end)}, + where start is relative start position of @mention in a message + and end is relative end position of @mention :return: :ref:`Message ID ` of the sent message :raises: FBchatException if request failed """ @@ -912,6 +916,14 @@ def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER): data['action_type'] = 'ma-type:user-generated-message' data['body'] = message or '' + if mention: + n = 0 + for key, value in mention.items(): + data['profile_xmd[%d][id]'%n] = key + data['profile_xmd[%d][offset]'%n] = value[0] + data['profile_xmd[%d][length]'%n] = value[1] - value[0] + data['profile_xmd[%d][type]'%n] = 'p' + n += 1 data['has_attachment'] = False data['specific_to_list[0]'] = 'fbid:' + thread_id data['specific_to_list[1]'] = 'fbid:' + self.uid