import json
import requests
from requests_toolbelt import MultipartEncoder

DEFAULT_API_VERSION = 2.6

class Bot(object):
    def __init__(self, access_token, api_version=DEFAULT_API_VERSION):
        self.api_version = api_version
        self.access_token = access_token
        self.base_url = (
            "https://graph.facebook.com"
            "/v{0}/me/messages?access_token={1}"
        ).format(self.api_version, access_token)

    def send_text_message(self, recipient_id, message):
        payload = {
            'recipient': {
                'id': recipient_id
            },
            'message': {
                'text': message
            }
        }
        result = requests.post(self.base_url, json=payload)
        return result.json()

    def send_message(self, recipient_id, message):
        payload = {
            'recipient': {
                'id': recipient_id
            },
            'message': message
        }
        return requests.post(self.base_url, json=payload).json()

    def send_generic_message(self, recipient_id, elements):
        payload = {
            'recipient': {
                'id': recipient_id
            },
            'message': {
                "attachment": {
                    "type": "template",
                    "payload": {
                        "template_type": "generic",
                        "elements": elements
                    }
                }
            }
        }
        return requests.post(self.base_url, json=payload).json()

    def send_image(self, recipient_id, image_path):
        payload = {
            'recipient': json.dumps(
                {
                    'id': recipient_id
                }
            ),
            'message': json.dumps(
                {
                    'attachment': {
                        'type': 'image',
                        'payload': {}
                    }
                }
            ),
            'filedata': (image_path, open(image_path, 'rb'))
        }
        multipart_data = MultipartEncoder(payload)
        multipart_header = {
            'Content-Type': multipart_data.content_type
        }
        return requests.post(self.base_url, data=multipart_data, headers=multipart_header)

@@ -680,85 +680,39 @@
   re
-sult = requests.post(self.base_url, json=payload)%0A        return result.json(
+turn self._send_payload(payload
 )%0A%0A 
@@ -918,56 +918,34 @@
 urn 
-requests.post(self.base_url, json=payload).json(
+self._send_payload(payload
 )%0A%0A 
@@ -1397,32 +1397,647 @@
 %7D%0A        return
+ self._send_payload(payload)%0A%0A    def send_button_message(self, recipient_id, text, buttons):%0A        payload = %7B%0A            'recipient': %7B%0A                'id': recipient_id%0A            %7D,%0A            'message': %7B%0A                %22attachment%22: %7B%0A                    %22type%22: %22template%22,%0A                    %22payload%22: %7B%0A                        %22template_type%22: %22button%22,%0A                        %22text%22: text,%0A                        %22buttons%22: buttons%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return self._send_payload(payload)%0A%0A    def _send_payload(self, payload):%0A        result =
  requests.post(s
@@ -2070,16 +2070,38 @@
 ).json()
+%0A        return result
 %0A%0A    de
@@ -2146,16 +2146,284 @@
 _path):%0A
+        '''%0A            This sends an image to the specified recipient.%0A            Input:%0A              recipient_id: recipient id to send to%0A              image_path: path to image to be sent%0A            Output:%0A              Response from API as %3Cdict%3E%0A        '''%0A
         
@@ -3091,9 +3091,16 @@
 _header)
+.json()
 %0A

Add button message support