I am developing FB bot on GAE and one of the function of my bot is sending images. I want to attach my image and send it to user (not via link).
The problem is I get error: recipient must be specified, but actually i have specified it:
from requests_toolbelt import MultipartEncoder
from google.appengine.api import urlfetch
def send_image(recipient_id):
payload = {
'recipient': json.dumps(
{
'id': recipient_id
}
),
'message': json.dumps(
{
'attachment': {
'type': 'image',
'payload': {}
}
}
),
'filedata': (path, open(path, 'rb'))
}
multipart_data = MultipartEncoder(payload)
multipart_header = {
u'Content-Type': multipart_data.content_type
}
result = urlfetch.fetch(
url=request_endpoint,
payload=multipart_data,
method=urlfetch.POST,
headers=multipart_header,
deadline=10)
return result.content
result.response:
'{"error":{"message":"(#100) The parameter recipient is required","type":"OAuthException","code":100,"fbtrace_id":"CIGds8u22au"}}'