# Path: golem/core/responses/buttons.py
# class Button(MessageElement, ABC):
#     """
#     An abstract chat button. Don't use this class directly.
#     """
# 
#     @abstractmethod
#     def to_response(self):
#         raise NotImplementedError('Abstract method')
# 
#     @abstractmethod
#     def __str__(self):
#         raise NotImplementedError('Abstract method')
# 
# class LinkButton(Button):
#     """
#     A button that opens a website when clicked.
#     """
# 
#     def __init__(self, title, url, webview=False):
#         super(Button, self).__init__()
#         self.title = title
#         self.url = url
#         self.webview_height_ratio = 'compact' if webview else 'full'
# 
#     def to_response(self):
#         return {
#             'title': self.title,
#             'type': 'web_url',
#             'url': self.url,
#             'webview_height_ratio': self.webview_height_ratio
#         }
# 
#     def __str__(self):
#         return 'button: {}: {}'.format(self.title, self.url)
# 
# class PayloadButton(Button):
#     """
#     A button that sends predefined data back to the bot when clicked.
#     """
# 
#     def __init__(self, title, payload):
#         super(Button, self).__init__()
#         self.title = title
#         self.payload = payload
# 
#     def to_response(self):
#         return {
#             'title': self.title,
#             'type': 'postback',
#             'payload': json.dumps(self.payload, default=json_serialize)
#         }
# 
#     def __str__(self):
#         return 'button: {}: {}'.format(self.title, self.payload)
# 
# Path: golem/core/responses/quick_reply.py
# class QuickReply(MessageElement):
#     """
#     A button with text that gets sent as message when clicked.
#     """
# 
#     def __init__(self, title=None, payload=None, image_url=None):
#         self.title = title
#         self.payload = payload
#         self.image_url = image_url
# 
#     def to_response(self):
#         response = {
#             "content_type": 'text',
#             'title': self.title[:20],
#             'payload': json.dumps(self.payload if self.payload else {}, default=json_serialize)
#         }
#         if self.image_url:
#             response['image_url'] = self.image_url
#         return response
# 
#     def __str__(self):
#         text = 'quick_reply: '
#         if self.title:
#             text += self.title + ': '
#         if self.payload:
#             text += _get_payload_string(self.payload)
#         return text
# 
# class LocationQuickReply(QuickReply):
#     """
#     A button that asks for user's location when clicked.
#     Currently only supported on Facebook Messenger.
#     """
# 
#     def __init__(self):
#         super().__init__()
# 
#     def to_response(self):
#         return {'content_type': 'location'}
# 
#     def __str__(self):
#         return str(super) + " location"
# 
# Path: golem/core/responses/templates.py
# class ListTemplate(MessageElement):
# 
#     def __init__(self, is_compact=False, button=None):
#         super().__init__()
#         self.elements = []  # type: List[GenericTemplateElement]
#         self.compact = is_compact
#         self.button = button
# 
#     def add_element(self, element: GenericTemplateElement):
#         self.elements.append(element)
#         return self
# 
#     def create_element(self, **kwargs):
#         element = GenericTemplateElement(**kwargs)
#         return self.add_element(element)
# 
#     def to_response(self):
#         response = {
#             "attachment": {
#                 "type": "template",
#                 "payload": {
#                     "template_type": "list",
#                     'top_element_style': 'compact' if self.compact else 'large',
#                     "elements": [element.to_response() for element in self.elements[:4]]
#                 }
#             }
#         }
#         if self.button:
#             response['attachment']['payload']['buttons'] = [self.button.to_response()]
# 
#         return response


import json
import logging
from typing import List, Optional
from golem.core.responses.buttons import Button, LinkButton, PayloadButton
from golem.core.responses.quick_reply import QuickReply, LocationQuickReply
from golem.core.responses.responses import *
from golem.core.responses.templates import ListTemplate
                from golem.core.interfaces.telegram import TelegramInterface
        payload = {
            'chat_id': self.id,
            'text': text
        }
        if parse_mode:
            payload['parse_mode'] = parse_mode
        if silent:
            payload['disable_notification'] = True
        if reply:
            payload['reply_markup'] = json.dumps(reply)
        return 'sendMessage', payload

    def quick_replies(self, replies: List[QuickReply]) -> dict:
        row = []
        for reply in replies:
            if isinstance(reply, LocationQuickReply):
                logging.warning('Skipping location quick reply, not supported')
                continue  # TODO support telegram location, keyboard <> inline keyboard
            key_button = {
                'text': reply.title
            }
            row.append(key_button)
        keyboard = [row]
        return {
            'keyboard': keyboard,
            'resize_keyboard': True,
            'one_time_keyboard': True
        }

    def buttons(self, buttons: List[Button] or Button) -> Optional[dict]:

# Path: golem/core/responses/buttons.py
# class Button(MessageElement, ABC):
#     """
#     An abstract chat button. Don't use this class directly.
#     """
# 
#     @abstractmethod
#     def to_response(self):
#         raise NotImplementedError('Abstract method')
# 
#     @abstractmethod
#     def __str__(self):
#         raise NotImplementedError('Abstract method')
# 
# class LinkButton(Button):
#     """
#     A button that opens a website when clicked.
#     """
# 
#     def __init__(self, title, url, webview=False):
#         super(Button, self).__init__()
#         self.title = title
#         self.url = url
#         self.webview_height_ratio = 'compact' if webview else 'full'
# 
#     def to_response(self):
#         return {
#             'title': self.title,
#             'type': 'web_url',
#             'url': self.url,
#             'webview_height_ratio': self.webview_height_ratio
#         }
# 
#     def __str__(self):
#         return 'button: {}: {}'.format(self.title, self.url)
# 
# class PayloadButton(Button):
#     """
#     A button that sends predefined data back to the bot when clicked.
#     """
# 
#     def __init__(self, title, payload):
#         super(Button, self).__init__()
#         self.title = title
#         self.payload = payload
# 
#     def to_response(self):
#         return {
#             'title': self.title,
#             'type': 'postback',
#             'payload': json.dumps(self.payload, default=json_serialize)
#         }
# 
#     def __str__(self):
#         return 'button: {}: {}'.format(self.title, self.payload)
# 
# Path: golem/core/responses/quick_reply.py
# class QuickReply(MessageElement):
#     """
#     A button with text that gets sent as message when clicked.
#     """
# 
#     def __init__(self, title=None, payload=None, image_url=None):
#         self.title = title
#         self.payload = payload
#         self.image_url = image_url
# 
#     def to_response(self):
#         response = {
#             "content_type": 'text',
#             'title': self.title[:20],
#             'payload': json.dumps(self.payload if self.payload else {}, default=json_serialize)
#         }
#         if self.image_url:
#             response['image_url'] = self.image_url
#         return response
# 
#     def __str__(self):
#         text = 'quick_reply: '
#         if self.title:
#             text += self.title + ': '
#         if self.payload:
#             text += _get_payload_string(self.payload)
#         return text
# 
# class LocationQuickReply(QuickReply):
#     """
#     A button that asks for user's location when clicked.
#     Currently only supported on Facebook Messenger.
#     """
# 
#     def __init__(self):
#         super().__init__()
# 
#     def to_response(self):
#         return {'content_type': 'location'}
# 
#     def __str__(self):
#         return str(super) + " location"
# 
# Path: golem/core/responses/templates.py
# class ListTemplate(MessageElement):
# 
#     def __init__(self, is_compact=False, button=None):
#         super().__init__()
#         self.elements = []  # type: List[GenericTemplateElement]
#         self.compact = is_compact
#         self.button = button
# 
#     def add_element(self, element: GenericTemplateElement):
#         self.elements.append(element)
#         return self
# 
#     def create_element(self, **kwargs):
#         element = GenericTemplateElement(**kwargs)
#         return self.add_element(element)
# 
#     def to_response(self):
#         response = {
#             "attachment": {
#                 "type": "template",
#                 "payload": {
#                     "template_type": "list",
#                     'top_element_style': 'compact' if self.compact else 'large',
#                     "elements": [element.to_response() for element in self.elements[:4]]
#                 }
#             }
#         }
#         if self.button:
#             response['attachment']['payload']['buttons'] = [self.button.to_response()]
# 
#         return response


# Path: golem/core/interfaces/adapter/telegram.py
import json
import logging
from typing import List, Optional
from golem.core.responses.buttons import Button, LinkButton, PayloadButton
from golem.core.responses.quick_reply import QuickReply, LocationQuickReply
from golem.core.responses.responses import *
from golem.core.responses.templates import ListTemplate
                from golem.core.interfaces.telegram import TelegramInterface

        payload = {
            'chat_id': self.id,
            'text': text
        }
        if parse_mode:
            payload['parse_mode'] = parse_mode
        if silent:
            payload['disable_notification'] = True
        if reply:
            payload['reply_markup'] = json.dumps(reply)
        return 'sendMessage', payload

    def quick_replies(self, replies: List[QuickReply]) -> dict:
        row = []
        for reply in replies:
            if isinstance(reply, LocationQuickReply):
                logging.warning('Skipping location quick reply, not supported')
                continue  # TODO support telegram location, keyboard <> inline keyboard
            key_button = {
                'text': reply.title
            }
            row.append(key_button)
        keyboard = [row]
        return {
            'keyboard': keyboard,
            'resize_keyboard': True,
            'one_time_keyboard': True
        }

    def buttons(self, buttons: List[Button] or Button) -> Optional[dict]:

        if isinstance(buttons, Button):