From 8d343774198152a97503f5f401ba167ca4f03cd0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 7 Feb 2017 14:51:46 +0100 Subject: [PATCH 1/2] Added python3 support Without this, it crashes with a `UnicodeDecodeError` --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 0460f3c..3fb0f6b 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -498,7 +498,7 @@ class Client(object): :param image: path to a local image to send """ mimetype = guess_type(image)[0] - image_id = self.uploadImage({'file': (image, open(image), mimetype)}) + image_id = self.uploadImage({'file': (image, open(image, 'rb'), mimetype)}) return self.send(recipient_id, message, message_type, None, image_id) def uploadImage(self, image): From fdb72e1f66039a0ac61e39f415cf3586326d362f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 7 Feb 2017 20:36:43 +0100 Subject: [PATCH 2/2] Changed name of the new on_message, to be properly backwards compatible Apparently, python doesn't work the way i expected, when it comes to overriding functions --- fbchat/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 3fb0f6b..c82561a 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -760,7 +760,7 @@ class Client(object): mid = m['delta']['messageMetadata']['messageId'] message = m['delta'].get('body','') fbid = m['delta']['messageMetadata']['actorFbId'] - self.on_message(mid, fbid, message, m, recipient_id, thread_type) + self.on_message_new(mid, fbid, message, m, recipient_id, thread_type) elif m['type'] in ['jewel_requests_add']: from_id = m['from'] self.on_friend_request(from_id) @@ -878,7 +878,7 @@ class Client(object): return r.ok - def on_message(self, mid, author_id, message, metadata, recipient_id, thread_type): + def on_message_new(self, mid, author_id, message, metadata, recipient_id, thread_type): ''' subclass Client and override this method to add custom behavior on event