diff --git a/examples/broadcast_example.py b/examples/broadcast_example.py
index 468da916..dc43759d 100644
--- a/examples/broadcast_example.py
+++ b/examples/broadcast_example.py
@@ -32,7 +32,7 @@ async def send_message(user_id: int, text: str) -> bool:
:return:
"""
try:
- await bot.send_message(user_id, 'Hello, World!')
+ await bot.send_message(user_id, text)
except exceptions.BotBlocked:
log.error(f"Target [ID:{user_id}]: blocked by user")
except exceptions.ChatNotFound:
diff --git a/examples/check_user_language.py b/examples/check_user_language.py
index 1e1046a9..bd0ba7f9 100644
--- a/examples/check_user_language.py
+++ b/examples/check_user_language.py
@@ -5,18 +5,14 @@ Babel is required.
import asyncio
import logging
-from aiogram import Bot, types
-from aiogram.dispatcher import Dispatcher
-from aiogram.types import ParseMode
-from aiogram.utils.executor import start_polling
-from aiogram.utils.markdown import *
+from aiogram import Bot, Dispatcher, executor, md, types
API_TOKEN = 'BOT TOKEN HERE'
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop()
-bot = Bot(token=API_TOKEN, loop=loop)
+bot = Bot(token=API_TOKEN, loop=loop, parse_mode=types.ParseMode.MARKDOWN)
dp = Dispatcher(bot)
@@ -24,14 +20,14 @@ dp = Dispatcher(bot)
async def check_language(message: types.Message):
locale = message.from_user.locale
- await message.reply(text(
- bold('Info about your language:'),
- text(' 🔸', bold('Code:'), italic(locale.locale)),
- text(' 🔸', bold('Territory:'), italic(locale.territory or 'Unknown')),
- text(' 🔸', bold('Language name:'), italic(locale.language_name)),
- text(' 🔸', bold('English language name:'), italic(locale.english_name)),
- sep='\n'), parse_mode=ParseMode.MARKDOWN)
+ await message.reply(md.text(
+ md.bold('Info about your language:'),
+ md.text(' 🔸', md.bold('Code:'), md.italic(locale.locale)),
+ md.text(' 🔸', md.bold('Territory:'), md.italic(locale.territory or 'Unknown')),
+ md.text(' 🔸', md.bold('Language name:'), md.italic(locale.language_name)),
+ md.text(' 🔸', md.bold('English language name:'), md.italic(locale.english_name)),
+ sep='\n'))
if __name__ == '__main__':
- start_polling(dp, loop=loop, skip_updates=True)
+ executor.start_polling(dp, loop=loop, skip_updates=True)
diff --git a/examples/echo_bot.py b/examples/echo_bot.py
index 7f4b0324..617dbad7 100644
--- a/examples/echo_bot.py
+++ b/examples/echo_bot.py
@@ -1,9 +1,7 @@
import asyncio
import logging
-from aiogram import Bot, types
-from aiogram.dispatcher import Dispatcher
-from aiogram.utils.executor import start_polling
+from aiogram import Bot, types, Dispatcher, executor
API_TOKEN = 'BOT TOKEN HERE'
@@ -32,10 +30,4 @@ async def echo(message: types.Message):
if __name__ == '__main__':
- start_polling(dp, loop=loop, skip_updates=True)
-
- # Also you can use another execution method
- # >>> try:
- # >>> loop.run_until_complete(main())
- # >>> except KeyboardInterrupt:
- # >>> loop.stop()
+ executor.start_polling(dp, loop=loop, skip_updates=True)
diff --git a/examples/example_context_middleware.py b/examples/example_context_middleware.py
deleted file mode 100644
index d909b52d..00000000
--- a/examples/example_context_middleware.py
+++ /dev/null
@@ -1,47 +0,0 @@
-from aiogram import Bot, types
-from aiogram.contrib.middlewares.context import ContextMiddleware
-from aiogram.dispatcher import Dispatcher
-from aiogram.types import ParseMode
-from aiogram.utils import markdown as md
-from aiogram.utils.executor import start_polling
-
-API_TOKEN = 'BOT TOKEN HERE'
-
-bot = Bot(token=API_TOKEN)
-dp = Dispatcher(bot)
-
-# Setup Context middleware
-data: ContextMiddleware = dp.middleware.setup(ContextMiddleware())
-
-
-# Write custom filter
-async def demo_filter(message: types.Message):
- # Store some data in context
- command = data['command'] = message.get_command() or ''
- args = data['args'] = message.get_args() or ''
- data['has_args'] = bool(args)
- data['some_random_data'] = 42
- return command != '/bad_command'
-
-
-@dp.message_handler(demo_filter)
-async def send_welcome(message: types.Message):
- # Get data from context
- # All of this is available only in current context and from current update object
- # `data`- pseudo-alias for `ctx.get_update().conf['_context_data']`
- command = data['command']
- args = data['args']
- rand = data['some_random_data']
- has_args = data['has_args']
-
- # Send as pre-formatted code block.
- await message.reply(md.hpre(f"""command: {command}
-args: {['Not available', 'available'][has_args]}: {args}
-some random data: {rand}
-message ID: {message.message_id}
-message: {message.html_text}
- """), parse_mode=ParseMode.HTML)
-
-
-if __name__ == '__main__':
- start_polling(dp)
diff --git a/examples/i18n_example.py b/examples/i18n_example.py
index a7ccbde3..6469ed5b 100644
--- a/examples/i18n_example.py
+++ b/examples/i18n_example.py
@@ -21,9 +21,8 @@ Step 5: When you change the code of your bot you need to update po & mo files.
from pathlib import Path
-from aiogram import Bot, Dispatcher, types
+from aiogram import Bot, Dispatcher, executor, types
from aiogram.contrib.middlewares.i18n import I18nMiddleware
-from aiogram.utils import executor
TOKEN = 'BOT TOKEN HERE'
I18N_DOMAIN = 'mybot'
diff --git a/examples/inline_bot.py b/examples/inline_bot.py
index bb6d0f89..4a771210 100644
--- a/examples/inline_bot.py
+++ b/examples/inline_bot.py
@@ -1,9 +1,7 @@
import asyncio
import logging
-from aiogram import Bot, types
-from aiogram.dispatcher import Dispatcher
-from aiogram.utils.executor import start_polling
+from aiogram import Bot, types, Dispatcher, executor
API_TOKEN = 'BOT TOKEN HERE'
@@ -23,4 +21,4 @@ async def inline_echo(inline_query: types.InlineQuery):
if __name__ == '__main__':
- start_polling(dp, loop=loop, skip_updates=True)
+ executor.start_polling(dp, loop=loop, skip_updates=True)
diff --git a/examples/media_group.py b/examples/media_group.py
index 0194733d..b1f5246a 100644
--- a/examples/media_group.py
+++ b/examples/media_group.py
@@ -1,9 +1,6 @@
import asyncio
-from aiogram import Bot, types
-from aiogram.dispatcher import Dispatcher
-from aiogram.types import ChatActions
-from aiogram.utils.executor import start_polling
+from aiogram import Bot, Dispatcher, executor, filters, types
API_TOKEN = 'BOT TOKEN HERE'
@@ -12,7 +9,7 @@ bot = Bot(token=API_TOKEN, loop=loop)
dp = Dispatcher(bot)
-@dp.message_handler(commands=['start'])
+@dp.message_handler(filters.CommandStart())
async def send_welcome(message: types.Message):
# So... At first I want to send something like this:
await message.reply("Do you want to see many pussies? Are you ready?")
@@ -21,7 +18,7 @@ async def send_welcome(message: types.Message):
await asyncio.sleep(1)
# Good bots should send chat actions. Or not.
- await ChatActions.upload_photo()
+ await types.ChatActions.upload_photo()
# Create media group
media = types.MediaGroup()
@@ -39,9 +36,8 @@ async def send_welcome(message: types.Message):
# media.attach_photo('', 'cat-cat-cat.')
# Done! Send media group
- await bot.send_media_group(message.chat.id, media=media,
- reply_to_message_id=message.message_id)
+ await message.reply_media_group(media=media)
if __name__ == '__main__':
- start_polling(dp, loop=loop, skip_updates=True)
+ executor.start_polling(dp, loop=loop, skip_updates=True)
diff --git a/examples/middleware_and_antiflood.py b/examples/middleware_and_antiflood.py
index d0a8ad08..7b83d9a4 100644
--- a/examples/middleware_and_antiflood.py
+++ b/examples/middleware_and_antiflood.py
@@ -1,11 +1,10 @@
import asyncio
-from aiogram import Bot, types
+from aiogram import Bot, Dispatcher, executor, types
from aiogram.contrib.fsm_storage.redis import RedisStorage2
-from aiogram.dispatcher import CancelHandler, DEFAULT_RATE_LIMIT, Dispatcher
+from aiogram.dispatcher import DEFAULT_RATE_LIMIT
+from aiogram.dispatcher.handler import CancelHandler
from aiogram.dispatcher.middlewares import BaseMiddleware
-from aiogram.utils import executor
-from aiogram.utils.exceptions import Throttled
TOKEN = 'BOT TOKEN HERE'