Skip to content

Commit

Permalink
See commit description
Browse files Browse the repository at this point in the history
- Deprecated `sendMessage` and `sendEmoji` in favor of `send`
- (Almost) Fully integrated attachment support
- Updated tests
- General cleanup
  • Loading branch information
madsmtm committed Oct 21, 2017
1 parent dda75c6 commit 7ecf229
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 277 deletions.
12 changes: 6 additions & 6 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ The same method can be applied to some user accounts, though if they've set a cu
Here's an snippet showing the usage of thread IDs and thread types, where ``<user id>`` and ``<group id>``
corresponds to the ID of a single user, and the ID of a group respectively::

client.sendMessage('<message>', thread_id='<user id>', thread_type=ThreadType.USER)
client.sendMessage('<message>', thread_id='<group id>', thread_type=ThreadType.GROUP)
client.send(Message(text='<message>'), thread_id='<user id>', thread_type=ThreadType.USER)
client.send(Message(text='<message>'), thread_id='<group id>', thread_type=ThreadType.GROUP)

Some functions (e.g. :func:`Client.changeThreadColor`) don't require a thread type, so in these cases you just provide the thread ID::

Expand All @@ -91,7 +91,7 @@ Some of `fbchat`'s functions require these ID's, like :func:`Client.reactToMessa
and some of then provide this ID, like :func:`Client.sendMessage`.
This snippet shows how to send a message, and then use the returned ID to react to that message with a 😍 emoji::

message_id = client.sendMessage('message', thread_id=thread_id, thread_type=thread_type)
message_id = client.send(Message(text='message'), thread_id=thread_id, thread_type=thread_type)
client.reactToMessage(message_id, MessageReaction.LOVE)


Expand All @@ -108,7 +108,7 @@ like adding users to and removing users from a group chat, logically only works
The simplest way of using `fbchat` is to send a message.
The following snippet will, as you've probably already figured out, send the message `test message` to your account::

message_id = client.sendMessage('test message', thread_id=client.uid, thread_type=ThreadType.USER)
message_id = client.send(Message(text='test message'), thread_id=client.uid, thread_type=ThreadType.USER)

You can see a full example showing all the possible thread interactions with `fbchat` by going to :ref:`examples`

Expand Down Expand Up @@ -176,7 +176,7 @@ The event actions can be changed by subclassing the :class:`Client`, and then ov

class CustomClient(Client):
def onMessage(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs):
# Do something with the message_object here
# Do something with message_object here
pass

client = CustomClient('<email>', '<password>')
Expand All @@ -185,7 +185,7 @@ The event actions can be changed by subclassing the :class:`Client`, and then ov

class CustomClient(Client):
def onMessage(self, message_object, author_id, thread_id, thread_type, **kwargs):
# Do something with the message here
# Do something with message_object here
pass

client = CustomClient('<email>', '<password>')
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

print('Own id: {}'.format(client.uid))

client.sendMessage('Hi me!', thread_id=client.uid, thread_type=ThreadType.USER)
client.send(Message(text='Hi me!'), thread_id=client.uid, thread_type=ThreadType.USER)

client.logout()
6 changes: 3 additions & 3 deletions examples/echobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs)

log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))

# If you're not the author, and the message was a message containing text, echo
if author_id != self.uid and message_object.text is not None:
self.sendMessage(message_object.text, thread_id=thread_id, thread_type=thread_type)
# If you're not the author, echo
if author_id != self.uid:
self.send(message_object, thread_id=thread_id, thread_type=thread_type)

client = EchoBot("<email>", "<password>")
client.listen()
16 changes: 11 additions & 5 deletions examples/interract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@
thread_type = ThreadType.GROUP

# Will send a message to the thread
client.sendMessage('<message>', thread_id=thread_id, thread_type=thread_type)
client.send(Message(text='<message>'), thread_id=thread_id, thread_type=thread_type)

# Will send the default `like` emoji
client.sendEmoji(emoji=None, size=EmojiSize.LARGE, thread_id=thread_id, thread_type=thread_type)
client.send(Message(emoji_size=EmojiSize.LARGE), thread_id=thread_id, thread_type=thread_type)

# Will send the emoji `👍`
client.sendEmoji(emoji='👍', size=EmojiSize.LARGE, thread_id=thread_id, thread_type=thread_type)
client.send(Message(text='👍', emoji_size=EmojiSize.LARGE), thread_id=thread_id, thread_type=thread_type)

# Will send the sticker with ID `767334476626295`
client.send(Message(sticker=Sticker('767334476626295')), thread_id=thread_id, thread_type=thread_type)

# Will send a message with a mention
client.send(Message(text='This is a @mention', mentions=[Mention(thread_id, offset=10, length=8)]), thread_id=thread_id, thread_type=thread_type)

# Will send the image located at `<image path>`
client.sendLocalImage('<image path>', message='This is a local image', thread_id=thread_id, thread_type=thread_type)
client.sendLocalImage('<image path>', message=Message(text='This is a local image'), thread_id=thread_id, thread_type=thread_type)

# Will download the image at the url `<image url>`, and then send it
client.sendRemoteImage('<image url>', message='This is a remote image', thread_id=thread_id, thread_type=thread_type)
client.sendRemoteImage('<image url>', message=Message(text='This is a remote image'), thread_id=thread_id, thread_type=thread_type)


# Only do these actions if the thread is a group
Expand Down
2 changes: 1 addition & 1 deletion fbchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
__version__ = '1.0.25'
__version__ = '1.1.0'
__license__ = 'BSD'
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
__email__ = '[email protected]'
Expand Down
Loading

0 comments on commit 7ecf229

Please sign in to comment.