From 18e37f3d20e0537aba14439a507af92ed3ee649a Mon Sep 17 00:00:00 2001 From: nailer Date: Sat, 17 Nov 2018 12:58:56 +0200 Subject: [PATCH 01/20] sleep time timeout time instead of 5 seconds always --- telebot/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 52a4e5a..3a93750 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -364,12 +364,12 @@ class TeleBot: for listener in self.update_listener: self._exec_task(listener, new_messages) - def infinity_polling(self, *args, **kwargs): + def infinity_polling(self, timeout: int = 20, *args, **kwargs): while not self.__stop_polling.is_set(): try: - self.polling(*args, **kwargs) + self.polling(timeout=timeout, *args, **kwargs) except Exception as e: - time.sleep(5) + time.sleep(timeout) pass logger.info("Break infinity polling") From b82ed70ec91baaadddf935f1baf07dc8ec345801 Mon Sep 17 00:00:00 2001 From: nailer Date: Sat, 17 Nov 2018 13:19:09 +0200 Subject: [PATCH 02/20] fix syntax errors --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 3a93750..2cfebbd 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -364,7 +364,7 @@ class TeleBot: for listener in self.update_listener: self._exec_task(listener, new_messages) - def infinity_polling(self, timeout: int = 20, *args, **kwargs): + def infinity_polling(self, timeout=20, *args, **kwargs): while not self.__stop_polling.is_set(): try: self.polling(timeout=timeout, *args, **kwargs) From 8005ca2f6c43fc12d2a700b52eac2a6157589fe2 Mon Sep 17 00:00:00 2001 From: FrankWang Date: Sat, 29 Dec 2018 23:49:10 +0800 Subject: [PATCH 03/20] Update example for api server check webhook alive. --- examples/webhook_examples/webhook_cpython_echo_bot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/webhook_examples/webhook_cpython_echo_bot.py b/examples/webhook_examples/webhook_cpython_echo_bot.py index 029f361..528d636 100644 --- a/examples/webhook_examples/webhook_cpython_echo_bot.py +++ b/examples/webhook_examples/webhook_cpython_echo_bot.py @@ -86,11 +86,13 @@ def echo_message(message): # Remove webhook, it fails sometimes the set if there is a previous webhook -bot.remove_webhook() +#bot.remove_webhook() # Set webhook -bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH, - certificate=open(WEBHOOK_SSL_CERT, 'r')) +# Beacuse telegram bot api server will check webhook server is alive. +# Here we need set webhook after server started manually. +#bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH, +# certificate=open(WEBHOOK_SSL_CERT, 'r')) # Start server httpd = HTTPServer((WEBHOOK_LISTEN, WEBHOOK_PORT), From 79e6a3166da036435f31e197f8ea5a72edc838e6 Mon Sep 17 00:00:00 2001 From: Moon Princess Date: Sun, 20 Jan 2019 23:04:11 +0500 Subject: [PATCH 04/20] edit message_handler doc --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 52a4e5a..8c5b9cd 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1333,7 +1333,7 @@ class TeleBot: bot.send_message(message.chat.id, 'Document received, sir!') # Handle all other commands. - @bot.message_handler(func=lambda message: True, content_types=['audio', 'video', 'document', 'text', 'location', 'contact', 'sticker']) + @bot.message_handler(func=lambda message: True, content_types=['audio', 'photo', 'voice', 'video', 'document', 'text', 'location', 'contact', 'sticker']) def default_command(message): bot.send_message(message.chat.id, "This is the default command handler.") From 1a58731fb74890e3821fd27a86eeb5a693eae861 Mon Sep 17 00:00:00 2001 From: Victor Koropetskyi Date: Sat, 23 Feb 2019 16:15:20 +0200 Subject: [PATCH 05/20] Add 'method' parameter to methods that edit message --- telebot/apihelper.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 839754f..749fc98 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -619,7 +619,7 @@ def edit_message_text(token, text, chat_id=None, message_id=None, inline_message payload['disable_web_page_preview'] = disable_web_page_preview if reply_markup: payload['reply_markup'] = _convert_markup(reply_markup) - return _make_request(token, method_url, params=payload) + return _make_request(token, method_url, params=payload, method='post') def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_message_id=None, @@ -636,7 +636,7 @@ def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_m payload['parse_mode'] = parse_mode if reply_markup: payload['reply_markup'] = _convert_markup(reply_markup) - return _make_request(token, method_url, params=payload) + return _make_request(token, method_url, params=payload, method='post') def edit_message_media(token, media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): @@ -665,13 +665,13 @@ def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_messa payload['inline_message_id'] = inline_message_id if reply_markup: payload['reply_markup'] = _convert_markup(reply_markup) - return _make_request(token, method_url, params=payload) + return _make_request(token, method_url, params=payload, method='post') def delete_message(token, chat_id, message_id): method_url = r'deleteMessage' payload = {'chat_id': chat_id, 'message_id': message_id} - return _make_request(token, method_url, params=payload) + return _make_request(token, method_url, params=payload, method='post') # Game @@ -814,7 +814,7 @@ def answer_shipping_query(token, shipping_query_id, ok, shipping_options=None, e :param ok: Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible) :param shipping_options: Required if ok is True. A JSON-serialized array of available shipping options. :param error_message: Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user. - :return: + :return: """ method_url = 'answerShippingQuery' payload = {'shipping_query_id': shipping_query_id, 'ok': ok} @@ -832,7 +832,7 @@ def answer_pre_checkout_query(token, pre_checkout_query_id, ok, error_message=No :param pre_checkout_query_id: Unique identifier for the query to be answered :param ok: Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. :param error_message: Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. - :return: + :return: """ method_url = 'answerPreCheckoutQuery' payload = {'pre_checkout_query_id': pre_checkout_query_id, 'ok': ok} From c77307881d29f73048686eb4d30d5bf0931c50aa Mon Sep 17 00:00:00 2001 From: iv8 <44664770+iv8@users.noreply.github.com> Date: Mon, 4 Mar 2019 15:24:55 +0800 Subject: [PATCH 06/20] fix errors --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fbe40e8..c16cb36 100644 --- a/README.md +++ b/README.md @@ -524,16 +524,16 @@ Telegram Bot API support new type Chat for message.chat. - Check the ```type``` attribute in ```Chat``` object: - ```python -if message.chat.type == “private”: +if message.chat.type == "private": # private chat message -if message.chat.type == “group”: +if message.chat.type == "group": # group chat message -if message.chat.type == “supergroup”: +if message.chat.type == "supergroup": # supergroup chat message -if message.chat.type == “channel”: +if message.chat.type == "channel": # channel message ``` From 2285d0466e6dba3924a0bbfdb7a64d10ee221142 Mon Sep 17 00:00:00 2001 From: David Lorenzo <17401854+Pythoneiro@users.noreply.github.com> Date: Tue, 9 Apr 2019 11:32:15 +0200 Subject: [PATCH 07/20] update bot list Remove areajugonesbot; add vigobustelegrambot --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c16cb36..0a8e715 100644 --- a/README.md +++ b/README.md @@ -576,7 +576,6 @@ Get help. Discuss. Chat. * [EmaProject](https://github.com/halkliff/emaproject) by [*halkliff*](https://github.com/halkliff) - Ema - Eastern Media Assistant was made thinking on the ease-to-use feature. Coding here is simple, as much as is fast and powerful. * [filmratingbot](http://t.me/filmratingbot)([source](https://github.com/jcolladosp/film-rating-bot)) by [*jcolladosp*](https://github.com/jcolladosp) - Telegram bot using the Python API that gets films rating from IMDb and metacritic * [you2mp3bot](http://t.me/you2mp3bot)([link](https://storebot.me/bot/you2mp3bot)) - This bot can convert a Youtube video to Mp3. All you need is send the URL video. -* [areajugonesbot](http://t.me/areajugonesbot)([link](http://t.me/areajugonesbot)) - The areajugonesbot sends news published on the videogames blog Areajugones to Telegram. * [Send2Kindlebot](http://t.me/Send2KindleBot) ([source](https://github.com/GabrielRF/Send2KindleBot)) by *GabrielRF* - Send to Kindle service. * [RastreioBot](http://t.me/RastreioBot) ([source](https://github.com/GabrielRF/RastreioBot)) by *GabrielRF* - Bot used to track packages on the Brazilian Mail Service. * [filex_bot](http://t.me/filex_bot)([link](https://github.com/victor141516/FileXbot-telegram)) @@ -587,6 +586,7 @@ Get help. Discuss. Chat. * [MusicQuiz_bot](https://t.me/MusicQuiz_bot) by [Etoneja](https://github.com/Etoneja) - Listen to audiosamles and try to name the performer of the song. * [Bot-Telegram-Shodan ](https://github.com/rubenleon/Bot-Telegram-Shodan) by [rubenleon](https://github.com/rubenleon) * [MandangoBot](https://t.me/MandangoBot) by @Alvaricias - Bot for managing Marvel Strike Force alliances (only in spanish, atm). +* [VigoBusTelegramBot](https://t.me/vigobusbot) ([GitHub](https://github.com/Pythoneiro/VigoBus-TelegramBot)) - Bot that provides buses coming to a certain stop and their remaining time for the city of Vigo (Galicia - Spain) Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh. From 7dc9abffc6477e8ea78157580c6c007fc63ba0b1 Mon Sep 17 00:00:00 2001 From: SetazeR Date: Tue, 16 Apr 2019 07:38:50 +0700 Subject: [PATCH 08/20] remove unnecessary f-strings --- examples/inline_keyboard_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/inline_keyboard_example.py b/examples/inline_keyboard_example.py index 0618eee..f2b3fce 100644 --- a/examples/inline_keyboard_example.py +++ b/examples/inline_keyboard_example.py @@ -9,8 +9,8 @@ bot = telebot.TeleBot(TELEGRAM_TOKEN) def gen_markup(): markup = InlineKeyboardMarkup() markup.row_width = 2 - markup.add(InlineKeyboardButton("Yes", callback_data=f"cb_yes"), - InlineKeyboardButton("No", callback_data=f"cb_no")) + markup.add(InlineKeyboardButton("Yes", callback_data="cb_yes"), + InlineKeyboardButton("No", callback_data="cb_no")) return markup @bot.callback_query_handler(func=lambda call: True) From f51643836091284553b10b14cca96e9f69c46fdd Mon Sep 17 00:00:00 2001 From: Airat K Date: Sun, 21 Apr 2019 18:34:10 +0300 Subject: [PATCH 09/20] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c16cb36..afb7465 100644 --- a/README.md +++ b/README.md @@ -587,6 +587,7 @@ Get help. Discuss. Chat. * [MusicQuiz_bot](https://t.me/MusicQuiz_bot) by [Etoneja](https://github.com/Etoneja) - Listen to audiosamles and try to name the performer of the song. * [Bot-Telegram-Shodan ](https://github.com/rubenleon/Bot-Telegram-Shodan) by [rubenleon](https://github.com/rubenleon) * [MandangoBot](https://t.me/MandangoBot) by @Alvaricias - Bot for managing Marvel Strike Force alliances (only in spanish, atm). +* [kaishnik-bot](https://t.me/kaishnik_bot) ([source](https://github.com/airatk/kaishnik-bot)) by *airatk* - bot which shows all the necessary information to KNTRU-KAI students. Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh. From 2d0ebde481d7d531bb9dd2bc0c84fe63ca688292 Mon Sep 17 00:00:00 2001 From: Komron Date: Wed, 24 Apr 2019 11:29:52 +0200 Subject: [PATCH 10/20] added creationdatebot to bots api list --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index afb7465..62574f0 100644 --- a/README.md +++ b/README.md @@ -581,13 +581,14 @@ Get help. Discuss. Chat. * [RastreioBot](http://t.me/RastreioBot) ([source](https://github.com/GabrielRF/RastreioBot)) by *GabrielRF* - Bot used to track packages on the Brazilian Mail Service. * [filex_bot](http://t.me/filex_bot)([link](https://github.com/victor141516/FileXbot-telegram)) * [Spbu4UBot](http://t.me/Spbu4UBot)([link](https://github.com/EeOneDown/spbu4u)) by *EeOneDown* - Bot with timetables for SPbU students. -* [SmartySBot](http://t.me/ZDU_bot)([link](https://github.com/0xVK/SmartySBot)) by *0xVK* - Telegram timetable bot, for Zhytomyr Ivan Franko State University students. +* [SmartySBot](http://t.me/ZDU_bot)([link](https://github.com/0xVK/SmartySBot)) by *0xVK* - Telegram timetable bot, for Zhytomyr Ivan Franko State University students. * [yandex_music_bot](http://t.me/yandex_music_bot)- Downloads tracks/albums/public playlists from Yandex.Music streaming service for free. * [LearnIt](https://t.me/LearnItbot)([link](https://github.com/tiagonapoli/LearnIt)) - A Telegram Bot created to help people to memorize other languages’ vocabulary. * [MusicQuiz_bot](https://t.me/MusicQuiz_bot) by [Etoneja](https://github.com/Etoneja) - Listen to audiosamles and try to name the performer of the song. * [Bot-Telegram-Shodan ](https://github.com/rubenleon/Bot-Telegram-Shodan) by [rubenleon](https://github.com/rubenleon) * [MandangoBot](https://t.me/MandangoBot) by @Alvaricias - Bot for managing Marvel Strike Force alliances (only in spanish, atm). * [kaishnik-bot](https://t.me/kaishnik_bot) ([source](https://github.com/airatk/kaishnik-bot)) by *airatk* - bot which shows all the necessary information to KNTRU-KAI students. +* [Creation Date](https://t.me/creationdatebot) by @karipov - interpolates account creation dates based on telegram given ID’s Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh. From ceceeb7d8c4d55fed05eda7f0447d9dc33e12d02 Mon Sep 17 00:00:00 2001 From: FrankWang Date: Fri, 24 May 2019 15:05:20 +0800 Subject: [PATCH 11/20] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 62574f0..ef5a177 100644 --- a/README.md +++ b/README.md @@ -589,6 +589,8 @@ Get help. Discuss. Chat. * [MandangoBot](https://t.me/MandangoBot) by @Alvaricias - Bot for managing Marvel Strike Force alliances (only in spanish, atm). * [kaishnik-bot](https://t.me/kaishnik_bot) ([source](https://github.com/airatk/kaishnik-bot)) by *airatk* - bot which shows all the necessary information to KNTRU-KAI students. * [Creation Date](https://t.me/creationdatebot) by @karipov - interpolates account creation dates based on telegram given ID’s +* [m0xbot](https://t.me/m0xbot) by [kor0p](https://github.com/kor0p) - tic-tac-toe. +* [kboardbot](https://t.me/kboardbot) by [kor0p](https://github.com/kor0p) - inline switches keyboard layout (English, Hebrew, Ukrainian, Russian). Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh. From 55c7b6373c62154142176444bf3f73cf5c4e579a Mon Sep 17 00:00:00 2001 From: FacuM Date: Thu, 30 May 2019 00:35:23 -0300 Subject: [PATCH 12/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef5a177..06d992c 100644 --- a/README.md +++ b/README.md @@ -591,6 +591,6 @@ Get help. Discuss. Chat. * [Creation Date](https://t.me/creationdatebot) by @karipov - interpolates account creation dates based on telegram given ID’s * [m0xbot](https://t.me/m0xbot) by [kor0p](https://github.com/kor0p) - tic-tac-toe. * [kboardbot](https://t.me/kboardbot) by [kor0p](https://github.com/kor0p) - inline switches keyboard layout (English, Hebrew, Ukrainian, Russian). - +* [Robbie](https://t.me/romdeliverybot) ([source](https://github.com/FacuM/romdeliverybot_support)) by @FacuM - Support Telegram bot for developers and maintainers. Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh. From 9624b45314b46eff513a90240449a9fae50e153a Mon Sep 17 00:00:00 2001 From: Tiger 1 Date: Thu, 6 Jun 2019 21:47:08 +0300 Subject: [PATCH 13/20] add Poll, sendPoll, stopPoll --- telebot/__init__.py | 7 +++++++ telebot/apihelper.py | 20 ++++++++++++++++++ telebot/types.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ tests/my_tests.py | 41 +++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 tests/my_tests.py diff --git a/telebot/__init__.py b/telebot/__init__.py index 52a4e5a..98076cd 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -113,6 +113,7 @@ class TeleBot: getUserProfilePhotos getUpdates getFile + sendPoll kickChatMember unbanChatMember restrictChatMember @@ -1044,6 +1045,12 @@ class TeleBot: disable_notification, reply_to_message_id, reply_markup, provider_data) return types.Message.de_json(result) + def send_poll(self, chat_id, poll, disable_notifications=False, reply_to_message=None, reply_markup=None): + return types.Message.de_json(apihelper.send_poll(self.token, chat_id, poll.question, poll.options, disable_notifications, reply_to_message, reply_markup)) + + def stop_poll(self, chat_id, message_id): + return types.Poll.de_json(apihelper.stop_poll(self.token, chat_id, message_id)) + def answer_shipping_query(self, shipping_query_id, ok, shipping_options=None, error_message=None): return apihelper.answer_shipping_query(self.token, shipping_query_id, ok, shipping_options, error_message) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 749fc98..094fbbf 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -938,6 +938,26 @@ def delete_sticker_from_set(token, sticker): return _make_request(token, method_url, params=payload, method='post') +def send_poll(token, chat_id, question, options, disable_notifications=False, reply_to_message_id=None, reply_markup=None): + method_url = r'sendPoll' + payload = {'chat_id': str(chat_id), 'question': question, 'options': _convert_list_json_serializable(options)} + if disable_notifications: + payload['disable_notification'] = disable_notifications + if reply_to_message_id: + payload['reply_to_message_id'] = reply_to_message_id + if reply_markup: + payload['reply_markup'] = _convert_markup(reply_markup) + return _make_request(token, method_url, params=payload) + + +def stop_poll(token, chat_id, message_id, reply_markup=None): + method_url = r'stopPoll' + payload = {'chat_id': str(chat_id), 'message_id': message_id} + if reply_markup: + payload['reply_markup'] = _convert_markup(reply_markup) + return _make_request(token, method_url, params=payload) + + def _convert_list_json_serializable(results): ret = '' for r in results: diff --git a/telebot/types.py b/telebot/types.py index 6165c94..0965ebd 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -368,6 +368,9 @@ class Message(JsonDeserializable): if 'connected_website' in obj: opts['connected_website'] = obj['connected_website'] content_type = 'connected_website' + if 'poll' in obj: + opts['poll'] = Poll.de_json(obj['poll']) + content_type = 'poll' return cls(message_id, from_user, date, chat, content_type, opts, json_string) @classmethod @@ -2173,3 +2176,48 @@ class InputMediaDocument(InputMedia): if self.thumb: ret['thumb'] = self.thumb return ret + + +class PollOption(JsonSerializable, JsonDeserializable): + @classmethod + def de_json(cls, json_type): + obj = cls.check_json(json_type) + text = obj['text'] + voter_count = int(obj['voter_count']) + option = cls(text) + option.voter_count = voter_count + return option + + def __init__(self, text): + self.text = text + self.voter_count = 0 + + def to_json(self): + return json.dumps(self.text) + + +class Poll(JsonDeserializable): + @classmethod + def de_json(cls, json_type): + obj = cls.check_json(json_type) + poll_id = obj['id'] + question = obj['question'] + poll = cls(question) + options = [] + for opt in obj['options']: + options.append(PollOption.de_json(opt)) + poll.options = options + is_closed = obj['is_closed'] + poll.id = poll_id + poll.is_closed = is_closed + return poll + + def __init__(self, question): + self.options = [] + self.question = question + + def add(self, option): + if type(option) is PollOption: + self.options.append(option) + else: + self.options.append(PollOption(option)) diff --git a/tests/my_tests.py b/tests/my_tests.py new file mode 100644 index 0000000..05d4078 --- /dev/null +++ b/tests/my_tests.py @@ -0,0 +1,41 @@ +import os +from telebot import logger, logging, types, TeleBot +import telebot.apihelper as api + +try: + TOKEN = os.environ['TOKEN'] +except: + logger.error('Not variable \'TOKEN\' in environ') + exit(1) + +CHAT_ID = -1001405019571 +logger.setLevel(logging.DEBUG) + +bot = TeleBot(TOKEN) + + +@bot.message_handler(content_types=['poll']) +def po(m): + logger.debug('Give poll') + bot.send_message(m.chat.id, 'Я тоже так умею!') + m = bot.send_poll(m.chat.id, m.poll) + print(m.chat.id, m.message_id) + + +def test_send_poll(): + poll = types.Poll('Какой ты сегодня?') + poll.add('Добрый') + poll.add('Веселый') + poll.add('Грустный') + kb = types.InlineKeyboardMarkup() + kb.add(types.InlineKeyboardButton('1', url='t.me/dr_forse')) + result = bot.send_poll(CHAT_ID, poll, reply_to_message=60312, reply_markup=kb) + assert result['poll']['question'] == 'Какой ты сегодня?' + + +def test_stop_poll(): + res = bot.stop_poll(-1001405019571, 60370) + + +test_stop_poll() +bot.polling(none_stop=True, timeout=600) From b10e45f7140921805dc7e2bf0522ce8263634705 Mon Sep 17 00:00:00 2001 From: Tiger 1 Date: Thu, 6 Jun 2019 21:49:06 +0300 Subject: [PATCH 14/20] add Poll, sendPoll, stopPoll --- tests/my_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/my_tests.py b/tests/my_tests.py index 05d4078..80f4abd 100644 --- a/tests/my_tests.py +++ b/tests/my_tests.py @@ -1,6 +1,5 @@ import os from telebot import logger, logging, types, TeleBot -import telebot.apihelper as api try: TOKEN = os.environ['TOKEN'] From a8cf9f4ae59ee02b6f6737b4b2d8aa82df56ab10 Mon Sep 17 00:00:00 2001 From: OslikAi <48922415+OslikAi@users.noreply.github.com> Date: Thu, 6 Jun 2019 21:54:06 +0300 Subject: [PATCH 15/20] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 06d992c..5dcd01b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ * [Using web hooks](#using-web-hooks) * [Logging](#logging) * [Proxy](#proxy) + * [New in library](#new-in-library) * [F.A.Q.](#faq) * [Bot 2.0](#bot-20) * [How can I distinguish a User and a GroupChat in message.chat?](#how-can-i-distinguish-a-user-and-a-groupchat-in-messagechat) @@ -510,6 +511,10 @@ apihelper.proxy = {'https':'socks5://userproxy:password@proxy_address:port'} ``` +## New in library + +06.06.2019 - Добавленна поддержка опросов (Poll). Добавлены функции send_poll, stop_poll + ## F.A.Q. ### Bot 2.0 From 63df69aeb89a4aaa9ed25c42b47be6da73179c4f Mon Sep 17 00:00:00 2001 From: OslikAi <48922415+OslikAi@users.noreply.github.com> Date: Thu, 6 Jun 2019 22:23:11 +0300 Subject: [PATCH 16/20] Delete my_tests.py --- tests/my_tests.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 tests/my_tests.py diff --git a/tests/my_tests.py b/tests/my_tests.py deleted file mode 100644 index 80f4abd..0000000 --- a/tests/my_tests.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -from telebot import logger, logging, types, TeleBot - -try: - TOKEN = os.environ['TOKEN'] -except: - logger.error('Not variable \'TOKEN\' in environ') - exit(1) - -CHAT_ID = -1001405019571 -logger.setLevel(logging.DEBUG) - -bot = TeleBot(TOKEN) - - -@bot.message_handler(content_types=['poll']) -def po(m): - logger.debug('Give poll') - bot.send_message(m.chat.id, 'Я тоже так умею!') - m = bot.send_poll(m.chat.id, m.poll) - print(m.chat.id, m.message_id) - - -def test_send_poll(): - poll = types.Poll('Какой ты сегодня?') - poll.add('Добрый') - poll.add('Веселый') - poll.add('Грустный') - kb = types.InlineKeyboardMarkup() - kb.add(types.InlineKeyboardButton('1', url='t.me/dr_forse')) - result = bot.send_poll(CHAT_ID, poll, reply_to_message=60312, reply_markup=kb) - assert result['poll']['question'] == 'Какой ты сегодня?' - - -def test_stop_poll(): - res = bot.stop_poll(-1001405019571, 60370) - - -test_stop_poll() -bot.polling(none_stop=True, timeout=600) From 3c62e9d391e0b2947ba608526896ebc4b558c7d8 Mon Sep 17 00:00:00 2001 From: Vova Pytsyuk Date: Sat, 15 Jun 2019 22:59:41 +0300 Subject: [PATCH 17/20] Added LoginUrl to types --- telebot/types.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index 6165c94..bdc5bbc 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -885,9 +885,30 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable): return json_dict +class LoginUrl(JsonSerializable): + def __init__(self, url, forward_text=None, bot_username=None, request_write_access=None): + self.url = url + self.forward_text = forward_text + self.bot_username = bot_username + self.request_write_access = request_write_access + + def to_json(self): + return json.dumps(self.to_dic()) + + def to_dic(self): + json_dic = {'url': self.url} + if self.forward_text: + json_dic['forward_text'] = self.forward_text + if self.bot_username: + json_dic['bot_username'] = self.bot_username + if self.request_write_access: + json_dic['request_write_access'] = self.request_write_access + return json_dic + + class InlineKeyboardButton(JsonSerializable): def __init__(self, text, url=None, callback_data=None, switch_inline_query=None, - switch_inline_query_current_chat=None, callback_game=None, pay=None): + switch_inline_query_current_chat=None, callback_game=None, pay=None, login_url=None): self.text = text self.url = url self.callback_data = callback_data @@ -895,6 +916,7 @@ class InlineKeyboardButton(JsonSerializable): self.switch_inline_query_current_chat = switch_inline_query_current_chat self.callback_game = callback_game self.pay = pay + self.login_url = login_url.to_dic() def to_json(self): return json.dumps(self.to_dic()) @@ -913,6 +935,8 @@ class InlineKeyboardButton(JsonSerializable): json_dic['callback_game'] = self.callback_game if self.pay is not None: json_dic['pay'] = self.pay + if self.login_url is not None: + json_dic['login_url'] = self.login_url return json_dic From 600002e1581a6fe457d96d2f6f0213c2b1f978e7 Mon Sep 17 00:00:00 2001 From: Vova Pytsyuk Date: Sat, 15 Jun 2019 23:09:59 +0300 Subject: [PATCH 18/20] Fixed bug with LoginUrl --- telebot/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index bdc5bbc..4de616a 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -916,7 +916,7 @@ class InlineKeyboardButton(JsonSerializable): self.switch_inline_query_current_chat = switch_inline_query_current_chat self.callback_game = callback_game self.pay = pay - self.login_url = login_url.to_dic() + self.login_url = login_url def to_json(self): return json.dumps(self.to_dic()) @@ -936,7 +936,7 @@ class InlineKeyboardButton(JsonSerializable): if self.pay is not None: json_dic['pay'] = self.pay if self.login_url is not None: - json_dic['login_url'] = self.login_url + json_dic['login_url'] = self.login_url.to_dic() return json_dic From 4e57adbcb67eeced1b0a6a10f617d67f5785d2e2 Mon Sep 17 00:00:00 2001 From: desexcile <34170928+desexcile@users.noreply.github.com> Date: Wed, 26 Jun 2019 10:54:59 +0300 Subject: [PATCH 19/20] Update Readme added @asadov_bot to Bot list using this Api --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 06d992c..0c5d402 100644 --- a/README.md +++ b/README.md @@ -592,5 +592,6 @@ Get help. Discuss. Chat. * [m0xbot](https://t.me/m0xbot) by [kor0p](https://github.com/kor0p) - tic-tac-toe. * [kboardbot](https://t.me/kboardbot) by [kor0p](https://github.com/kor0p) - inline switches keyboard layout (English, Hebrew, Ukrainian, Russian). * [Robbie](https://t.me/romdeliverybot) ([source](https://github.com/FacuM/romdeliverybot_support)) by @FacuM - Support Telegram bot for developers and maintainers. +* [AsadovBot](https://t.me/asadov_bot) ([source])(https://github.com/desexcile/BotApi)) by @DesExcile - Сatalog of poems by Eduard Asadov. Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh. From 3a1bdc289929e55d7322945cb21ceca30cc6a9a6 Mon Sep 17 00:00:00 2001 From: P0lunin Date: Thu, 27 Jun 2019 15:07:41 +0300 Subject: [PATCH 20/20] add Poll, sendPoll, stopPoll --- telebot/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index 98076cd..e8cc10b 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1757,3 +1757,11 @@ class AsyncTeleBot(TeleBot): @util.async_dec() def delete_sticker_from_set(self, *args, **kwargs): return TeleBot.delete_sticker_from_set(self, *args, **kwargs) + + @util.async_dec() + def send_poll(self, *args, **kwargs): + return TeleBot.send_poll(self, *args, **kwargs) + + @util.async_dec() + def stop_poll(self, *args, **kwargs): + return TeleBot.stop_poll(self, *args, **kwargs)