Cretezy / pymessenger2

A Python Wrapper for the FB Messenger Bot API (Send/Receive API)
MIT License
25 stars 14 forks source link

error pymessenger2/pymessenger2/bot.py #11

Closed jdrh0503 closed 7 years ago

jdrh0503 commented 7 years ago

Hi, I have tried to send images from a local directory and it looks like an error in the function

def send_attachment(self, recipient_id, attachment_type, attachment_path, notification_type=NotificationType.regular):

The error that appears is:

send_attachment 'payload': {} TypeError: unhashable type: 'dict'

I think the problem is in the double keys in which they are found in 'recipient' and 'message'

'recipient': {{ 'id': recipient_id }}, 'notification_type': notification_type, 'message': {{ 'attachment': { 'type': attachment_type, 'payload': {} } }},

Maybe with what I've seen can be corrected. Thank you.

MarekStojecki commented 7 years ago

Hi, I solved this problem with small workaround ;) payload = { 'recipient': str({'id': sid}), 'message': str({'attachment': {'type': "image", 'payload': {}}}), 'filedata': (filename, open(filename, 'rb'), 'image/png') }

multipart_data = MultipartEncoder(payload) multipart_header = {'Content-Type': multipart_data.content_type}

requests.post( 'https://graph.facebook.com/v2.6/me/messages', data=multipart_data, params={'access_token': THE_TOKEN}, headers=multipart_header).json()

Can you add verify this and fix a bug?

Cretezy commented 7 years ago

Are you using Python 2? And can you explain the fix (or make a PR)?

Cretezy commented 7 years ago

https://github.com/Cretezy/pymessenger2/pull/14