diff --git a/README.rst b/README.rst index 1cf2765d..09072c81 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ AIOGramBot :target: https://pypi.python.org/pypi/aiogram :alt: Supported python versions -.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-4.9-blue.svg?style=flat-square&logo=telegram +.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.0-blue.svg?style=flat-square&logo=telegram :target: https://core.telegram.org/bots/api :alt: Telegram Bot API diff --git a/docs/source/examples/advanced_executor_example.rst b/docs/source/examples/advanced_executor_example.rst index 9eb5d950..a824ebaf 100644 --- a/docs/source/examples/advanced_executor_example.rst +++ b/docs/source/examples/advanced_executor_example.rst @@ -1,28 +1,8 @@ -.. Autogenerated file at 2018-10-28 19:31:48.335963 - ========================= Advanced executor example ========================= -!/usr/bin/env python3 -**This example is outdated** -In this example used ArgumentParser for configuring Your bot. -Provided to start bot with webhook: -python advanced_executor_example.py \ ---token TOKEN_HERE \ ---host 0.0.0.0 \ ---port 8084 \ ---host-name example.com \ ---webhook-port 443 -Or long polling: -python advanced_executor_example.py --token TOKEN_HERE -So... In this example found small trouble: -can't get bot instance in handlers. -If you want to automatic change getting updates method use executor utils (from aiogram.utils.executor) - TODO: Move token to environment variables. - .. literalinclude:: ../../../examples/advanced_executor_example.py :caption: advanced_executor_example.py :language: python :linenos: - :lines: 25- diff --git a/docs/source/examples/broadcast_example.rst b/docs/source/examples/broadcast_example.rst index 97556e73..837ad02f 100644 --- a/docs/source/examples/broadcast_example.rst +++ b/docs/source/examples/broadcast_example.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.593501 - ================= Broadcast example ================= diff --git a/docs/source/examples/check_user_language.rst b/docs/source/examples/check_user_language.rst index 0fc2d90e..5d859d43 100644 --- a/docs/source/examples/check_user_language.rst +++ b/docs/source/examples/check_user_language.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.558059 - =================== Check user language =================== @@ -10,4 +8,3 @@ Babel is required. :caption: check_user_language.py :language: python :linenos: - :lines: 5- diff --git a/docs/source/examples/echo_bot.rst b/docs/source/examples/echo_bot.rst index 18c45569..dfbecce1 100644 --- a/docs/source/examples/echo_bot.rst +++ b/docs/source/examples/echo_bot.rst @@ -1,8 +1,7 @@ +======== Echo bot ======== -Very simple example of the bot which will sent text of the received messages to the sender - .. literalinclude:: ../../../examples/echo_bot.py :caption: echo_bot.py :language: python diff --git a/docs/source/examples/finite_state_machine_example.rst b/docs/source/examples/finite_state_machine_example.rst index 3eea4a22..29e251b8 100644 --- a/docs/source/examples/finite_state_machine_example.rst +++ b/docs/source/examples/finite_state_machine_example.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.595032 - ============================ Finite state machine example ============================ diff --git a/docs/source/examples/i18n_example.rst b/docs/source/examples/i18n_example.rst index 875006be..dc794619 100644 --- a/docs/source/examples/i18n_example.rst +++ b/docs/source/examples/i18n_example.rst @@ -1,28 +1,8 @@ -.. Autogenerated file at 2018-09-08 02:07:37.591007 - ============ I18n example ============ -Internalize your bot -Step 1: extract texts -# pybabel extract i18n_example.py -o locales/mybot.pot -Step 2: create *.po files. For e.g. create en, ru, uk locales. -# echo {en,ru,uk} | xargs -n1 pybabel init -i locales/mybot.pot -d locales -D mybot -l -Step 3: translate texts -Step 4: compile translations -# pybabel compile -d locales -D mybot -Step 5: When you change the code of your bot you need to update po & mo files. -Step 5.1: regenerate pot file: -command from step 1 -Step 5.2: update po files -# pybabel update -d locales -D mybot -i locales/mybot.pot -Step 5.3: update your translations -Step 5.4: compile mo files -command from step 4 - .. literalinclude:: ../../../examples/i18n_example.py :caption: i18n_example.py :language: python :linenos: - :lines: 22- diff --git a/docs/source/examples/index.rst b/docs/source/examples/index.rst index 2bedaa52..c5be4bfc 100644 --- a/docs/source/examples/index.rst +++ b/docs/source/examples/index.rst @@ -19,3 +19,4 @@ Examples payments broadcast_example media_group + local_server diff --git a/docs/source/examples/inline_bot.rst b/docs/source/examples/inline_bot.rst index b6059974..ca3d227c 100644 --- a/docs/source/examples/inline_bot.rst +++ b/docs/source/examples/inline_bot.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.561907 - ========== Inline bot ========== diff --git a/docs/source/examples/local_server.rst b/docs/source/examples/local_server.rst new file mode 100644 index 00000000..6e056a6f --- /dev/null +++ b/docs/source/examples/local_server.rst @@ -0,0 +1,8 @@ +============ +Local server +============ + +.. literalinclude:: ../../../examples/local_server.py + :caption: local_server.py + :language: python + :linenos: diff --git a/docs/source/examples/media_group.rst b/docs/source/examples/media_group.rst index ebf2d3f2..1eb12e4f 100644 --- a/docs/source/examples/media_group.rst +++ b/docs/source/examples/media_group.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.566615 - =========== Media group =========== diff --git a/docs/source/examples/middleware_and_antiflood.rst b/docs/source/examples/middleware_and_antiflood.rst index 4f634c93..ce9e99db 100644 --- a/docs/source/examples/middleware_and_antiflood.rst +++ b/docs/source/examples/middleware_and_antiflood.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.560132 - ======================== Middleware and antiflood ======================== diff --git a/docs/source/examples/payments.rst b/docs/source/examples/payments.rst index 7b634ce7..f663c8ee 100644 --- a/docs/source/examples/payments.rst +++ b/docs/source/examples/payments.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.579017 - ======== Payments ======== diff --git a/docs/source/examples/proxy_and_emojize.rst b/docs/source/examples/proxy_and_emojize.rst index 3dbaa268..96a4f9a7 100644 --- a/docs/source/examples/proxy_and_emojize.rst +++ b/docs/source/examples/proxy_and_emojize.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.555359 - ================= Proxy and emojize ================= diff --git a/docs/source/examples/regexp_commands_filter_example.rst b/docs/source/examples/regexp_commands_filter_example.rst index 36452350..e524640a 100644 --- a/docs/source/examples/regexp_commands_filter_example.rst +++ b/docs/source/examples/regexp_commands_filter_example.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.568530 - ============================== Regexp commands filter example ============================== diff --git a/docs/source/examples/throtling_example.rst b/docs/source/examples/throtling_example.rst index f64eaccc..258d3d22 100644 --- a/docs/source/examples/throtling_example.rst +++ b/docs/source/examples/throtling_example.rst @@ -1,14 +1,8 @@ -.. Autogenerated file at 2018-09-08 02:07:37.563878 - -================= -Throtling example -================= - -Example for throttling manager. -You can use that for flood controlling. +================== +Throttling example +================== .. literalinclude:: ../../../examples/throttling_example.py :caption: throttling_example.py :language: python :linenos: - :lines: 7- diff --git a/docs/source/examples/webhook_example.rst b/docs/source/examples/webhook_example.rst index 48de8622..ce71339a 100644 --- a/docs/source/examples/webhook_example.rst +++ b/docs/source/examples/webhook_example.rst @@ -1,13 +1,8 @@ -.. Autogenerated file at 2018-10-28 19:31:48.341172 - =============== Webhook example =============== -Example outdated - .. literalinclude:: ../../../examples/webhook_example.py :caption: webhook_example.py :language: python :linenos: - :lines: 5- diff --git a/docs/source/examples/webhook_example_2.rst b/docs/source/examples/webhook_example_2.rst index 025264e4..8c104f12 100644 --- a/docs/source/examples/webhook_example_2.rst +++ b/docs/source/examples/webhook_example_2.rst @@ -1,5 +1,3 @@ -.. Autogenerated file at 2018-09-08 02:07:37.576034 - =================== Webhook example old =================== diff --git a/docs/source/index.rst b/docs/source/index.rst index 0ac6eccd..e08e8830 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -22,7 +22,7 @@ Welcome to aiogram's documentation! :target: https://pypi.python.org/pypi/aiogram :alt: Supported python versions - .. image:: https://img.shields.io/badge/Telegram%20Bot%20API-4.9-blue.svg?style=flat-square&logo=telegram + .. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.0-blue.svg?style=flat-square&logo=telegram :target: https://core.telegram.org/bots/api :alt: Telegram Bot API diff --git a/examples/local_server.py b/examples/local_server.py new file mode 100644 index 00000000..7dbc4aca --- /dev/null +++ b/examples/local_server.py @@ -0,0 +1,27 @@ +import logging + +from aiogram import Bot, Dispatcher, executor, types +from aiogram.bot.api import TelegramAPIServer +from aiogram.types import ContentType + +API_TOKEN = 'BOT TOKEN HERE' + +# Configure logging +logging.basicConfig(level=logging.INFO) + +# Create private Bot API server endpoints wrapper +local_server = TelegramAPIServer.from_base('http://localhost') + +# Initialize bot with using local server +bot = Bot(token=API_TOKEN, server=local_server) +# ... and dispatcher +dp = Dispatcher(bot) + + +@dp.message_handler(content_types=ContentType.ANY) +async def echo(message: types.Message): + await message.copy_to(message.chat.id) + + +if __name__ == '__main__': + executor.start_polling(dp, skip_updates=True)