From dbe9ce49dfe5c7c77a47576c77f343d599fb647a Mon Sep 17 00:00:00 2001 From: Badiboy Date: Tue, 21 Jul 2020 01:20:01 +0300 Subject: [PATCH] Minor updates in code --- telebot/__init__.py | 56 +++++++++++++++++++++++--------------------- telebot/apihelper.py | 25 +++++++++++++------- telebot/types.py | 2 +- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index ffde7e3..14366b5 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -648,14 +648,14 @@ class TeleBot: return types.Message.de_json( apihelper.forward_message(self.token, chat_id, from_chat_id, message_id, disable_notification, timeout)) - def delete_message(self, chat_id, message_id): + def delete_message(self, chat_id, message_id, timeout=None): """ Use this method to delete message. Returns True on success. :param chat_id: in which chat to delete :param message_id: which message to delete :return: API reply. """ - return apihelper.delete_message(self.token, chat_id, message_id) + return apihelper.delete_message(self.token, chat_id, message_id, timeout) def send_dice( self, chat_id, @@ -1252,39 +1252,41 @@ class TeleBot: def send_invoice(self, chat_id, title, description, invoice_payload, provider_token, currency, prices, start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, - is_flexible=None, disable_notification=None, reply_to_message_id=None, reply_markup=None, - provider_data=None, timeout=None): + send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None, + disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None, timeout=None): """ Sends invoice - :param chat_id: - :param title: - :param description: - :param invoice_payload: - :param provider_token: - :param currency: - :param prices: - :param start_parameter: - :param photo_url: - :param photo_size: - :param photo_width: - :param photo_height: - :param need_name: - :param need_phone_number: - :param need_email: - :param need_shipping_address: - :param is_flexible: - :param disable_notification: - :param reply_to_message_id: - :param reply_markup: - :param provider_data: + :param chat_id: Unique identifier for the target private chat + :param title: Product name + :param description: Product description + :param invoice_payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + :param provider_token: Payments provider token, obtained via @Botfather + :param currency: Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies + :param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + :param start_parameter: Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter + :param photo_url: URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for. + :param photo_size: Photo size + :param photo_width: Photo width + :param photo_height: Photo height + :param need_name: Pass True, if you require the user's full name to complete the order + :param need_phone_number: Pass True, if you require the user's phone number to complete the order + :param need_email: Pass True, if you require the user's email to complete the order + :param need_shipping_address: Pass True, if you require the user's shipping address to complete the order + :param is_flexible: Pass True, if the final price depends on the shipping method + :param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider + :param send_email_to_provider: Pass True, if user's email address should be sent to provider + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :param reply_to_message_id: If the message is a reply, ID of the original message + :param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button + :param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. :return: """ result = apihelper.send_invoice( self.token, chat_id, title, description, invoice_payload, provider_token, currency, prices, start_parameter, photo_url, photo_size, photo_width, photo_height, need_name, need_phone_number, need_email, need_shipping_address, - is_flexible, disable_notification, reply_to_message_id, reply_markup, - provider_data, timeout) + send_phone_number_to_provider, send_email_to_provider, is_flexible, disable_notification, + reply_to_message_id, reply_markup, provider_data, timeout) return types.Message.de_json(result) def send_poll( diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 8a6ae75..b3a6abf 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -320,7 +320,7 @@ def send_media_group( disable_notification=None, reply_to_message_id=None, timeout=None): method_url = r'sendMediaGroup' - media_json, files = _convert_input_media_array(media) + media_json, files = convert_input_media_array(media) payload = {'chat_id': chat_id, 'media': media_json} if disable_notification is not None: payload['disable_notification'] = disable_notification @@ -781,7 +781,7 @@ def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_m def edit_message_media(token, media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): method_url = r'editMessageMedia' - media_json, file = _convert_input_media(media) + media_json, file = convert_input_media(media) payload = {'media': media_json} if chat_id: payload['chat_id'] = chat_id @@ -808,9 +808,11 @@ def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_messa return _make_request(token, method_url, params=payload, method='post') -def delete_message(token, chat_id, message_id): +def delete_message(token, chat_id, message_id, timeout=None): method_url = r'deleteMessage' payload = {'chat_id': chat_id, 'message_id': message_id} + if timeout: + payload['connect-timeout'] = timeout return _make_request(token, method_url, params=payload, method='post') @@ -890,7 +892,8 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m def send_invoice( token, chat_id, title, description, invoice_payload, provider_token, currency, prices, start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None, - need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, + need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, + send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None, disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None, timeout=None): """ @@ -913,10 +916,12 @@ def send_invoice( :param need_email: Pass True, if you require the user's email to complete the order :param need_shipping_address: Pass True, if you require the user's shipping address to complete the order :param is_flexible: Pass True, if the final price depends on the shipping method + :param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider + :param send_email_to_provider: Pass True, if user's email address should be sent to provider :param disable_notification: Sends the message silently. Users will receive a notification with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message :param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button - :param provider_data: + :param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. :return: """ method_url = r'sendInvoice' @@ -939,6 +944,10 @@ def send_invoice( payload['need_email'] = need_email if need_shipping_address is not None: payload['need_shipping_address'] = need_shipping_address + if send_phone_number_to_provider is not None: + payload['send_phone_number_to_provider'] = send_phone_number_to_provider + if send_email_to_provider is not None: + payload['send_email_to_provider'] = send_email_to_provider if is_flexible is not None: payload['is_flexible'] = is_flexible if disable_notification is not None: @@ -1154,13 +1163,13 @@ def _convert_markup(markup): return markup -def _convert_input_media(media): +def convert_input_media(media): if isinstance(media, types.InputMedia): - return media._convert_input_media() + return media.convert_input_media() return None, None -def _convert_input_media_array(array): +def convert_input_media_array(array): media = [] files = {} for input_media in array: diff --git a/telebot/types.py b/telebot/types.py index cf3d7e9..19c6d35 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -2268,7 +2268,7 @@ class InputMedia(Dictionaryable, JsonSerializable): json_dict['parse_mode'] = self.parse_mode return json_dict - def _convert_input_media(self): + def convert_input_media(self): if util.is_string(self.media): return self.to_json(), None