import requests

from bot.api.domain import ApiObject


class TelegramBotApi:
    def __init__(self, auth_token, debug: bool):
        self.base_url = "https://api.telegram.org/bot" + auth_token + "/"
        self.debug = debug

    def get_me(self):
        return self.__send_request("getMe")

    def send_message(self, chat_id, text):
        return self.__send_request("sendMessage", chat_id=chat_id, text=text)

    def get_updates(self, offset=None, timeout=None):
        return self.__send_request("getUpdates", offset=offset, timeout=timeout)

    def __send_request(self, command, **params):
        request = requests.get(self.base_url + command, params=params)
        self.__log_request(request)
        response = request.json()
        self.__log_response(response)
        if not response["ok"]:
            raise TelegramBotApiException(response["description"])
        return ApiObject.wrap_api_object(response["result"])

    def __log_request(self, request):
        if self.debug:
            print(">> " + request.url)

    def __log_response(self, response):
        if self.debug:
            print("<< " + str(response))


class TelegramBotApiException(Exception):
    pass

import requests

from bot.api.domain import ApiObject


class TelegramBotApi:
    def __init__(self, auth_token, debug: bool):
        self.base_url = "https://api.telegram.org/bot" + auth_token + "/"
        self.debug = debug

    def get_me(self):
        return self.__send_request("getMe")

    def send_message(self, chat_id, text):
        return self.__send_request("sendMessage", chat_id=chat_id, text=text)

    def get_updates(self, offset=None, timeout=None):
        return self.__send_request("getUpdates", offset=offset, timeout=timeout)

    def __send_request(self, command, **params):
        request = requests.get(self.base_url + command, params=params, timeout=60)
        self.__log_request(request)
        response = request.json()
        self.__log_response(response)
        if not response["ok"]:
            raise TelegramBotApiException(response["description"])
        return ApiObject.wrap_api_object(response["result"])

    def __log_request(self, request):
        if self.debug:
            print(">> " + request.url)

    def __log_response(self, response):
        if self.debug:
            print("<< " + str(response))


class TelegramBotApiException(Exception):
    pass

Add timeout to requests so that they do get death-locked
Add timeout to requests so that they do get death-locked
