Skip to content

Commit

Permalink
Merge remote-tracking branch 'svaikstude/feature/@mention'
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Oct 21, 2017
2 parents 28d5ac9 + 42c1d26 commit dda75c6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion fbchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,18 @@ 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
:param message: Message to send
: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 <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
"""
Expand All @@ -944,6 +948,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
Expand Down

0 comments on commit dda75c6

Please sign in to comment.