import json

class Message():
    """
    Base message object
    """

    def __init__(self, recipient, type, **kwargs):

        self.recipient = recipient
        self.type = type
        self.kwargs = kwargs

    def to_json(self, text=None, attachment=None):
         """Returns json representation of message"""

        data = {}

        if self.type == 'text':
            data['text'] = self.kwargs['text']
        else:
            data['attachment'] = {}
            data['attachment']['type'] = self.type
            elif self.type == 'template':
                template = self.kwargs['template']
                data['attachment']['payload'] = template.to_json()
            else:
                data['attachment']['payload']['url'] = self.kwargs['url']
    
class StructuredMessage(Message):
    """
    Facebook Messenger message
    model for structured messages
    """

    button_type = 'button'
    generic_type = 'generic'

    def __init__(self, type):
        self.title = ''
        self.sub_title = ''
        self.buttons = []
        self.type = type

    def to_json(self):
        message = {}
        message['message'] = {
                'attachment' : {
                    'type' : 'template',
                }
            }

        if self.type == self.button_type:
            message['message']['attachment']['payload'] = {
                'template_type' : 'button',
                'text' : self.title,
                'buttons' : [b.to_json() for b in self.buttons]
            }
        else:
            pass

        return json.dumps(message)

class ReceivedMessage(Message):
    """
    Model to represent reciepts
    """

    def __init__(self, json):

        if 'text' in json['message']:
            self.type = 'text'
            self.text = json['message']['text']

        self.recipient = json['recipient']['id']
        self.sender = json['sender']['id']
        self.time = json['timestamp']

    def to_json(self):
        raise NotImplementedError


@@ -6,16 +6,118 @@
 t json%0A%0A
+supported_types = %5B%0A    'text',%0A    'image',%0A    'video',%0A    'audio',%0A    'file',%0A    'template' %0A%5D%0A%0A
 class Me
@@ -210,20 +210,91 @@
 pe, 
-**kwargs
+payload
 ):%0A%0A
+        assert type in supported_types, 'That is not a supported type'%0A%0A
     
@@ -366,23 +366,25 @@
 elf.
-kwargs = kwargs
+payload = payload
 %0A%0A  
@@ -405,40 +405,11 @@
 self
-, text=None, attachment=None
 ):%0A
- 
     
@@ -453,25 +453,24 @@
  message%22%22%22%0A
-%0A
         data
@@ -474,16 +474,59 @@
 ata = %7B%7D
+%0A        # TODO: check types on the payload
 %0A%0A      
@@ -587,22 +587,15 @@
 elf.
-kwargs%5B'text'%5D
+payload
 %0A   
@@ -704,18 +704,16 @@
         
-el
 if self.
@@ -768,26 +768,15 @@
 elf.
-kwargs%5B'template'%5D
+payload
 %0A   
@@ -906,36 +906,103 @@
 ad'%5D
-%5B
+ = %7B%0A                    
 'url'
-%5D =
+:
  self.
-kwargs%5B'url'%5D
+payload%0A                %7D%0A%0A        return json.dumps(data)
 %0A   

Update message model