{"id":297859,"date":"2020-01-29T03:00:13","date_gmt":"2020-01-29T03:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297859"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297859","title":{"rendered":"\u0425\u0440\u0430\u043d\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0430\u0442\u0430 \u043d\u0430 \u0441\u0442\u0435\u043a\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/486006\/\">\n<blockquote><p>\u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435 \u2014 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435!<\/p><\/blockquote>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u0438\u0448\u0443\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u043e\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 IM \u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u043a\u0430\u043a-\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0436\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vf\/_h\/zm\/vf_hzmqlsydmjpiaqmzwxglsi7i.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0412\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043a\u043e\u0434 \u043c\u043d\u043e\u0433\u0438\u0445 \u0431\u043e\u0442\u043e\u0432, \u0442\u043e \u043e\u043d \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/li>\n<li>\u043e\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (<code>callback<\/code>)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u043e\u0432. \u041e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0434\u043b\u044f \u0447\u0430\u0442\u043e\u0432 \u0441 \u043e\u0434\u043d\u0438\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u043c \u0438 \u0434\u043b\u044f \u0431\u043e\u0442\u043e\u0432, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u0445 \u0432 \u0433\u0440\u0443\u043f\u043f\u044b. \u0421 \u044d\u0442\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e: \u043a\u043e\u0434 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0431\u043e\u0442\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u0443\u0442\u0430\u0442\u044c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"nachnu-s-disklaymerov\">\u041d\u0430\u0447\u043d\u0443 \u0441 \u0434\u0438\u0441\u043a\u043b\u0430\u0439\u043c\u0435\u0440\u043e\u0432:<\/h2>\n<p>  <\/p>\n<ol>\n<li>\u0422\u043e \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0431\u043e\u0442\u043e\u0432 \u0432\u0438\u0434\u0430 <code>\u0431\u043e\u0442 &lt;-&gt; \u043e\u0434\u0438\u043d \u0447\u0435\u043b\u043e\u0432\u0435\u043a<\/code>.<\/li>\n<li>\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0434\u043e\u043c-\u0441\u043a\u0435\u0442\u0447\u0435\u043c. \u041d\u0430\u043f\u0438\u0441\u0430\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0437\u0430 15 \u043c\u0438\u043d\u0443\u0442. \u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u0433\u043e.<\/li>\n<li>\u042f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441\u0435: \u0441 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u041d\u043e, \u0443\u0432\u044b, \u043c\u043e\u0439 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d \u043a\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0433\u043e \u043d\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0441\u043a\u0435\u0442\u0447. \u042f \u043a\u043e\u0441\u043d\u0443\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u044b (\u043e\u043f\u0438\u0448\u0443 \u043a\u0443\u0434\u0430 \u0438 \u043a\u0430\u043a \u043c\u044b \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u043b\u0438).<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"nu-a-teper-poehali\">\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0435\u0445\u0430\u043b\u0438.<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u043f\u043e\u0440\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/aiogram.readthedocs.io\/en\/latest\/quick_start.html#summary\" rel=\"nofollow\">aiogram, python3.7+<\/a>. \u041f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e echo-\u0431\u043e\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u043f\u0438\u0440\u0443\u044e \u0435\u0433\u043e \u0441\u044e\u0434\u0430:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">&quot;&quot;&quot; This is a echo bot. It echoes any incoming text messages. &quot;&quot;&quot;  import logging  from aiogram import Bot, Dispatcher, executor, types  API_TOKEN = 'BOT TOKEN HERE'  # Configure logging logging.basicConfig(level=logging.INFO)  # Initialize bot and dispatcher bot = Bot(token=API_TOKEN) dp = Dispatcher(bot)  @dp.message_handler(regexp='(^cat[s]?$|puss)') async def cats(message: types.Message):     with open('data\/cats.jpg', 'rb') as photo:         '''         # Old fashioned way:         await bot.send_photo(             message.chat.id,             photo,             caption='Cats are here ',             reply_to_message_id=message.message_id,         )         '''          await message.reply_photo(photo, caption='Cats are here ')  @dp.message_handler() async def echo(message: types.Message):     # old style:     # await bot.send_message(message.chat.id, message.text)      await message.answer(message.text)  if __name__ == '__main__':     executor.start_polling(dp, skip_updates=True)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u043e\u0442\u0430 \u2014 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0430\u044f. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u043c \u0447\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u0442 \u2014 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<p>  <\/p>\n<h2 id=\"chto-plohogo-v-etoy-paradigme\">\u0427\u0442\u043e \u043f\u043b\u043e\u0445\u043e\u0433\u043e \u0432 \u044d\u0442\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435?<\/h2>\n<p>  <\/p>\n<p>\u0422\u043e, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0432\u043e\u0451\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0442\u0435\u0439\u0442 \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0431\u043e\u0442\u043e\u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0431\u0438\u0437\u043d\u0435\u0441 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u0451\u043c \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443), \u0442\u043e \u043e\u043d\u0438 \u0437\u0430\u0434\u0430\u044e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e 1..N \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u0437\u0430\u0442\u0435\u043c \u043f\u043e \u0438\u0442\u043e\u0433\u0443 \u044d\u0442\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442 \u0430\u043d\u043a\u0435\u0442\u0443 \u0432 \u0411\u0414).<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0432 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 (\u0430 \u043d\u0435 \u043a\u043e\u043b\u0431\u0435\u0447\u043d\u043e\u043c), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u044f\u043c\u043e \u043d\u0430 \u0441\u0442\u0435\u043a\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"davayte-poprobuem-eto-sdelat\">\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/h2>\n<p>  <\/p>\n<p>\u042f \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b \u0441\u043a\u0435\u0442\u0447 \u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0424\u0430\u0439\u043b - chat_dispatcher.py import asyncio  class ChatDispatcher:     class Timeout(RuntimeError):         def __init__(self, last_message):             self.last_message = last_message             super().__init__('timeout exceeded')      def __init__(self, *,                  chatcb,                  shardcb = lambda message: message.from_user.id,                  inactive_timeout = 15 * 60):         self.chatcb = chatcb         self.shardcb = shardcb         self.inactive_timeout = inactive_timeout         self.chats = {}      async def handle(self, message):         shard = self.shardcb(message)          loop = asyncio.get_event_loop()          if shard not in self.chats:             self.chats[shard] = {                 'task': self.create_chat(loop, shard),                 'messages': [],                 'wait': asyncio.Event(),                 'last_message': None,             }         self.chats[shard]['messages'].append(message)         self.chats[shard]['wait'].set()      def create_chat(self, loop, shard):         async def _chat_wrapper():             try:                 await self.chatcb(self.get_message(shard))             finally:                 del self.chats[shard]          return loop.create_task(_chat_wrapper())      def get_message(self, shard):         async def _get_message(inactive_timeout=self.inactive_timeout):             while True:                 if self.chats[shard]['messages']:                     last_message = self.chats[shard]['messages'].pop(0)                     self.chats[shard]['last_message'] = last_message                     return last_message                  try:                     await asyncio.wait_for(self.chats[shard]['wait'].wait(),                                            timeout=inactive_timeout)                 except asyncio.TimeoutError:                     self.chats[shard]['wait'].set()                     raise self.Timeout(self.chats[shard]['last_message'])                  if not self.chats[shard]['messages']:                     self.chats[shard]['wait'].clear()         return _get_message <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <code>ChatDispatcher<\/code> \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (\u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u0437\u0432\u0430\u043d\u043e \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u043e\u043c \u2014 \u043f\u043e\u0437\u0434\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0441\u043d\u0451\u043c\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u043a). \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043d\u0430 \u0434\u0438\u0430\u043b\u043e\u0433. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/li>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0442\u0430.<\/li>\n<li>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u043f\u043e \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433. \u042d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440 \u043f\u043e\u043a\u0430 \u0434\u0438\u0430\u043b\u043e\u0433 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f.<\/li>\n<li>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u044f\u0432\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435. \u041f\u0440\u0438\u043c\u0435\u0440 \u0447\u0430\u0442\u0430 <code>echo<\/code>:<br \/> \n<pre><code class=\"python\">async def chat(get_message):     message = await get_message()     await message.answer(message.text)<\/code><\/pre>\n<\/li>\n<li>\u041e\u0442\u0432\u0435\u0447\u0430\u0435\u043c \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u043a, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 (<code>message.answer<\/code>).<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"davayte-poprobuem-napisat-bota-v-etoy-paradigme\">\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0432 \u044d\u0442\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435<\/h2>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0442\u0443\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0424\u0430\u0439\u043b bot.py  import asyncio import re from .chat_dispatcher import ChatDispatcher import logging from aiogram import Bot, Dispatcher, executor, types  API_TOKEN ='\u0421\u044e\u0434\u0430 \u0432\u043f\u0438\u0448\u0438\u0442\u0435 \u0442\u043e\u043a\u0435\u043d \u0412\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430'  logging.basicConfig(level=logging.INFO) bot = Bot(token=API_TOKEN) dp = Dispatcher(bot)  async def chat(get_message):     try:         message = await get_message()         await message.answer('\u0423\u043c\u0435\u044e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430, \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e')          first = await get_message()         if not re.match('^\\d+$', str(first.text)):             await first.answer('\u044d\u0442\u043e \u043d\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430: \/start')             return          await first.answer('\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0435 \u0447\u0438\u0441\u043b\u043e')         second = await get_message()          if not re.match('^\\d+$', str(second.text)):             await second.answer('\u044d\u0442\u043e \u043d\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430: \/start')             return          result = int(first.text) + int(second.text)         await second.answer('\u0411\u0443\u0434\u0435\u0442 %s (\/start - \u0441\u043d\u0430\u0447\u0430\u043b\u0430)' % result)      except ChatDispatcher.Timeout as te:         await te.last_message.answer('\u0427\u0442\u043e-\u0442\u043e \u0412\u044b \u0434\u043e\u043b\u0433\u043e \u043c\u043e\u043b\u0447\u0438\u0442\u0435, \u043f\u043e\u0439\u0434\u0443 \u043f\u043e\u0441\u043f\u043b\u044e')         await te.last_message.answer('\u0441\u043d\u0430\u0447\u0430\u043b\u0430 - \/start')  chat_dispatcher = ChatDispatcher(chatcb=chat,                                  inactive_timeout=20)  @dp.message_handler() async def message_handle(message: types.Message):     await chat_dispatcher.handle(message)  if __name__ == '__main__':     executor.start_polling(dp, skip_updates=True) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u043e\u0442\u0430 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u0440\u0443 \u0447\u0438\u0441\u0435\u043b \u0438 \u0432\u044b\u0434\u0430\u0451\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/x9\/5z\/qo\/x95zqothkgmmdklolp7gijvqeaa.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0431\u043b\u0438\u0436\u0435 \u043a\u043e\u0434. \u0418\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u043d\u0430\u0448\u0438\u043c \u0441\u043a\u0435\u0442\u0447\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u043d\u0430 \u0442\u0430\u043a \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>await chat_dispatcher.handle(message)<\/code>. \u0410 \u0447\u0430\u0442 \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>chat<\/code>, \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u0441\u044e\u0434\u0430 \u0435\u0433\u043e \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">async def chat(get_message):     try:         message = await get_message()         await message.answer('\u0423\u043c\u0435\u044e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430, \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e')          first = await get_message()         if not re.match('^\\d+$', str(first.text)):             await first.answer('\u044d\u0442\u043e \u043d\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430: \/start')             return          await first.answer('\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0435 \u0447\u0438\u0441\u043b\u043e')         second = await get_message()          if not re.match('^\\d+$', str(second.text)):             await second.answer('\u044d\u0442\u043e \u043d\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430: \/start')             return          result = int(first.text) + int(second.text)         await second.answer('\u0411\u0443\u0434\u0435\u0442 %s (\/start - \u0441\u043d\u0430\u0447\u0430\u043b\u0430)' % result)      except ChatDispatcher.Timeout as te:         await te.last_message.answer('\u0427\u0442\u043e-\u0442\u043e \u0412\u044b \u0434\u043e\u043b\u0433\u043e \u043c\u043e\u043b\u0447\u0438\u0442\u0435, \u043f\u043e\u0439\u0434\u0443 \u043f\u043e\u0441\u043f\u043b\u044e')         await te.last_message.answer('\u0441\u043d\u0430\u0447\u0430\u043b\u0430 - \/start') <\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0442\u0430 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u0442\u0432\u0435\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043b\u0430\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0435\u043a\u0435 (\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <code>first<\/code>, <code>second<\/code>, <code>message<\/code>).<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>get_message<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0432\u043e\u0434\u0438\u0442 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 (\u0438 \u0435\u0439 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043f\u043e \u043c\u0435\u0441\u0442\u0443).<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0435\u0439\u0442 \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u2014 \u043f\u0440\u044f\u043c\u043e \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <strong>\u041f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u044f\u0441\u044c \u0432\u043d\u0438\u0437 \u043f\u043e \u043a\u043e\u0434\u0443 \u2014 \u043c\u044b \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u0441\u0445\u0435\u043c\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u0430<\/strong>. \u0412\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0432\u0435\u0442\u043a\u0443 \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u2014 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e!<br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u043d\u0435 \u043d\u0443\u0436\u043d\u044b. \u0412 \u044d\u0442\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c <strong>\u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435<\/strong> \u0434\u0438\u0430\u043b\u043e\u0433\u0438 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0438\u0445 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0447\u0435\u043c \u043a\u043e\u0434 \u0441 <code>callback<\/code>&#8216;\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"nedostatki\">\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/h2>\n<p>  <\/p>\n<p>\u041a\u0443\u0434\u0430 \u0436 \u0431\u0435\u0437 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u0442\u0430\u0441\u043a-\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u0412 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043e\u0434\u0438\u043d CPU \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u043a\u043e\u043b\u043e 1000 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438.<\/li>\n<li>\u0420\u0435\u0441\u0442\u0430\u0440\u0442 \u0432\u0441\u0435\u0433\u043e \u0434\u0435\u043c\u043e\u043d\u0430 \u2014 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044e \u0432\u0441\u0435\u0445 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 (\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0443 \u0438\u0445).<\/li>\n<li>\u041a\u043e\u0434 [\u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430] \u043d\u0435 \u043f\u0440\u0438\u0441\u043f\u043e\u0441\u043e\u0431\u043b\u0435\u043d \u043a \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c: \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0430 \u0438 \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c &quot;\u0443 \u043c\u0435\u043d\u044f \u0442\u0443\u0442 \u0427\u041f, \u043f\u043e\u0436\u0430\u0440, \u0432\u0435\u0440\u043d\u0443\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0434\u043d\u0435\u0435&quot;. \u0422\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0451:<\/p>\n<p>  <\/p>\n<h2 id=\"masshtabirovanie-nagruzki\">\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438<\/h2>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u0431\u043e\u0442\u044b \u043d\u0430\u0434\u043e \u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0430 \u043c\u043d\u043e\u0433\u0438\u0445 \u0431\u0430\u043a\u0435\u043d\u0434\u0430\u0445 \u0441\u0440\u0430\u0437\u0443. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <code>webHook<\/code> \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>webHook<\/code> \u043c\u0435\u0436\u0434\u0443 \u0441\u043a\u0430\u0436\u0435\u043c \u0434\u0432\u0443\u043c\u044f \u0431\u0430\u043a\u0435\u043d\u0434\u0430\u043c\u0438, \u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b \u043a \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0434\u0451\u0442 \u0441 \u043d\u0438\u043c \u0434\u0438\u0430\u043b\u043e\u0433.<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0430 \u0431\u0430\u043b\u0430\u043d\u0441\u0435\u0440\u0435 \u043f\u0430\u0440\u0441\u0438\u043c JSON \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>message<\/code>)<\/li>\n<li>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/li>\n<li>\u041f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u0431\u0430\u043a\u0435\u043d\u0434\u0430 (== \u0448\u0430\u0440\u0434\u0430). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 <code>user_id % Nshards<\/code>.<\/li>\n<li>\u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0448\u0430\u0440\u0434\u0443.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2014 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u043c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0438 \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u0440\u0434-\u043d\u043e\u043c\u0435\u0440\u0430 \u0431\u0430\u043a\u0435\u043d\u0434\u0430 \u0432 \u0431\u0430\u043b\u0430\u043d\u0441\u0435\u0440\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0435\u0440\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u2014 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0437\u0430 10 \u043c\u0438\u043d\u0443\u0442. \u041d\u0435 \u0431\u0443\u0434\u0443 \u0435\u0433\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u043e\u0432 \u0432 \u044d\u0442\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433\u0438 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u2014 <strong>\u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f<\/strong> \u0432 \u043a\u043e\u0434\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0442\u043e-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u0434\u043e \u043d\u0435\u0433\u043e.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0438\u0448\u0435\u0442 \u0431\u043e\u0442\u043e\u0432 \u0432 \u043a\u043e\u043b\u0431\u0435\u0447\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u2014 \u044f \u043d\u0435 \u0437\u043d\u0430\u044e.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u043d\u044c\u0448\u0435 \u043f\u0438\u0441\u0430\u043b\u0438 \u0432 \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435. \u041e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0447\u0430\u0442\u043e\u0432 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0432 \u044d\u043f\u043e\u0445\u0443 IRC \u0438 \u0431\u043e\u0442\u043e\u0432 \u0434\u043b\u044f \u043d\u0435\u0433\u043e. \u0422\u0430\u043a \u0447\u0442\u043e \u044f \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u044e \u043d\u0430 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043d\u043e\u0432\u0438\u0437\u043d\u0443.<\/p>\n<p>  <\/p>\n<p>\u0418 \u0435\u0449\u0451. \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0443 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>goto<\/code>, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f <code>goto<\/code> (\u0446\u0438\u043a\u043b\u044b \u0432 \u0434\u0438\u0430\u043b\u043e\u0433\u0430\u0445 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 <code>goto<\/code>). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u044d\u0442\u043e \u043d\u0435 \u043e Python.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/486006\/\"> https:\/\/habr.com\/ru\/post\/486006\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/486006\/\">\n<blockquote><p>\u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435 \u2014 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435!<\/p><\/blockquote>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u0438\u0448\u0443\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u043e\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 IM \u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u043a\u0430\u043a-\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0436\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vf\/_h\/zm\/vf_hzmqlsydmjpiaqmzwxglsi7i.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0412\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043a\u043e\u0434 \u043c\u043d\u043e\u0433\u0438\u0445 \u0431\u043e\u0442\u043e\u0432, \u0442\u043e \u043e\u043d \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/li>\n<li>\u043e\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (<code>callback<\/code>)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u043e\u0432. \u041e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0434\u043b\u044f \u0447\u0430\u0442\u043e\u0432 \u0441 \u043e\u0434\u043d\u0438\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u043c \u0438 \u0434\u043b\u044f \u0431\u043e\u0442\u043e\u0432, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u0445 \u0432 \u0433\u0440\u0443\u043f\u043f\u044b. \u0421 \u044d\u0442\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e: \u043a\u043e\u0434 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0431\u043e\u0442\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u0443\u0442\u0430\u0442\u044c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297859","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297859"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297859\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}