{"id":321962,"date":"2021-04-23T15:00:29","date_gmt":"2021-04-23T15:00:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=321962"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=321962","title":{"rendered":"\u0425\u0430\u0440\u0434\u043a\u043e\u0440\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u043e\u0434 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c. \u0411\u043e\u0442-\u043c\u043e\u0434\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u044c 1"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e94\/571\/5a3\/e945715a32a70ede6b2302b7dfaecf9f.jpeg\" width=\"1332\" height=\"850\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u0440\u0443\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430-\u043c\u043e\u0434\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0447\u0430\u0442\u043e\u0432 \u043d\u0430 Python. \u041f\u0443\u0441\u0442\u044c \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u0442, \u0431\u0430\u043d\u0438\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043c \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0447\u0430\u0442\u0430 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u041c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043b\u0438\u043c\u0438\u0442\u043e\u0432 \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043d\u0430\u0443\u0447\u0438\u043c \u0431\u043e\u0442\u0430 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c Python \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 Telethon \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Telegram API (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0438\u0436\u0435) \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 Databases \u0441 SQLAlchemy Core \u0434\u043b\u044f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0443\u0436\u0435 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438).<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/Tm-A-T\/admin-bot-tutorial\/tree\/chapter-1\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0434 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043d\u0430 GitHub<\/a>.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u043e\u0442\u0430<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043e\u0442\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430 <a href=\"http:\/\/t.me\/botfather\" rel=\"noopener noreferrer nofollow\">BotFather<\/a>.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ab7\/b6b\/130\/ab7b6b1304844515c4fef02a774dd4fc.png\" width=\"479\" height=\"282\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u043d \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442 \u0432\u0430\u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u043c\u044f \u0431\u043e\u0442\u0430 \u0438 \u0435\u0433\u043e \u044e\u0437\u0435\u0440\u043d\u0435\u0439\u043c. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0441\u0432\u043e\u0435\u0433\u043e &#171;\u0420\u043e\u0431\u043e\u0442\u0430 \u0412\u0430\u0441\u044e 2077&#187;, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0442\u043e\u043a\u0435\u043d \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0431\u043e\u0442\u043e\u043c.  <\/p>\n<h2>Telegram API<\/h2>\n<p>\u0412 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/543676\" rel=\"noopener noreferrer nofollow\">&#171;\u0412\u0441\u0451, \u043e \u0447\u0451\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u0431\u043e\u0442\u043e\u0432&#187;<\/a> \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u043b, \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f Telegram API \u043e\u0442 Telegram Bot API.<\/p>\n<p>Bot API \u0431\u043e\u043b\u0435\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u043e\u0442\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0433\u0440\u0443\u043f\u043f\u044b \u0438\u043b\u0438 \u0441\u0442\u0430\u0440\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0418 \u0445\u043e\u0442\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u044d\u0442\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f, \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e Telegram API. \u0410 \u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u043a\u0430\u043a \u043e\u0431\u0438\u0434\u043d\u043e: \u0432\u043e\u0442 \u043f\u0438\u0448\u0435\u0442\u0435 \u0432\u044b \u0431\u043e\u0442\u0430, \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0435 \u0435\u0433\u043e, \u0438 \u0432\u0434\u0440\u0443\u0433 \u0432\u0430\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u0430 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0444\u0438\u0447\u0430, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c API. \u0418 \u0441\u0440\u0430\u0437\u0443 \u0433\u0440\u0443\u0441\u0442\u043d\u0435\u043d\u044c\u043a\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Telegram API \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/docs.telethon.dev\/\" rel=\"noopener noreferrer nofollow\">Telethon<\/a>:<\/p>\n<pre><code>$ pip install telethon<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a Telegram API \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0430, \u0434\u043b\u044f \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 my.telegram.org. \u0414\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 API \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u043e\u0442\u043e\u0432. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7f4\/1d8\/765\/7f41d8765adf0b4a45945a40dd098fdc.png\" width=\"989\" height=\"862\"><figcaption><\/figcaption><\/figure>\n<p>\u0424\u043e\u0440\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 api_id \u0438 api_hash \u0432\u0430\u0448\u0435\u0433\u043e &#171;\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f&#187;. \u041e\u043d\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>app\/     __init__.py     __main__.py     handlers.py config.py<\/code><\/pre>\n<p>\u0412 <code>handlers.py<\/code> \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u0412 <code>config.py<\/code> \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0435\u0433\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c:<\/p>\n<pre><code class=\"python\">BOT_TOKEN = '\u0442\u043e\u043a\u0435\u043d-\u0432\u0430\u0448\u0435\u0433\u043e-\u0431\u043e\u0442\u0430' API_ID = 123456789 API_HASH = '\u0432\u0430\u0448\u0435-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435'<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043b\u044e\u0431\u044b\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u0430\u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u041d\u043e \u044f \u0431\u0443\u0434\u0443 \u0434\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b config.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e <code>__init__.py<\/code>. \u0413\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 telethon \u2014 \u043a\u043b\u0430\u0441\u0441 <code>TelegramClient<\/code>. \u0418\u043c\u0435\u043d\u043d\u043e \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430.<\/p>\n<p>\u041f\u043e\u0437\u0436\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0431\u043e\u0442\u0435 (\u0435\u0433\u043e id, \u044e\u0437\u0435\u0440\u043d\u0435\u0439\u043c \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 TelegramClient:<\/p>\n<pre><code class=\"python\">import logging from telethon import TelegramClient import config  class Bot(TelegramClient):     def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.me = None  # \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0431\u043e\u0442\u0435  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0431\u043e\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u0430\u043d\u043d\u044b\u0435 API bot = Bot('bot', config.API_ID, config.API_HASH)<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u043e\u0442\u0430 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u0427\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u043e\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u043e\u043a\u0435\u043d\u0430. (\u0423\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <code>'bot'<\/code>\u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u0441\u0435\u0441\u0441\u0438\u0438: \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.)<\/p>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0431\u043e\u0442\u0430 <code>parse_mode<\/code> \u2014 \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u043e\u0439 (\u0436\u0438\u0440\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043a\u0443\u0440\u0441\u0438\u0432, \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435).  \u0412\u044b\u0431\u0435\u0440\u0435\u043c HTML.<\/p>\n<p>\u0418 \u0437\u0430\u043e\u0434\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043b\u043e\u0433\u0433\u0438\u043d\u0433:<\/p>\n<pre><code class=\"python\">bot.parse_mode = 'HTML' logging.basicConfig(level=logging.INFO)<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 bot \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b: \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c app.handlers (\u0441\u0435\u0439\u0447\u0430\u0441 \u0432 \u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442).<\/p>\n<pre><code class=\"python\">import app.handlers<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0430\u043f\u0434\u0435\u0439\u0442\u044b.<\/p>\n<pre><code class=\"python\">async def start():     # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443     await bot.connect()          # \u0412\u043e\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u043a\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 sign_in \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0431\u043e\u0442\u0435. \u041c\u044b \u0441\u0440\u0430\u0437\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0435\u0451 \u0432 bot.me     bot.me = await bot.sign_in(bot_token=config.BOT_TOKEN)          # \u041d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u043f\u0434\u0435\u0439\u0442\u044b \u043e\u0442 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b     await bot.run_until_disconnected() <\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0444\u0443\u043d\u043a\u0446\u0438\u044e run, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e start:<\/p>\n<pre><code class=\"python\">def run():     bot.loop.run_until_complete(start())<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u043f\u0435\u0440\u044c __init__.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import logging  from telethon import TelegramClient  import config   class Bot(TelegramClient):     def __init__(self, *args):         super().__init__(*args)         self.me = None   bot = Bot('bot', config.API_ID, config.API_HASH) bot.parse_mode = 'HTML' logging.basicConfig(level=logging.INFO)  import app.handlers   async def start():     await bot.connect()     bot.me = await bot.sign_in(bot_token=config.BOT_TOKEN)     await bot.run_until_disconnected()   def run():     bot.loop.run_until_complete(start()) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430\u043c.<\/p>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u0432 <a href=\"http:\/\/handlers.py\" rel=\"noopener noreferrer nofollow\">handlers.py<\/a> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0431\u0443\u0434\u0435\u043c \u043b\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0431\u043e\u0442\u0430 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443.<\/p>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u043e\u0432\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 &#171;\u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0433\u0440\u0443\u043f\u043f\u0443&#187;, &#171;\u0438\u0437\u043c\u0435\u043d\u0438\u043b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u0440\u0443\u043f\u043f\u044b&#187;, &#171;\u0437\u0430\u043a\u0440\u0435\u043f\u0438\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f&#187; \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435). \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<br \/>\u0430) \u0431\u044b\u043b\u043e \u0432 \u0433\u0440\u0443\u043f\u043f\u0435,<br \/>\u0431) \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f,<br \/>\u0432) \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043a \u0431\u043e\u0442\u0443,<br \/>\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443. \u041f\u0443\u0441\u0442\u044c \u0442\u043e\u0433\u0434\u0430 \u0431\u043e\u0442 \u043d\u0430\u043f\u0438\u0448\u0435\u0442 \u0432 \u044d\u0442\u0443 \u0433\u0440\u0443\u043f\u043f\u0443: &#171;\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0433\u043e\u0441\u043f\u043e\u0434\u0430!&#187;<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 telethon.events.ChatAction.<\/p>\n<p>\u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">from telethon import events  from app import bot  @bot.on(events.ChatAction()) async def on_join(event: events.ChatAction.Event):     if event.is_group and event.user_added and event.user_id == bot.me.id: \t\t\t\tawait bot.send_message(event.chat.id, '\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0433\u043e\u0441\u043f\u043e\u0434\u0430!')<\/code><\/pre>\n<p>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>@bot.on<\/code> \u043c\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u044e. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 &#171;\u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438&#187;. \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 \u2014 \u0444\u0430\u0439\u043b <code>__main__.py<\/code> \u0412 \u043d\u0451\u043c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e run:<\/p>\n<pre><code class=\"python\">from app import run  run()<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0411\u043e\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c.<\/p>\n<pre><code>$ python -m app<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/881\/c64\/d53\/881c64d530a921ef300451229b1d7479.png\" width=\"473\" height=\"119\"><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430\u0445<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435\u043c:<\/p>\n<pre><code class=\"python\">@bot.on(events.ChatAction(func=lambda e: e.is_group and e.user_added and e.user_id == bot.me.id)) async def on_join(event: events.ChatAction.Event):     await event.respond('\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0433\u043e\u0441\u043f\u043e\u0434\u0430!')<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 ChatAction \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>func<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0421\u044e\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0445\u0435\u043d\u0434\u043b\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>event.respond<\/code>. \u041e\u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0447\u0430\u0442, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u0451\u043b event. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>bot.send_message<\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f! \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0440\u0438\u0433\u0433\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 &#171;\u0422\u044b \u043a\u0442\u043e?&#187;:<\/p>\n<pre><code class=\"python\">... from telethon.tl.custom import Message ...  @bot.on(events.NewMessage(func=lambda e: e.text.lower() == '\u0442\u044b \u043a\u0442\u043e?')) async def who_are_you(event: Message):     await event.respond('\u042f \u0443\u043c\u043d\u044b\u0439, \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439, \u0432 \u043c\u0435\u0440\u0443 \u0443\u043f\u0438\u0442\u0430\u043d\u043d\u044b\u0439 \u043c\u0443\u0436\u0447\u0438\u043d\u0430 \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u0440\u0430\u0441\u0446\u0432\u0435\u0442\u0435 \u0441\u0438\u043b!') <\/code><\/pre>\n<p>Message \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f NewMessage.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0431\u043e\u0442 \u0432\u0438\u0434\u0435\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f-\u043d\u0435-\u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0435\u0433\u043e \u0430\u0434\u043c\u0438\u043d\u043e\u043c \u0438\u043b\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/543676\/#privacy-mode\" rel=\"noopener noreferrer nofollow\">privacy mode<\/a>.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043a\u043e\u0442\u0438\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0438\u0434\u0430\u0435\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0441 \u043a\u043e\u0442\u0438\u043a\u043e\u043c \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \/cat.<\/p>\n<pre><code class=\"python\">... from telethon.tl.custom import Message ...  @bot.on(events.NewMessage(func=lambda e: e.text.lower() == '\/cat')) async def send_cat(event: Message):     await bot.send_message(event.chat.id, file='path\/to\/cat.png') <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u0435\u0451 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/docs.telethon.dev\/en\/latest\/modules\/client.html#telethon.client.uploads.UploadMethods.upload_file\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u043e\u0434\u0430 bot.upload_file()<\/a> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0411\u0440\u043e\u0441\u043e\u043a \u043a\u0443\u0431\u0438\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0438\u0434\u0430\u0435\u0442 \u043a\u0443\u0431\u0438\u043a \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \/dice (\u0410\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u044d\u043c\u043e\u0434\u0437\u0438 \u043a\u0443\u0431\u0438\u043a\u0430)<\/p>\n<pre><code class=\"python\">... from telethon.tl.custom import Message from telethon.tl.types import InputMediaDice ...  @bot.on(events.NewMessage(func=lambda e: e.text.lower() == '\/dice')) async def send_dice(event: Message):     await bot.send_message(event.chat.id, file=InputMediaDice('?'))<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/079\/4ae\/d23\/0794aed2342e8fd3fb7a9bac2acb3602.png\" width=\"470\" height=\"243\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0448\u043b\u0438 \u0432 \u0447\u0430\u0442:<\/p>\n<pre><code class=\"python\">@bot.on(events.ChatAction(func=lambda e: (e.user_added or e.user_joined) and e.user_id != bot.me.id)) async def greet(event: events.ChatAction.Event):     await event.respond('\u041f\u0440\u0438\u0432\u0435\u0442\u0438\u043a!') <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041d\u043e \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u0441\u044e\u0434\u0430 \u043d\u0435 \u0437\u0430 \u044d\u0442\u0438\u043c. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0438\u0447\u0438 \u0434\u043b\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0433\u0440\u0443\u043f\u043f\u044b! \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c \u0430\u0434\u043c\u0438\u043d\u043e\u0432 \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0433\u0440\u0443\u043f\u043f\u044b. \u042d\u0442\u0438\u043c \u043c\u044b \u0437\u0430\u0439\u043c\u0451\u043c\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430. \u041c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0445\u0438\u0442\u0440\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u0434\u043c\u0438\u043d\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442.<\/p>\n<hr>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/Tm-A-T\/admin-bot-tutorial\/tree\/chapter-1\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043a\u043e\u0434 \u043d\u0430 GitHub<\/a>. \u041b\u044e\u0431\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043d\u0430 \u043d\u0438\u0445 \u043e\u0442\u0432\u0435\u0447\u0443 \u044f \u0438\u043b\u0438 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0451. \u0418 \u0441\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"http:\/\/t.me\/vanutp\" rel=\"noopener noreferrer nofollow\">vanutp<\/a> \u0437\u0430 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \ud83d\ude42<\/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\/553968\/\"> https:\/\/habr.com\/ru\/post\/553968\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u0440\u0443\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430-\u043c\u043e\u0434\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0447\u0430\u0442\u043e\u0432 \u043d\u0430 Python. \u041f\u0443\u0441\u0442\u044c \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u0442, \u0431\u0430\u043d\u0438\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043c \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0447\u0430\u0442\u0430 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u041c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043b\u0438\u043c\u0438\u0442\u043e\u0432 \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043d\u0430\u0443\u0447\u0438\u043c \u0431\u043e\u0442\u0430 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c Python \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 Telethon \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Telegram API (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0438\u0436\u0435) \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 Databases \u0441 SQLAlchemy Core \u0434\u043b\u044f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0443\u0436\u0435 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438).<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/Tm-A-T\/admin-bot-tutorial\/tree\/chapter-1\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0434 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043d\u0430 GitHub<\/a>.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u043e\u0442\u0430<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043e\u0442\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430 <a href=\"http:\/\/t.me\/botfather\" rel=\"noopener noreferrer nofollow\">BotFather<\/a>.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u043d \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442 \u0432\u0430\u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u043c\u044f \u0431\u043e\u0442\u0430 \u0438 \u0435\u0433\u043e \u044e\u0437\u0435\u0440\u043d\u0435\u0439\u043c. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0441\u0432\u043e\u0435\u0433\u043e &#171;\u0420\u043e\u0431\u043e\u0442\u0430 \u0412\u0430\u0441\u044e 2077&#187;, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0442\u043e\u043a\u0435\u043d \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0431\u043e\u0442\u043e\u043c.  <\/p>\n<h2>Telegram API<\/h2>\n<p>\u0412 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/543676\" rel=\"noopener noreferrer nofollow\">&#171;\u0412\u0441\u0451, \u043e \u0447\u0451\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u0431\u043e\u0442\u043e\u0432&#187;<\/a> \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u043b, \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f Telegram API \u043e\u0442 Telegram Bot API.<\/p>\n<p>Bot API \u0431\u043e\u043b\u0435\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u043e\u0442\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0433\u0440\u0443\u043f\u043f\u044b \u0438\u043b\u0438 \u0441\u0442\u0430\u0440\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0418 \u0445\u043e\u0442\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u044d\u0442\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f, \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e Telegram API. \u0410 \u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u043a\u0430\u043a \u043e\u0431\u0438\u0434\u043d\u043e: \u0432\u043e\u0442 \u043f\u0438\u0448\u0435\u0442\u0435 \u0432\u044b \u0431\u043e\u0442\u0430, \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0435 \u0435\u0433\u043e, \u0438 \u0432\u0434\u0440\u0443\u0433 \u0432\u0430\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u0430 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0444\u0438\u0447\u0430, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c API. \u0418 \u0441\u0440\u0430\u0437\u0443 \u0433\u0440\u0443\u0441\u0442\u043d\u0435\u043d\u044c\u043a\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Telegram API \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/docs.telethon.dev\/\" rel=\"noopener noreferrer nofollow\">Telethon<\/a>:<\/p>\n<pre><code>$ pip install telethon<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a Telegram API \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0430, \u0434\u043b\u044f \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 my.telegram.org. \u0414\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 API \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u043e\u0442\u043e\u0432. <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0424\u043e\u0440\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 api_id \u0438 api_hash \u0432\u0430\u0448\u0435\u0433\u043e &#171;\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f&#187;. \u041e\u043d\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>app\/     __init__.py     __main__.py     handlers.py config.py<\/code><\/pre>\n<p>\u0412 <code>handlers.py<\/code> \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u0412 <code>config.py<\/code> \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0435\u0433\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c:<\/p>\n<pre><code class=\"python\">BOT_TOKEN = '\u0442\u043e\u043a\u0435\u043d-\u0432\u0430\u0448\u0435\u0433\u043e-\u0431\u043e\u0442\u0430' API_ID = 123456789 API_HASH = '\u0432\u0430\u0448\u0435-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435'<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043b\u044e\u0431\u044b\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u0430\u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u041d\u043e \u044f \u0431\u0443\u0434\u0443 \u0434\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b config.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e <code>__init__.py<\/code>. \u0413\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 telethon \u2014 \u043a\u043b\u0430\u0441\u0441 <code>TelegramClient<\/code>. \u0418\u043c\u0435\u043d\u043d\u043e \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430.<\/p>\n<p>\u041f\u043e\u0437\u0436\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0431\u043e\u0442\u0435 (\u0435\u0433\u043e id, \u044e\u0437\u0435\u0440\u043d\u0435\u0439\u043c \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 TelegramClient:<\/p>\n<pre><code class=\"python\">import logging from telethon import TelegramClient import config  class Bot(TelegramClient):     def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.me = None  # \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0431\u043e\u0442\u0435  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0431\u043e\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u0430\u043d\u043d\u044b\u0435 API bot = Bot('bot', config.API_ID, config.API_HASH)<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u043e\u0442\u0430 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u0427\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u043e\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u043e\u043a\u0435\u043d\u0430. (\u0423\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <code>'bot'<\/code>\u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u0441\u0435\u0441\u0441\u0438\u0438: \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.)<\/p>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0431\u043e\u0442\u0430 <code>parse_mode<\/code> \u2014 \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u043e\u0439 (\u0436\u0438\u0440\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043a\u0443\u0440\u0441\u0438\u0432, \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435).  \u0412\u044b\u0431\u0435\u0440\u0435\u043c HTML.<\/p>\n<p>\u0418 \u0437\u0430\u043e\u0434\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043b\u043e\u0433\u0433\u0438\u043d\u0433:<\/p>\n<pre><code class=\"python\">bot.parse_mode = 'HTML' logging.basicConfig(level=logging.INFO)<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 bot \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b: \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c app.handlers (\u0441\u0435\u0439\u0447\u0430\u0441 \u0432 \u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442).<\/p>\n<pre><code class=\"python\">import app.handlers<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0430\u043f\u0434\u0435\u0439\u0442\u044b.<\/p>\n<pre><code class=\"python\">async def start():     # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443     await bot.connect()          # \u0412\u043e\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u043a\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 sign_in \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0431\u043e\u0442\u0435. \u041c\u044b \u0441\u0440\u0430\u0437\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0435\u0451 \u0432 bot.me     bot.me = await bot.sign_in(bot_token=config.BOT_TOKEN)          # \u041d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u043f\u0434\u0435\u0439\u0442\u044b \u043e\u0442 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b     await bot.run_until_disconnected() <\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0444\u0443\u043d\u043a\u0446\u0438\u044e run, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e start:<\/p>\n<pre><code class=\"python\">def run():     bot.loop.run_until_complete(start())<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u043f\u0435\u0440\u044c __init__.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import logging  from telethon import TelegramClient  import config   class Bot(TelegramClient):     def __init__(self, *args):         super().__init__(*args)         self.me = None   bot = Bot('bot', config.API_ID, config.API_HASH) bot.parse_mode = 'HTML' logging.basicConfig(level=logging.INFO)  import app.handlers   async def start():     await bot.connect()     bot.me = await bot.sign_in(bot_token=config.BOT_TOKEN)     await bot.run_until_disconnected()   def run():     bot.loop.run_until_complete(start()) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430\u043c.<\/p>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u0432 <a href=\"http:\/\/handlers.py\" rel=\"noopener noreferrer nofollow\">handlers.py<\/a> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0431\u0443\u0434\u0435\u043c \u043b\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0431\u043e\u0442\u0430 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443.<\/p>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u043e\u0432\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 &#171;\u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0433\u0440\u0443\u043f\u043f\u0443&#187;, &#171;\u0438\u0437\u043c\u0435\u043d\u0438\u043b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u0440\u0443\u043f\u043f\u044b&#187;, &#171;\u0437\u0430\u043a\u0440\u0435\u043f\u0438\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f&#187; \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435). \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<br \/>\u0430) \u0431\u044b\u043b\u043e \u0432 \u0433\u0440\u0443\u043f\u043f\u0435,<br \/>\u0431) \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f,<br \/>\u0432) \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043a \u0431\u043e\u0442\u0443,<br \/>\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443. \u041f\u0443\u0441\u0442\u044c \u0442\u043e\u0433\u0434\u0430 \u0431\u043e\u0442 \u043d\u0430\u043f\u0438\u0448\u0435\u0442 \u0432 \u044d\u0442\u0443 \u0433\u0440\u0443\u043f\u043f\u0443: &#171;\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0433\u043e\u0441\u043f\u043e\u0434\u0430!&#187;<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 telethon.events.ChatAction.<\/p>\n<p>\u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">from telethon import events  from app import bot  @bot.on(events.ChatAction()) async def on_join(event: events.ChatAction.Event):     if event.is_group and event.user_added and event.user_id == bot.me.id: \t\t\t\tawait bot.send_message(event.chat.id, '\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0433\u043e\u0441\u043f\u043e\u0434\u0430!')<\/code><\/pre>\n<p>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>@bot.on<\/code> \u043c\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u044e. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 &#171;\u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438&#187;. \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 \u2014 \u0444\u0430\u0439\u043b <code>__main__.py<\/code> \u0412 \u043d\u0451\u043c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e run:<\/p>\n<pre><code class=\"python\">from app import run  run()<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0411\u043e\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c.<\/p>\n<pre><code>$ python -m app<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430\u0445<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435\u043c:<\/p>\n<pre><code class=\"python\">@bot.on(events.ChatAction(func=lambda e: e.is_group and e.user_added and e.user_id == bot.me.id)) async def on_join(event: events.ChatAction.Event):     await event.respond('\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0433\u043e\u0441\u043f\u043e\u0434\u0430!')<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 ChatAction \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>func<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0421\u044e\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0445\u0435\u043d\u0434\u043b\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>event.respond<\/code>. \u041e\u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0447\u0430\u0442, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u0451\u043b event. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>bot.send_message<\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f! \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0440\u0438\u0433\u0433\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 &#171;\u0422\u044b \u043a\u0442\u043e?&#187;:<\/p>\n<pre><code class=\"python\">... from telethon.tl.custom import Message ...  @bot.on(events.NewMessage(func=lambda e: e.text.lower() == '\u0442\u044b \u043a\u0442\u043e?')) async def who_are_you(event: Message):     await event.respond('\u042f \u0443\u043c\u043d\u044b\u0439, \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439, \u0432 \u043c\u0435\u0440\u0443 \u0443\u043f\u0438\u0442\u0430\u043d\u043d\u044b\u0439 \u043c\u0443\u0436\u0447\u0438\u043d\u0430 \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u0440\u0430\u0441\u0446\u0432\u0435\u0442\u0435 \u0441\u0438\u043b!') <\/code><\/pre>\n<p>Message \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f NewMessage.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0431\u043e\u0442 \u0432\u0438\u0434\u0435\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f-\u043d\u0435-\u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0435\u0433\u043e \u0430\u0434\u043c\u0438\u043d\u043e\u043c \u0438\u043b\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/543676\/#privacy-mode\" rel=\"noopener noreferrer nofollow\">privacy mode<\/a>.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043a\u043e\u0442\u0438\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0438\u0434\u0430\u0435\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0441 \u043a\u043e\u0442\u0438\u043a\u043e\u043c \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \/cat.<\/p>\n<pre><code class=\"python\">... from telethon.tl.custom import Message ...  @bot.on(events.NewMessage(func=lambda e: e.text.lower() == '\/cat')) async def send_cat(event: Message):     await bot.send_message(event.chat.id, file='path\/to\/cat.png') <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u0435\u0451 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/docs.telethon.dev\/en\/latest\/modules\/client.html#telethon.client.uploads.UploadMethods.upload_file\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u043e\u0434\u0430 bot.upload_file()<\/a> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0411\u0440\u043e\u0441\u043e\u043a \u043a\u0443\u0431\u0438\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0438\u0434\u0430\u0435\u0442 \u043a\u0443\u0431\u0438\u043a \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \/dice (\u0410\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u044d\u043c\u043e\u0434\u0437\u0438 \u043a\u0443\u0431\u0438\u043a\u0430)<\/p>\n<pre><code class=\"python\">... from telethon.tl.custom import Message from telethon.tl.types import InputMediaDice ...  @bot.on(events.NewMessage(func=lambda e: e.text.lower() == '\/dice')) async def send_dice(event: Message):     await bot.send_message(event.chat.id, file=InputMediaDice('?'))<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0448\u043b\u0438 \u0432 \u0447\u0430\u0442:<\/p>\n<pre><code class=\"python\">@bot.on(events.ChatAction(func=lambda e: (e.user_added or e.user_joined) and e.user_id != bot.me.id)) async def greet(event: events.ChatAction.Event):     await event.respond('\u041f\u0440\u0438\u0432\u0435\u0442\u0438\u043a!') <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041d\u043e \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u0441\u044e\u0434\u0430 \u043d\u0435 \u0437\u0430 \u044d\u0442\u0438\u043c. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0438\u0447\u0438 \u0434\u043b\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0433\u0440\u0443\u043f\u043f\u044b! \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c \u0430\u0434\u043c\u0438\u043d\u043e\u0432 \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0433\u0440\u0443\u043f\u043f\u044b. \u042d\u0442\u0438\u043c \u043c\u044b \u0437\u0430\u0439\u043c\u0451\u043c\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430. \u041c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0445\u0438\u0442\u0440\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u0434\u043c\u0438\u043d\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442.<\/p>\n<hr>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/Tm-A-T\/admin-bot-tutorial\/tree\/chapter-1\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043a\u043e\u0434 \u043d\u0430 GitHub<\/a>. \u041b\u044e\u0431\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043d\u0430 \u043d\u0438\u0445 \u043e\u0442\u0432\u0435\u0447\u0443 \u044f \u0438\u043b\u0438 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0451. \u0418 \u0441\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"http:\/\/t.me\/vanutp\" rel=\"noopener noreferrer nofollow\">vanutp<\/a> \u0437\u0430 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \ud83d\ude42<\/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\/553968\/\"> https:\/\/habr.com\/ru\/post\/553968\/<\/a><br \/><\/br><\/br><\/br><\/br><\/br><\/p>\n<\/div>\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-321962","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321962","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=321962"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321962\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}