From 7957bc45a89c62e2286d67c86a61c66b005abd6f Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 12 Apr 2018 13:45:32 +0300 Subject: [PATCH 1/3] Fixing and upgrading next step and reply handlers. + minor fixes Rename telebot package to pytelegrambotapi becouse lib named telebot exists and it raising many errors Add methods: | register_for_reply_by_message_id, | register_next_step_handler_by_chat_id, | clear_reply_handlers, | clear_reply_handlers_by_message_id --- examples/deep_linking.py | 4 +- examples/detailed_example/detailed_example.py | 6 +- examples/echo_bot.py | 4 +- examples/step_example.py | 6 +- examples/telebot_bot/telebot_bot.py | 4 +- .../webhook_aiohttp_echo_bot.py | 10 +- .../webhook_cherrypy_echo_bot.py | 10 +- .../webhook_cpython_echo_bot.py | 10 +- .../webhook_flask_echo_bot.py | 10 +- .../webhook_flask_heroku_echo.py | 6 +- .../webhook_tornado_echo_bot.py | 6 +- {telebot => pytelegrambotapi}/__init__.py | 147 +++++++++++------- {telebot => pytelegrambotapi}/apihelper.py | 8 +- {telebot => pytelegrambotapi}/types.py | 2 +- {telebot => pytelegrambotapi}/util.py | 0 tests/test_telebot.py | 112 ++++++------- tests/test_types.py | 2 +- 17 files changed, 192 insertions(+), 155 deletions(-) rename {telebot => pytelegrambotapi}/__init__.py (93%) rename {telebot => pytelegrambotapi}/apihelper.py (99%) rename {telebot => pytelegrambotapi}/types.py (99%) rename {telebot => pytelegrambotapi}/util.py (100%) diff --git a/examples/deep_linking.py b/examples/deep_linking.py index f92680f..1d6060e 100644 --- a/examples/deep_linking.py +++ b/examples/deep_linking.py @@ -30,10 +30,10 @@ # Steps 1 to 4 will have to be implemented in a web server, using a language such as PHP, Python, C# or Java. These # steps are not shown here. Only steps 5 to 7 are illustrated, some in pseudo-code, with this example. -import telebot +import pytelegrambotapi import time -bot = telebot.TeleBot('TOKEN') +bot = pytelegrambotapi.TeleBot('TOKEN') def extract_unique_code(text): # Extracts the unique_code from the sent /start command. diff --git a/examples/detailed_example/detailed_example.py b/examples/detailed_example/detailed_example.py index 8fad9af..2bafe03 100644 --- a/examples/detailed_example/detailed_example.py +++ b/examples/detailed_example/detailed_example.py @@ -2,8 +2,8 @@ This is a detailed example using almost every command of the API """ -import telebot -from telebot import types +import pytelegrambotapi +from pytelegrambotapi import types import time TOKEN = '' @@ -48,7 +48,7 @@ def listener(messages): print str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text -bot = telebot.TeleBot(TOKEN) +bot = pytelegrambotapi.TeleBot(TOKEN) bot.set_update_listener(listener) # register listener diff --git a/examples/echo_bot.py b/examples/echo_bot.py index f88d3bf..0cf4cb2 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -1,11 +1,11 @@ # This is a simple echo bot using the decorator mechanism. # It echoes any incoming text messages. -import telebot +import pytelegrambotapi API_TOKEN = '' -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) # Handle '/start' and '/help' @bot.message_handler(commands=['help', 'start']) diff --git a/examples/step_example.py b/examples/step_example.py index fd8d07d..bf7c0a9 100644 --- a/examples/step_example.py +++ b/examples/step_example.py @@ -4,12 +4,12 @@ This Example will show you how to use register_next_step handler. """ import time -import telebot -from telebot import types +import pytelegrambotapi +from pytelegrambotapi import types API_TOKEN = '' -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) user_dict = {} diff --git a/examples/telebot_bot/telebot_bot.py b/examples/telebot_bot/telebot_bot.py index cd29276..d2fbed0 100644 --- a/examples/telebot_bot/telebot_bot.py +++ b/examples/telebot_bot/telebot_bot.py @@ -3,7 +3,7 @@ # and goes by the name 'TeleBot (@pyTeleBot)'. Join our group to talk to him! # WARNING: Tested with Python 2.7 -import telebot +import pytelegrambotapi import os text_messages = { @@ -30,7 +30,7 @@ text_messages = { if "TELEBOT_BOT_TOKEN" not in os.environ or "GROUP_CHAT_ID" not in os.environ: raise AssertionError("Please configure TELEBOT_BOT_TOKEN and GROUP_CHAT_ID as environment variables") -bot = telebot.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"]) +bot = pytelegrambotapi.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"]) GROUP_CHAT_ID = int(os.environ["GROUP_CHAT_ID"]) def is_api_group(chat_id): diff --git a/examples/webhook_examples/webhook_aiohttp_echo_bot.py b/examples/webhook_examples/webhook_aiohttp_echo_bot.py index d92cff9..089366b 100644 --- a/examples/webhook_examples/webhook_aiohttp_echo_bot.py +++ b/examples/webhook_examples/webhook_aiohttp_echo_bot.py @@ -9,7 +9,7 @@ import ssl from aiohttp import web -import telebot +import pytelegrambotapi API_TOKEN = '' @@ -33,10 +33,10 @@ WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN) -logger = telebot.logger -telebot.logger.setLevel(logging.INFO) +logger = pytelegrambotapi.logger +pytelegrambotapi.logger.setLevel(logging.INFO) -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) app = web.Application() @@ -45,7 +45,7 @@ app = web.Application() async def handle(request): if request.match_info.get('token') == bot.token: request_body_dict = await request.json() - update = telebot.types.Update.de_json(request_body_dict) + update = pytelegrambotapi.types.Update.de_json(request_body_dict) bot.process_new_updates([update]) return web.Response() else: diff --git a/examples/webhook_examples/webhook_cherrypy_echo_bot.py b/examples/webhook_examples/webhook_cherrypy_echo_bot.py index d0f3da0..8d08142 100644 --- a/examples/webhook_examples/webhook_cherrypy_echo_bot.py +++ b/examples/webhook_examples/webhook_cherrypy_echo_bot.py @@ -5,7 +5,7 @@ # It echoes any incoming text messages and does not use the polling method. import cherrypy -import telebot +import pytelegrambotapi import logging @@ -30,10 +30,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) -logger = telebot.logger -telebot.logger.setLevel(logging.INFO) +logger = pytelegrambotapi.logger +pytelegrambotapi.logger.setLevel(logging.INFO) -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) # WebhookServer, process webhook calls @@ -45,7 +45,7 @@ class WebhookServer(object): cherrypy.request.headers['content-type'] == 'application/json': length = int(cherrypy.request.headers['content-length']) json_string = cherrypy.request.body.read(length).decode("utf-8") - update = telebot.types.Update.de_json(json_string) + update = pytelegrambotapi.types.Update.de_json(json_string) bot.process_new_updates([update]) return '' else: diff --git a/examples/webhook_examples/webhook_cpython_echo_bot.py b/examples/webhook_examples/webhook_cpython_echo_bot.py index 5c1dfc9..3308fe4 100644 --- a/examples/webhook_examples/webhook_cpython_echo_bot.py +++ b/examples/webhook_examples/webhook_cpython_echo_bot.py @@ -6,7 +6,7 @@ import BaseHTTPServer import ssl -import telebot +import pytelegrambotapi import logging @@ -31,10 +31,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) -logger = telebot.logger -telebot.logger.setLevel(logging.INFO) +logger = pytelegrambotapi.logger +pytelegrambotapi.logger.setLevel(logging.INFO) -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) # WebhookHandler, process webhook calls @@ -59,7 +59,7 @@ class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.send_response(200) self.end_headers() - update = telebot.types.Update.de_json(json_string) + update = pytelegrambotapi.types.Update.de_json(json_string) bot.process_new_messages([update.message]) else: self.send_error(403) diff --git a/examples/webhook_examples/webhook_flask_echo_bot.py b/examples/webhook_examples/webhook_flask_echo_bot.py index 92ffa21..e9422a2 100644 --- a/examples/webhook_examples/webhook_flask_echo_bot.py +++ b/examples/webhook_examples/webhook_flask_echo_bot.py @@ -5,7 +5,7 @@ # It echoes any incoming text messages and does not use the polling method. import flask -import telebot +import pytelegrambotapi import logging @@ -30,10 +30,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) -logger = telebot.logger -telebot.logger.setLevel(logging.INFO) +logger = pytelegrambotapi.logger +pytelegrambotapi.logger.setLevel(logging.INFO) -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) app = flask.Flask(__name__) @@ -49,7 +49,7 @@ def index(): def webhook(): if flask.request.headers.get('content-type') == 'application/json': json_string = flask.request.get_data().decode('utf-8') - update = telebot.types.Update.de_json(json_string) + update = pytelegrambotapi.types.Update.de_json(json_string) bot.process_new_updates([update]) return '' else: diff --git a/examples/webhook_examples/webhook_flask_heroku_echo.py b/examples/webhook_examples/webhook_flask_heroku_echo.py index 62d0a90..392d9e9 100644 --- a/examples/webhook_examples/webhook_flask_heroku_echo.py +++ b/examples/webhook_examples/webhook_flask_heroku_echo.py @@ -1,10 +1,10 @@ import os -import telebot +import pytelegrambotapi from flask import Flask, request TOKEN = '' -bot = telebot.TeleBot(TOKEN) +bot = pytelegrambotapi.TeleBot(TOKEN) server = Flask(__name__) @@ -20,7 +20,7 @@ def echo_message(message): @server.route('/' + TOKEN, methods=['POST']) def getMessage(): - bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))]) + bot.process_new_updates([pytelegrambotapi.types.Update.de_json(request.stream.read().decode("utf-8"))]) return "!", 200 diff --git a/examples/webhook_examples/webhook_tornado_echo_bot.py b/examples/webhook_examples/webhook_tornado_echo_bot.py index 538b7b9..b6e3a2d 100644 --- a/examples/webhook_examples/webhook_tornado_echo_bot.py +++ b/examples/webhook_examples/webhook_tornado_echo_bot.py @@ -4,7 +4,7 @@ # This example shows webhook echo bot with Tornado web framework # Documenation to Tornado: http://tornadoweb.org -import telebot +import pytelegrambotapi import tornado.web import tornado.ioloop import tornado.httpserver @@ -27,7 +27,7 @@ WEBHOOK_URL_BASE = "https://{0}:{1}/{2}".format(WEBHOOK_HOST, str(WEBHOOK_PORT), # When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply # with the same value in you put in WEBHOOK_HOST -bot = telebot.TeleBot(API_TOKEN) +bot = pytelegrambotapi.TeleBot(API_TOKEN) class Root(tornado.web.RequestHandler): def get(self): @@ -45,7 +45,7 @@ class webhook_serv(tornado.web.RequestHandler): # length = int(self.request.headers['Content-Length']) json_data = self.request.body.decode("utf-8") - update = telebot.types.Update.de_json(json_data) + update = pytelegrambotapi.types.Update.de_json(json_data) bot.process_new_updates([update]) self.write("") self.finish() diff --git a/telebot/__init__.py b/pytelegrambotapi/__init__.py similarity index 93% rename from telebot/__init__.py rename to pytelegrambotapi/__init__.py index 96e7e3d..3132e2d 100644 --- a/telebot/__init__.py +++ b/pytelegrambotapi/__init__.py @@ -20,7 +20,7 @@ logger.addHandler(console_output_handler) logger.setLevel(logging.ERROR) -from telebot import apihelper, types, util +from pytelegrambotapi import apihelper, types, util """ Module : telebot @@ -70,6 +70,7 @@ class TeleBot: :param token: bot API token :return: Telebot object. """ + self.token = token self.update_listener = [] self.skip_pending = skip_pending @@ -78,13 +79,11 @@ class TeleBot: self.last_update_id = 0 self.exc_info = None - self.message_subscribers_messages = [] - self.message_subscribers_callbacks = [] - self.message_subscribers_lock = threading.Lock() + # key: message_id, value: handler list + self.reply_handlers = {} # key: chat_id, value: handler list - self.message_subscribers_next_step = {} - self.pre_message_subscribers_next_step = {} + self.next_step_handlers = {} self.message_handlers = [] self.edited_message_handlers = [] @@ -213,11 +212,10 @@ class TeleBot: self.process_new_shipping_query(new_shipping_querys) def process_new_messages(self, new_messages): - self._append_pre_next_step_handler() + self._notify_next_handlers(new_messages) + self._notify_reply_handlers(new_messages) self.__notify_update(new_messages) self._notify_command_handlers(self.message_handlers, new_messages) - self._notify_message_subscribers(new_messages) - self._notify_message_next_handler(new_messages) def process_new_edited_messages(self, edited_message): self._notify_command_handlers(self.edited_message_handlers, edited_message) @@ -912,8 +910,8 @@ 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): + is_flexible=None, disable_notification=None, reply_to_message_id=None, reply_markup=None, + provider_data=None): 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, @@ -1050,7 +1048,7 @@ class TeleBot: """ return apihelper.delete_sticker_from_set(self.token, sticker) - def register_for_reply(self, message, callback): + def register_for_reply(self, message, callback, *args, **kwargs): """ Registers a callback function to be notified when a reply to `message` arrives. @@ -1061,40 +1059,60 @@ class TeleBot: :param callback: The callback function to be called when a reply arrives. Must accept one `message` parameter, which will contain the replied message. """ - with self.message_subscribers_lock: - self.message_subscribers_messages.insert(0, message.message_id) - self.message_subscribers_callbacks.insert(0, callback) - if len(self.message_subscribers_messages) > 10000: - self.message_subscribers_messages.pop() - self.message_subscribers_callbacks.pop() + message_id = message.message_id + self.register_for_reply_by_message_id(message_id, callback, *args, **kwargs) - def _notify_message_subscribers(self, new_messages): + def register_for_reply_by_message_id(self, message_id, callback, *args, **kwargs): + """ + Registers a callback function to be notified when a reply to `message` arrives. + + Warning: `message` must be sent with reply_markup=types.ForceReply(), otherwise TeleBot will not be able to see + the difference between a reply to `message` and an ordinary message. + + :param message: The message for which we are awaiting a reply. + :param callback: The callback function to be called when a reply arrives. Must accept one `message` + parameter, which will contain the replied message. + """ + if message_id in self.reply_handlers.keys(): + self.reply_handlers[message_id].append({"callback": callback, "args": args, "kwargs": kwargs}) + else: + self.reply_handlers[message_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] + + def _notify_reply_handlers(self, new_messages): for message in new_messages: - if not message.reply_to_message: - continue + if hasattr(message, "reply_to_message") and message.reply_to_message is not None: + reply_msg_id = message.reply_to_message.message_id + if reply_msg_id in self.reply_handlers.keys(): + handlers = self.reply_handlers[reply_msg_id] + for handler in handlers: + self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) + self.reply_handlers.pop(reply_msg_id) - reply_msg_id = message.reply_to_message.message_id - if reply_msg_id in self.message_subscribers_messages: - index = self.message_subscribers_messages.index(reply_msg_id) - self.message_subscribers_callbacks[index](message) - - with self.message_subscribers_lock: - index = self.message_subscribers_messages.index(reply_msg_id) - del self.message_subscribers_messages[index] - del self.message_subscribers_callbacks[index] - - def register_next_step_handler(self, message, callback): + def register_next_step_handler(self, message, callback, *args, **kwargs): """ Registers a callback function to be notified when new message arrives after `message`. - :param message: The message for which we want to handle new message after that in same chat. + :param message: The message for which we want to handle new message in the same chat. :param callback: The callback function which next new message arrives. + :param args: Args to pass in callback func + :param kwargs: Args to pass in callback func """ chat_id = message.chat.id - if chat_id in self.pre_message_subscribers_next_step: - self.pre_message_subscribers_next_step[chat_id].append(callback) + self.register_next_step_handler_by_chat_id(chat_id, callback, *args, **kwargs) + + def register_next_step_handler_by_chat_id(self, chat_id, callback, *args, **kwargs): + """ + Registers a callback function to be notified when new message arrives after `message`. + + :param chat_id: The chat for which we want to handle new message. + :param callback: The callback function which next new message arrives. + :param args: Args to pass in callback func + :param kwargs: Args to pass in callback func + """ + if chat_id in self.next_step_handlers.keys(): + self.next_step_handlers[chat_id].append({"callback": callback, "args": args, "kwargs": kwargs}) else: - self.pre_message_subscribers_next_step[chat_id] = [callback] + self.next_step_handlers[chat_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] def clear_step_handler(self, message): """ @@ -1103,26 +1121,48 @@ class TeleBot: :param message: The message for which we want to handle new message after that in same chat. """ chat_id = message.chat.id - self.pre_message_subscribers_next_step[chat_id] = [] + self.clear_step_handler_by_chat_id(chat_id) - def _notify_message_next_handler(self, new_messages): - for message in new_messages: + def clear_step_handler_by_chat_id(self, chat_id): + """ + Clears all callback functions registered by register_next_step_handler(). + + :param chat_id: The chat for which we want to clear next step handlers + """ + self.next_step_handlers[chat_id] = [] + + def clear_reply_handlers(self, message): + """ + Clears all callback functions registered by register_for_reply() and register_for_reply_by_message_id(). + + :param message_id: The message for which we want to clear reply handlers + """ + message_id = message.message_id + self.clear_reply_handlers_by_message_id(message_id) + + def clear_reply_handlers_by_message_id(self, message_id): + """ + Clears all callback functions registered by register_for_reply() and register_for_reply_by_message_id(). + + :param message_id: The message id for which we want to clear reply handlers + """ + self.reply_handlers[message_id] = [] + + def _notify_next_handlers(self, new_messages): + i = 0 + while i < len(new_messages): + message = new_messages[i] chat_id = message.chat.id - if chat_id in self.message_subscribers_next_step: - handlers = self.message_subscribers_next_step[chat_id] + if chat_id in self.next_step_handlers.keys(): + handlers = self.next_step_handlers[chat_id] for handler in handlers: - self._exec_task(handler, message) - self.message_subscribers_next_step.pop(chat_id, None) + self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) + self.next_step_handlers.pop(chat_id, None) + new_messages.pop(i) # removing message that detects with next_step_handler + i += 1 - def _append_pre_next_step_handler(self): - for k in self.pre_message_subscribers_next_step.keys(): - if k in self.message_subscribers_next_step: - self.message_subscribers_next_step[k].extend(self.pre_message_subscribers_next_step[k]) - else: - self.message_subscribers_next_step[k] = self.pre_message_subscribers_next_step[k] - self.pre_message_subscribers_next_step = {} - - def _build_handler_dict(self, handler, **filters): + @staticmethod + def _build_handler_dict(handler, **filters): return { 'function': handler, 'filters': filters @@ -1300,9 +1340,6 @@ class TeleBot: def _notify_command_handlers(self, handlers, new_messages): for message in new_messages: - # if message has next step handler, dont exec command handlers - if hasattr(message, 'chat') and message.chat and (message.chat.id in self.message_subscribers_next_step): - continue for message_handler in handlers: if self._test_message_handler(message_handler, message): self._exec_task(message_handler['function'], message) diff --git a/telebot/apihelper.py b/pytelegrambotapi/apihelper.py similarity index 99% rename from telebot/apihelper.py rename to pytelegrambotapi/apihelper.py index 1173aa3..53c529e 100644 --- a/telebot/apihelper.py +++ b/pytelegrambotapi/apihelper.py @@ -13,11 +13,11 @@ try: format_header_param = fields.format_header_param except ImportError: format_header_param = None -import telebot -from telebot import types -from telebot import util +import pytelegrambotapi +from pytelegrambotapi import types +from pytelegrambotapi import util -logger = telebot.logger +logger = pytelegrambotapi.logger proxy = None API_URL = "https://api.telegram.org/bot{0}/{1}" diff --git a/telebot/types.py b/pytelegrambotapi/types.py similarity index 99% rename from telebot/types.py rename to pytelegrambotapi/types.py index f996436..84340d4 100644 --- a/telebot/types.py +++ b/pytelegrambotapi/types.py @@ -7,7 +7,7 @@ except ImportError: import six -from telebot import util +from pytelegrambotapi import util class JsonSerializable: diff --git a/telebot/util.py b/pytelegrambotapi/util.py similarity index 100% rename from telebot/util.py rename to pytelegrambotapi/util.py diff --git a/tests/test_telebot.py b/tests/test_telebot.py index 6818b5b..3a16ac2 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -7,9 +7,9 @@ import time import pytest import os -import telebot -from telebot import types -from telebot import util +import pytelegrambotapi +from pytelegrambotapi import types +from pytelegrambotapi import util should_skip = 'TOKEN' and 'CHAT_ID' not in os.environ @@ -29,11 +29,11 @@ class TestTeleBot: def listener(messages): assert len(messages) == 100 - tb = telebot.TeleBot('') + tb = pytelegrambotapi.TeleBot('') tb.set_update_listener(listener) def test_message_handler(self): - tb = telebot.TeleBot('') + tb = pytelegrambotapi.TeleBot('') msg = self.create_text_message('/help') @tb.message_handler(commands=['help', 'start']) @@ -45,7 +45,7 @@ class TestTeleBot: assert msg.text == 'got' def test_message_handler_reg(self): - bot = telebot.TeleBot('') + bot = pytelegrambotapi.TeleBot('') msg = self.create_text_message(r'https://web.telegram.org/') @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') @@ -57,7 +57,7 @@ class TestTeleBot: assert msg.text == 'got' def test_message_handler_lambda(self): - bot = telebot.TeleBot('') + bot = pytelegrambotapi.TeleBot('') msg = self.create_text_message(r'lambda_text') @bot.message_handler(func=lambda message: r'lambda' in message.text) @@ -69,7 +69,7 @@ class TestTeleBot: assert msg.text == 'got' def test_message_handler_lambda_fail(self): - bot = telebot.TeleBot('') + bot = pytelegrambotapi.TeleBot('') msg = self.create_text_message(r'text') @bot.message_handler(func=lambda message: r'lambda' in message.text) @@ -81,7 +81,7 @@ class TestTeleBot: assert not msg.text == 'got' def test_message_handler_reg_fail(self): - bot = telebot.TeleBot('') + bot = pytelegrambotapi.TeleBot('') msg = self.create_text_message(r'web.telegram.org/') @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') @@ -93,7 +93,7 @@ class TestTeleBot: assert not msg.text == 'got' def test_send_message_with_markdown(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) markdown = """ *bold text* _italic text_ @@ -103,7 +103,7 @@ class TestTeleBot: assert ret_msg.message_id def test_send_message_with_disable_notification(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) markdown = """ *bold text* _italic text_ @@ -114,7 +114,7 @@ class TestTeleBot: def test_send_file(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data) assert ret_msg.message_id @@ -123,7 +123,7 @@ class TestTeleBot: def test_send_file_dis_noti(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, disable_notification=True) assert ret_msg.message_id @@ -132,7 +132,7 @@ class TestTeleBot: def test_send_file_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, caption="Test") assert ret_msg.message_id @@ -141,30 +141,30 @@ class TestTeleBot: def test_send_video(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data) assert ret_msg.message_id def test_send_video_dis_noti(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, disable_notification=True) assert ret_msg.message_id def test_send_video_more_params(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, 1) assert ret_msg.message_id def test_send_video_more_params_dis_noti(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, 1, disable_notification=True) assert ret_msg.message_id def test_send_file_exception(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) try: tb.send_document(CHAT_ID, None) assert False @@ -174,7 +174,7 @@ class TestTeleBot: def test_send_photo(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data) assert ret_msg.message_id @@ -183,7 +183,7 @@ class TestTeleBot: def test_send_photo_dis_noti(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data) assert ret_msg.message_id @@ -192,7 +192,7 @@ class TestTeleBot: def test_send_audio(self): file_data = open('./test_data/record.mp3', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram') assert ret_msg.content_type == 'audio' assert ret_msg.audio.performer == 'eternnoir' @@ -200,7 +200,7 @@ class TestTeleBot: def test_send_audio_dis_noti(self): file_data = open('./test_data/record.mp3', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram', disable_notification=True) assert ret_msg.content_type == 'audio' @@ -209,19 +209,19 @@ class TestTeleBot: def test_send_voice(self): file_data = open('./test_data/record.ogg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data) assert ret_msg.voice.mime_type == 'audio/ogg' def test_send_voice_dis_noti(self): file_data = open('./test_data/record.ogg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True) assert ret_msg.voice.mime_type == 'audio/ogg' def test_get_file(self): file_data = open('./test_data/record.ogg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data) file_id = ret_msg.voice.file_id file_info = tb.get_file(file_id) @@ -229,7 +229,7 @@ class TestTeleBot: def test_get_file_dis_noti(self): file_data = open('./test_data/record.ogg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True) file_id = ret_msg.voice.file_id file_info = tb.get_file(file_id) @@ -237,19 +237,19 @@ class TestTeleBot: def test_send_message(self): text = 'CI Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_message(CHAT_ID, text) assert ret_msg.message_id def test_send_message_dis_noti(self): text = 'CI Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True) assert ret_msg.message_id def test_send_message_with_markup(self): text = 'CI Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) markup = types.ReplyKeyboardMarkup() markup.add(types.KeyboardButton("1")) markup.add(types.KeyboardButton("2")) @@ -258,7 +258,7 @@ class TestTeleBot: def test_send_message_with_markup_use_string(self): text = 'CI Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) markup = types.ReplyKeyboardMarkup() markup.add("1") markup.add("2") @@ -269,7 +269,7 @@ class TestTeleBot: def test_send_message_with_inlinemarkup(self): text = 'CI Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) @@ -278,28 +278,28 @@ class TestTeleBot: def test_forward_message(self): text = 'CI forward_message Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id) assert ret_msg.forward_from def test_forward_message_dis_noti(self): text = 'CI forward_message Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id, disable_notification=True) assert ret_msg.forward_from def test_reply_to(self): text = 'CI reply_to Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.reply_to(msg, text + ' REPLY') assert ret_msg.reply_to_message.message_id == msg.message_id def test_register_for_reply(self): text = 'CI reply_to Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text, reply_markup=types.ForceReply()) reply_msg = tb.reply_to(msg, text + ' REPLY') @@ -311,7 +311,7 @@ class TestTeleBot: tb.process_new_messages([reply_msg]) def test_send_location(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_location(CHAT_ID, lat, lon) @@ -319,7 +319,7 @@ class TestTeleBot: assert int(ret_msg.location.latitude) == int(lat) def test_send_location_dis_noti(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_location(CHAT_ID, lat, lon, disable_notification=True) @@ -327,7 +327,7 @@ class TestTeleBot: assert int(ret_msg.location.latitude) == int(lat) def test_send_venue(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address") @@ -335,50 +335,50 @@ class TestTeleBot: assert int(lat) == int(ret_msg.venue.location.latitude) def test_send_venue_dis_noti(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address", disable_notification=True) assert ret_msg.venue.title == "Test Venue" def test_Chat(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) me = tb.get_me() msg = tb.send_message(CHAT_ID, 'Test') assert me.id == msg.from_user.id assert msg.chat.id == int(CHAT_ID) def test_edit_message_text(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, 'Test') new_msg = tb.edit_message_text('Edit test', chat_id=CHAT_ID, message_id=msg.message_id) assert new_msg.text == 'Edit test' def test_edit_message_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) msg = tb.send_document(CHAT_ID, file_data, caption="Test") new_msg = tb.edit_message_caption(caption='Edit test', chat_id=CHAT_ID, message_id=msg.message_id) assert new_msg.caption == 'Edit test' def test_get_chat(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ch = tb.get_chat(GROUP_ID) assert str(ch.id) == GROUP_ID def test_get_chat_administrators(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) cas = tb.get_chat_administrators(GROUP_ID) assert len(cas) > 0 def test_get_chat_members_count(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) cn = tb.get_chat_members_count(GROUP_ID) assert cn > 1 def test_edit_markup(self): text = 'CI Test Message' - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) @@ -407,12 +407,12 @@ class TestTeleBot: def test_send_video_note(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_video_note(CHAT_ID, file_data) assert ret_msg.message_id def test_send_media_group(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) img1 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png' medias = [types.InputMediaPhoto(img1, "View"), types.InputMediaPhoto(img2, "Dog")] @@ -424,7 +424,7 @@ class TestTeleBot: def test_send_media_group_local_files(self): photo = open('../examples/detailed_example/kitten.jpg', 'rb') video = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) medias = [types.InputMediaPhoto(photo, "View"), types.InputMediaVideo(video)] result = tb.send_media_group(CHAT_ID, medias) @@ -434,31 +434,31 @@ class TestTeleBot: def test_send_photo_formating_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic' def test_send_video_formatting_caption(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic' def test_send_audio_formatting_caption(self): file_data = open('./test_data/record.mp3', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, caption='bold', parse_mode='HTML') assert ret_msg.caption_entities[0].type == 'bold' def test_send_voice_formatting_caprion(self): file_data = open('./test_data/record.ogg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data, caption='bold', parse_mode='HTML') assert ret_msg.caption_entities[0].type == 'bold' assert ret_msg.voice.mime_type == 'audio/ogg' def test_send_media_group_formatting_caption(self): - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) img1 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png' medias = [types.InputMediaPhoto(img1, "*View*", parse_mode='Markdown'), @@ -471,6 +471,6 @@ class TestTeleBot: def test_send_document_formating_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = telebot.TeleBot(TOKEN) + tb = pytelegrambotapi.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic' diff --git a/tests/test_types.py b/tests/test_types.py index c174d42..8744943 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -2,7 +2,7 @@ import sys sys.path.append('../') -from telebot import types +from pytelegrambotapi import types def test_json_user(): From 183230e92711f4feb95d1d779fe0511ce0a1144c Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 12 Apr 2018 17:24:04 +0300 Subject: [PATCH 2/3] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1c5529a..e95e6d9 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup(name='pyTelegramBotAPI', author='eternnoir', author_email='eternnoir@gmail.com', url='https://github.com/eternnoir/pyTelegramBotAPI', - packages=['telebot'], + packages=['pytelegrambotapi'], license='GPL2', keywords='telegram bot api tools', install_requires=['requests', 'six'], From 3ba9799b98d11a16c99e5f10e627b71ddebff65d Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 28 Apr 2018 13:50:59 +0300 Subject: [PATCH 3/3] Renaming back pytelegrambotapi module to telebot --- examples/deep_linking.py | 4 +- examples/detailed_example/detailed_example.py | 6 +- examples/echo_bot.py | 4 +- examples/step_example.py | 6 +- examples/telebot_bot/telebot_bot.py | 4 +- .../webhook_aiohttp_echo_bot.py | 10 +- .../webhook_cherrypy_echo_bot.py | 10 +- .../webhook_cpython_echo_bot.py | 10 +- .../webhook_flask_echo_bot.py | 10 +- .../webhook_flask_heroku_echo.py | 6 +- .../webhook_tornado_echo_bot.py | 6 +- setup.py | 2 +- {pytelegrambotapi => telebot}/__init__.py | 2 +- {pytelegrambotapi => telebot}/apihelper.py | 8 +- {pytelegrambotapi => telebot}/types.py | 2 +- {pytelegrambotapi => telebot}/util.py | 0 tests/test_telebot.py | 112 +++++++++--------- tests/test_types.py | 2 +- 18 files changed, 102 insertions(+), 102 deletions(-) rename {pytelegrambotapi => telebot}/__init__.py (99%) rename {pytelegrambotapi => telebot}/apihelper.py (99%) rename {pytelegrambotapi => telebot}/types.py (99%) rename {pytelegrambotapi => telebot}/util.py (100%) diff --git a/examples/deep_linking.py b/examples/deep_linking.py index 1d6060e..f92680f 100644 --- a/examples/deep_linking.py +++ b/examples/deep_linking.py @@ -30,10 +30,10 @@ # Steps 1 to 4 will have to be implemented in a web server, using a language such as PHP, Python, C# or Java. These # steps are not shown here. Only steps 5 to 7 are illustrated, some in pseudo-code, with this example. -import pytelegrambotapi +import telebot import time -bot = pytelegrambotapi.TeleBot('TOKEN') +bot = telebot.TeleBot('TOKEN') def extract_unique_code(text): # Extracts the unique_code from the sent /start command. diff --git a/examples/detailed_example/detailed_example.py b/examples/detailed_example/detailed_example.py index 2bafe03..8fad9af 100644 --- a/examples/detailed_example/detailed_example.py +++ b/examples/detailed_example/detailed_example.py @@ -2,8 +2,8 @@ This is a detailed example using almost every command of the API """ -import pytelegrambotapi -from pytelegrambotapi import types +import telebot +from telebot import types import time TOKEN = '' @@ -48,7 +48,7 @@ def listener(messages): print str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text -bot = pytelegrambotapi.TeleBot(TOKEN) +bot = telebot.TeleBot(TOKEN) bot.set_update_listener(listener) # register listener diff --git a/examples/echo_bot.py b/examples/echo_bot.py index 0cf4cb2..f88d3bf 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -1,11 +1,11 @@ # This is a simple echo bot using the decorator mechanism. # It echoes any incoming text messages. -import pytelegrambotapi +import telebot API_TOKEN = '' -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) # Handle '/start' and '/help' @bot.message_handler(commands=['help', 'start']) diff --git a/examples/step_example.py b/examples/step_example.py index bf7c0a9..fd8d07d 100644 --- a/examples/step_example.py +++ b/examples/step_example.py @@ -4,12 +4,12 @@ This Example will show you how to use register_next_step handler. """ import time -import pytelegrambotapi -from pytelegrambotapi import types +import telebot +from telebot import types API_TOKEN = '' -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) user_dict = {} diff --git a/examples/telebot_bot/telebot_bot.py b/examples/telebot_bot/telebot_bot.py index d2fbed0..cd29276 100644 --- a/examples/telebot_bot/telebot_bot.py +++ b/examples/telebot_bot/telebot_bot.py @@ -3,7 +3,7 @@ # and goes by the name 'TeleBot (@pyTeleBot)'. Join our group to talk to him! # WARNING: Tested with Python 2.7 -import pytelegrambotapi +import telebot import os text_messages = { @@ -30,7 +30,7 @@ text_messages = { if "TELEBOT_BOT_TOKEN" not in os.environ or "GROUP_CHAT_ID" not in os.environ: raise AssertionError("Please configure TELEBOT_BOT_TOKEN and GROUP_CHAT_ID as environment variables") -bot = pytelegrambotapi.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"]) +bot = telebot.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"]) GROUP_CHAT_ID = int(os.environ["GROUP_CHAT_ID"]) def is_api_group(chat_id): diff --git a/examples/webhook_examples/webhook_aiohttp_echo_bot.py b/examples/webhook_examples/webhook_aiohttp_echo_bot.py index 089366b..d92cff9 100644 --- a/examples/webhook_examples/webhook_aiohttp_echo_bot.py +++ b/examples/webhook_examples/webhook_aiohttp_echo_bot.py @@ -9,7 +9,7 @@ import ssl from aiohttp import web -import pytelegrambotapi +import telebot API_TOKEN = '' @@ -33,10 +33,10 @@ WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN) -logger = pytelegrambotapi.logger -pytelegrambotapi.logger.setLevel(logging.INFO) +logger = telebot.logger +telebot.logger.setLevel(logging.INFO) -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) app = web.Application() @@ -45,7 +45,7 @@ app = web.Application() async def handle(request): if request.match_info.get('token') == bot.token: request_body_dict = await request.json() - update = pytelegrambotapi.types.Update.de_json(request_body_dict) + update = telebot.types.Update.de_json(request_body_dict) bot.process_new_updates([update]) return web.Response() else: diff --git a/examples/webhook_examples/webhook_cherrypy_echo_bot.py b/examples/webhook_examples/webhook_cherrypy_echo_bot.py index 8d08142..d0f3da0 100644 --- a/examples/webhook_examples/webhook_cherrypy_echo_bot.py +++ b/examples/webhook_examples/webhook_cherrypy_echo_bot.py @@ -5,7 +5,7 @@ # It echoes any incoming text messages and does not use the polling method. import cherrypy -import pytelegrambotapi +import telebot import logging @@ -30,10 +30,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) -logger = pytelegrambotapi.logger -pytelegrambotapi.logger.setLevel(logging.INFO) +logger = telebot.logger +telebot.logger.setLevel(logging.INFO) -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) # WebhookServer, process webhook calls @@ -45,7 +45,7 @@ class WebhookServer(object): cherrypy.request.headers['content-type'] == 'application/json': length = int(cherrypy.request.headers['content-length']) json_string = cherrypy.request.body.read(length).decode("utf-8") - update = pytelegrambotapi.types.Update.de_json(json_string) + update = telebot.types.Update.de_json(json_string) bot.process_new_updates([update]) return '' else: diff --git a/examples/webhook_examples/webhook_cpython_echo_bot.py b/examples/webhook_examples/webhook_cpython_echo_bot.py index 3308fe4..5c1dfc9 100644 --- a/examples/webhook_examples/webhook_cpython_echo_bot.py +++ b/examples/webhook_examples/webhook_cpython_echo_bot.py @@ -6,7 +6,7 @@ import BaseHTTPServer import ssl -import pytelegrambotapi +import telebot import logging @@ -31,10 +31,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) -logger = pytelegrambotapi.logger -pytelegrambotapi.logger.setLevel(logging.INFO) +logger = telebot.logger +telebot.logger.setLevel(logging.INFO) -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) # WebhookHandler, process webhook calls @@ -59,7 +59,7 @@ class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.send_response(200) self.end_headers() - update = pytelegrambotapi.types.Update.de_json(json_string) + update = telebot.types.Update.de_json(json_string) bot.process_new_messages([update.message]) else: self.send_error(403) diff --git a/examples/webhook_examples/webhook_flask_echo_bot.py b/examples/webhook_examples/webhook_flask_echo_bot.py index e9422a2..92ffa21 100644 --- a/examples/webhook_examples/webhook_flask_echo_bot.py +++ b/examples/webhook_examples/webhook_flask_echo_bot.py @@ -5,7 +5,7 @@ # It echoes any incoming text messages and does not use the polling method. import flask -import pytelegrambotapi +import telebot import logging @@ -30,10 +30,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) -logger = pytelegrambotapi.logger -pytelegrambotapi.logger.setLevel(logging.INFO) +logger = telebot.logger +telebot.logger.setLevel(logging.INFO) -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) app = flask.Flask(__name__) @@ -49,7 +49,7 @@ def index(): def webhook(): if flask.request.headers.get('content-type') == 'application/json': json_string = flask.request.get_data().decode('utf-8') - update = pytelegrambotapi.types.Update.de_json(json_string) + update = telebot.types.Update.de_json(json_string) bot.process_new_updates([update]) return '' else: diff --git a/examples/webhook_examples/webhook_flask_heroku_echo.py b/examples/webhook_examples/webhook_flask_heroku_echo.py index 392d9e9..62d0a90 100644 --- a/examples/webhook_examples/webhook_flask_heroku_echo.py +++ b/examples/webhook_examples/webhook_flask_heroku_echo.py @@ -1,10 +1,10 @@ import os -import pytelegrambotapi +import telebot from flask import Flask, request TOKEN = '' -bot = pytelegrambotapi.TeleBot(TOKEN) +bot = telebot.TeleBot(TOKEN) server = Flask(__name__) @@ -20,7 +20,7 @@ def echo_message(message): @server.route('/' + TOKEN, methods=['POST']) def getMessage(): - bot.process_new_updates([pytelegrambotapi.types.Update.de_json(request.stream.read().decode("utf-8"))]) + bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))]) return "!", 200 diff --git a/examples/webhook_examples/webhook_tornado_echo_bot.py b/examples/webhook_examples/webhook_tornado_echo_bot.py index b6e3a2d..538b7b9 100644 --- a/examples/webhook_examples/webhook_tornado_echo_bot.py +++ b/examples/webhook_examples/webhook_tornado_echo_bot.py @@ -4,7 +4,7 @@ # This example shows webhook echo bot with Tornado web framework # Documenation to Tornado: http://tornadoweb.org -import pytelegrambotapi +import telebot import tornado.web import tornado.ioloop import tornado.httpserver @@ -27,7 +27,7 @@ WEBHOOK_URL_BASE = "https://{0}:{1}/{2}".format(WEBHOOK_HOST, str(WEBHOOK_PORT), # When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply # with the same value in you put in WEBHOOK_HOST -bot = pytelegrambotapi.TeleBot(API_TOKEN) +bot = telebot.TeleBot(API_TOKEN) class Root(tornado.web.RequestHandler): def get(self): @@ -45,7 +45,7 @@ class webhook_serv(tornado.web.RequestHandler): # length = int(self.request.headers['Content-Length']) json_data = self.request.body.decode("utf-8") - update = pytelegrambotapi.types.Update.de_json(json_data) + update = telebot.types.Update.de_json(json_data) bot.process_new_updates([update]) self.write("") self.finish() diff --git a/setup.py b/setup.py index e95e6d9..1c5529a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup(name='pyTelegramBotAPI', author='eternnoir', author_email='eternnoir@gmail.com', url='https://github.com/eternnoir/pyTelegramBotAPI', - packages=['pytelegrambotapi'], + packages=['telebot'], license='GPL2', keywords='telegram bot api tools', install_requires=['requests', 'six'], diff --git a/pytelegrambotapi/__init__.py b/telebot/__init__.py similarity index 99% rename from pytelegrambotapi/__init__.py rename to telebot/__init__.py index 3132e2d..8f9b60b 100644 --- a/pytelegrambotapi/__init__.py +++ b/telebot/__init__.py @@ -20,7 +20,7 @@ logger.addHandler(console_output_handler) logger.setLevel(logging.ERROR) -from pytelegrambotapi import apihelper, types, util +from telebot import apihelper, types, util """ Module : telebot diff --git a/pytelegrambotapi/apihelper.py b/telebot/apihelper.py similarity index 99% rename from pytelegrambotapi/apihelper.py rename to telebot/apihelper.py index 53c529e..1173aa3 100644 --- a/pytelegrambotapi/apihelper.py +++ b/telebot/apihelper.py @@ -13,11 +13,11 @@ try: format_header_param = fields.format_header_param except ImportError: format_header_param = None -import pytelegrambotapi -from pytelegrambotapi import types -from pytelegrambotapi import util +import telebot +from telebot import types +from telebot import util -logger = pytelegrambotapi.logger +logger = telebot.logger proxy = None API_URL = "https://api.telegram.org/bot{0}/{1}" diff --git a/pytelegrambotapi/types.py b/telebot/types.py similarity index 99% rename from pytelegrambotapi/types.py rename to telebot/types.py index 84340d4..f996436 100644 --- a/pytelegrambotapi/types.py +++ b/telebot/types.py @@ -7,7 +7,7 @@ except ImportError: import six -from pytelegrambotapi import util +from telebot import util class JsonSerializable: diff --git a/pytelegrambotapi/util.py b/telebot/util.py similarity index 100% rename from pytelegrambotapi/util.py rename to telebot/util.py diff --git a/tests/test_telebot.py b/tests/test_telebot.py index 3a16ac2..6818b5b 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -7,9 +7,9 @@ import time import pytest import os -import pytelegrambotapi -from pytelegrambotapi import types -from pytelegrambotapi import util +import telebot +from telebot import types +from telebot import util should_skip = 'TOKEN' and 'CHAT_ID' not in os.environ @@ -29,11 +29,11 @@ class TestTeleBot: def listener(messages): assert len(messages) == 100 - tb = pytelegrambotapi.TeleBot('') + tb = telebot.TeleBot('') tb.set_update_listener(listener) def test_message_handler(self): - tb = pytelegrambotapi.TeleBot('') + tb = telebot.TeleBot('') msg = self.create_text_message('/help') @tb.message_handler(commands=['help', 'start']) @@ -45,7 +45,7 @@ class TestTeleBot: assert msg.text == 'got' def test_message_handler_reg(self): - bot = pytelegrambotapi.TeleBot('') + bot = telebot.TeleBot('') msg = self.create_text_message(r'https://web.telegram.org/') @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') @@ -57,7 +57,7 @@ class TestTeleBot: assert msg.text == 'got' def test_message_handler_lambda(self): - bot = pytelegrambotapi.TeleBot('') + bot = telebot.TeleBot('') msg = self.create_text_message(r'lambda_text') @bot.message_handler(func=lambda message: r'lambda' in message.text) @@ -69,7 +69,7 @@ class TestTeleBot: assert msg.text == 'got' def test_message_handler_lambda_fail(self): - bot = pytelegrambotapi.TeleBot('') + bot = telebot.TeleBot('') msg = self.create_text_message(r'text') @bot.message_handler(func=lambda message: r'lambda' in message.text) @@ -81,7 +81,7 @@ class TestTeleBot: assert not msg.text == 'got' def test_message_handler_reg_fail(self): - bot = pytelegrambotapi.TeleBot('') + bot = telebot.TeleBot('') msg = self.create_text_message(r'web.telegram.org/') @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') @@ -93,7 +93,7 @@ class TestTeleBot: assert not msg.text == 'got' def test_send_message_with_markdown(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) markdown = """ *bold text* _italic text_ @@ -103,7 +103,7 @@ class TestTeleBot: assert ret_msg.message_id def test_send_message_with_disable_notification(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) markdown = """ *bold text* _italic text_ @@ -114,7 +114,7 @@ class TestTeleBot: def test_send_file(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data) assert ret_msg.message_id @@ -123,7 +123,7 @@ class TestTeleBot: def test_send_file_dis_noti(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, disable_notification=True) assert ret_msg.message_id @@ -132,7 +132,7 @@ class TestTeleBot: def test_send_file_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, caption="Test") assert ret_msg.message_id @@ -141,30 +141,30 @@ class TestTeleBot: def test_send_video(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data) assert ret_msg.message_id def test_send_video_dis_noti(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, disable_notification=True) assert ret_msg.message_id def test_send_video_more_params(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, 1) assert ret_msg.message_id def test_send_video_more_params_dis_noti(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, 1, disable_notification=True) assert ret_msg.message_id def test_send_file_exception(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) try: tb.send_document(CHAT_ID, None) assert False @@ -174,7 +174,7 @@ class TestTeleBot: def test_send_photo(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data) assert ret_msg.message_id @@ -183,7 +183,7 @@ class TestTeleBot: def test_send_photo_dis_noti(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data) assert ret_msg.message_id @@ -192,7 +192,7 @@ class TestTeleBot: def test_send_audio(self): file_data = open('./test_data/record.mp3', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram') assert ret_msg.content_type == 'audio' assert ret_msg.audio.performer == 'eternnoir' @@ -200,7 +200,7 @@ class TestTeleBot: def test_send_audio_dis_noti(self): file_data = open('./test_data/record.mp3', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram', disable_notification=True) assert ret_msg.content_type == 'audio' @@ -209,19 +209,19 @@ class TestTeleBot: def test_send_voice(self): file_data = open('./test_data/record.ogg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data) assert ret_msg.voice.mime_type == 'audio/ogg' def test_send_voice_dis_noti(self): file_data = open('./test_data/record.ogg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True) assert ret_msg.voice.mime_type == 'audio/ogg' def test_get_file(self): file_data = open('./test_data/record.ogg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data) file_id = ret_msg.voice.file_id file_info = tb.get_file(file_id) @@ -229,7 +229,7 @@ class TestTeleBot: def test_get_file_dis_noti(self): file_data = open('./test_data/record.ogg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True) file_id = ret_msg.voice.file_id file_info = tb.get_file(file_id) @@ -237,19 +237,19 @@ class TestTeleBot: def test_send_message(self): text = 'CI Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_message(CHAT_ID, text) assert ret_msg.message_id def test_send_message_dis_noti(self): text = 'CI Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True) assert ret_msg.message_id def test_send_message_with_markup(self): text = 'CI Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) markup = types.ReplyKeyboardMarkup() markup.add(types.KeyboardButton("1")) markup.add(types.KeyboardButton("2")) @@ -258,7 +258,7 @@ class TestTeleBot: def test_send_message_with_markup_use_string(self): text = 'CI Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) markup = types.ReplyKeyboardMarkup() markup.add("1") markup.add("2") @@ -269,7 +269,7 @@ class TestTeleBot: def test_send_message_with_inlinemarkup(self): text = 'CI Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) @@ -278,28 +278,28 @@ class TestTeleBot: def test_forward_message(self): text = 'CI forward_message Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id) assert ret_msg.forward_from def test_forward_message_dis_noti(self): text = 'CI forward_message Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id, disable_notification=True) assert ret_msg.forward_from def test_reply_to(self): text = 'CI reply_to Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.reply_to(msg, text + ' REPLY') assert ret_msg.reply_to_message.message_id == msg.message_id def test_register_for_reply(self): text = 'CI reply_to Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text, reply_markup=types.ForceReply()) reply_msg = tb.reply_to(msg, text + ' REPLY') @@ -311,7 +311,7 @@ class TestTeleBot: tb.process_new_messages([reply_msg]) def test_send_location(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_location(CHAT_ID, lat, lon) @@ -319,7 +319,7 @@ class TestTeleBot: assert int(ret_msg.location.latitude) == int(lat) def test_send_location_dis_noti(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_location(CHAT_ID, lat, lon, disable_notification=True) @@ -327,7 +327,7 @@ class TestTeleBot: assert int(ret_msg.location.latitude) == int(lat) def test_send_venue(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address") @@ -335,50 +335,50 @@ class TestTeleBot: assert int(lat) == int(ret_msg.venue.location.latitude) def test_send_venue_dis_noti(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address", disable_notification=True) assert ret_msg.venue.title == "Test Venue" def test_Chat(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) me = tb.get_me() msg = tb.send_message(CHAT_ID, 'Test') assert me.id == msg.from_user.id assert msg.chat.id == int(CHAT_ID) def test_edit_message_text(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, 'Test') new_msg = tb.edit_message_text('Edit test', chat_id=CHAT_ID, message_id=msg.message_id) assert new_msg.text == 'Edit test' def test_edit_message_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) msg = tb.send_document(CHAT_ID, file_data, caption="Test") new_msg = tb.edit_message_caption(caption='Edit test', chat_id=CHAT_ID, message_id=msg.message_id) assert new_msg.caption == 'Edit test' def test_get_chat(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ch = tb.get_chat(GROUP_ID) assert str(ch.id) == GROUP_ID def test_get_chat_administrators(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) cas = tb.get_chat_administrators(GROUP_ID) assert len(cas) > 0 def test_get_chat_members_count(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) cn = tb.get_chat_members_count(GROUP_ID) assert cn > 1 def test_edit_markup(self): text = 'CI Test Message' - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) @@ -407,12 +407,12 @@ class TestTeleBot: def test_send_video_note(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video_note(CHAT_ID, file_data) assert ret_msg.message_id def test_send_media_group(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) img1 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png' medias = [types.InputMediaPhoto(img1, "View"), types.InputMediaPhoto(img2, "Dog")] @@ -424,7 +424,7 @@ class TestTeleBot: def test_send_media_group_local_files(self): photo = open('../examples/detailed_example/kitten.jpg', 'rb') video = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) medias = [types.InputMediaPhoto(photo, "View"), types.InputMediaVideo(video)] result = tb.send_media_group(CHAT_ID, medias) @@ -434,31 +434,31 @@ class TestTeleBot: def test_send_photo_formating_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic' def test_send_video_formatting_caption(self): file_data = open('./test_data/test_video.mp4', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic' def test_send_audio_formatting_caption(self): file_data = open('./test_data/record.mp3', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, caption='bold', parse_mode='HTML') assert ret_msg.caption_entities[0].type == 'bold' def test_send_voice_formatting_caprion(self): file_data = open('./test_data/record.ogg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_voice(CHAT_ID, file_data, caption='bold', parse_mode='HTML') assert ret_msg.caption_entities[0].type == 'bold' assert ret_msg.voice.mime_type == 'audio/ogg' def test_send_media_group_formatting_caption(self): - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) img1 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png' medias = [types.InputMediaPhoto(img1, "*View*", parse_mode='Markdown'), @@ -471,6 +471,6 @@ class TestTeleBot: def test_send_document_formating_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') - tb = pytelegrambotapi.TeleBot(TOKEN) + tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic' diff --git a/tests/test_types.py b/tests/test_types.py index 8744943..c174d42 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -2,7 +2,7 @@ import sys sys.path.append('../') -from pytelegrambotapi import types +from telebot import types def test_json_user():