{"id":327766,"date":"2022-01-10T09:01:40","date_gmt":"2022-01-10T09:01:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=327766"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=327766","title":{"rendered":"<span>\u042d\u043a\u043e\u043d\u043e\u043c\u0438\u043c \u0441\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 Telegram \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u043e\u0442\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>TL;DR:<\/strong> \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c Telegram-\u043a\u0430\u043d\u0430\u043b \u0438 \u0432\u044b \u0443\u0441\u0442\u0430\u043b\u0438 \u0440\u0443\u043a\u0430\u043c\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u043a\u0443, \u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0431\u043e\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u0432\u0430\u043c \u0436\u0438\u0437\u043d\u044c.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u0412\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u043e\u043a\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u0443\u0442\u043e\u043c\u043b\u044f\u0435\u0442\" title=\"\u0412\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u043e\u043a\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u0443\u0442\u043e\u043c\u043b\u044f\u0435\u0442\" height=\"191\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5b3\/25f\/645\/5b325f6458740b3bd4b85997313c1584.png\" data-width=\"356\"\/><figcaption>\u0412\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u043e\u043a\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u0443\u0442\u043e\u043c\u043b\u044f\u0435\u0442<\/figcaption><\/figure>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442\u044c \u043a\u0430\u043d\u0430\u043b<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u0442<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u0438\u043f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 &#171;\u041e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f&#187;<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0441\u0442\u0430\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u043d\u043a\u0442\u044b 1, 2, 5. \u041f\u0440\u0438\u0447\u0435\u043c \u043f\u0443\u043d\u043a\u0442 2 \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c \u0434\u043e &#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b&#187;.<\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043e\u0431\u0438\u043b\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0445 \u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 (\u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u043b\u0430\u0442\u043d\u044b\u043c\u0438) \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0438\u043c\u0438 \u043c\u043e\u0436\u0435\u0442, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 (\u0432\u0438\u0434\u0435\u043e, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e), \u0430 \u043e\u043d \u0431\u044b \u0441\u0430\u043c \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u0438\u0445 \u0432 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430. <\/p>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u043e\u0442\u0443 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0432 \u043a\u0430\u043d\u0430\u043b\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u0414\u0443\u0440\u043e\u0432, \u043f\u043e\u0447\u0435\u043c\u0443?\" title=\"\u0414\u0443\u0440\u043e\u0432, \u043f\u043e\u0447\u0435\u043c\u0443?\" height=\"31\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aa5\/684\/130\/aa5684130d5c11427cfaba8a07285f8c.png\" data-width=\"582\"\/><figcaption>\u0414\u0443\u0440\u043e\u0432, \u043f\u043e\u0447\u0435\u043c\u0443?<\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0442\u043b\u043e\u0436\u043a\u0438 \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c.<\/p>\n<h2>\u0418\u0434\u0435\u044f<\/h2>\n<p>\u0423 \u043b\u044e\u0431\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 Telegram, \u0435\u0441\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 fileId. \u0415\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0431\u043e\u0442\u0443 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e, \u0442\u043e \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 id \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438\" title=\"\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438\" height=\"220\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/200\/cfd\/4c5\/200cfd4c5cf7ea9f7a749caee7573f1e.png\" data-width=\"714\"\/><figcaption>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438<\/figcaption><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u0440\u0435\u043c\u044f, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 fileId, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0441\u0442 \u0432 \u043a\u0430\u043d\u0430\u043b.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n<p>\u0411\u043e\u0442\u0430 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Spring Boot \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/rubenlagus\/TelegramBots\" rel=\"noopener noreferrer nofollow\">TelegramBots<\/a>,. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0411\u0414 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c PostgreSQL. \u041d\u0430 <a href=\"https:\/\/start.spring.io\/\" rel=\"noopener noreferrer nofollow\">Spring Initializr<\/a> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"892\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/360\/953\/031\/360953031abbd2b8e3f9f59681e2d316.png\" data-width=\"1507\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 IDE. \u0412 <code>build.gradle<\/code> \u0432 \u0442\u0435\u0433<code>dependencies<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u0442\u0430\u043c\u0438:<\/p>\n<pre><code>implementation 'org.telegram:telegrambots-spring-boot-starter:5.5.0'<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u043d\u0430\u0448\u0435\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0411\u0414. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 <code>application.yaml<\/code> \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c:<\/p>\n<pre><code class=\"yaml\">spring:   datasource:     url: ${SPRING_DATASOURCE_URL:jdbc:postgresql:\/\/localhost:5432\/postgres}<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0411\u0414:<\/p>\n<pre><code class=\"java\">@Configuration public class DatabaseConfig {      @Value(\"${spring.datasource.url}\")     private String dbUrl;      @Bean     public DataSource dataSource() {         HikariConfig config = new HikariConfig();         config.setJdbcUrl(dbUrl);         return new HikariDataSource(config);     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438:<\/p>\n<figure class=\"float\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"124\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/220\/fd8\/5a8\/220fd85a8c71540caab02af4c866ebfb.png\" data-width=\"339\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"yaml\">databaseChangeLog:   - changeSet:       id: 1-add-record       author: ananac       changes:         - createTable:             tableName: record             columns:               - column:                   name: id                   type: bigint                   constraints:                     primaryKey: true                     nullable: false               - column:                   name: file_id                   type: varchar(255)                   constraints:                     nullable: true               - column:                   name: comment                   type: text                   constraints:                     nullable: true               - column:                   name: data_type                   type: varchar(15)                   constraints:                     nullable: false               - column:                   name: create_date_time                   type: timestamp                   constraints:                     nullable: false               - column:                   name: post_date_time                   type: timestamp                   constraints:                     nullable: true               - column:                   name: author                   type: varchar(255)                   constraints:                     nullable: false<\/code><\/pre>\n<pre><code class=\"yaml\">databaseChangeLog:   - include:       file: db\/changelog\/1-add-record.yaml<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u043a\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u0438 \u0432 \u0411\u0414 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u0430\u0448\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u043e\u0432. <\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u043e\u0442\u0430<\/h2>\n<p>\u0418\u0434\u0435\u043c \u043a @BotFather, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>\/newbot<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c API \u0442\u043e\u043a\u0435\u043d. \u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>application.yaml<\/code>, \u0437\u0430\u043e\u0434\u043d\u043e \u0443\u043a\u0430\u0436\u0435\u043c \u0441\u0432\u043e\u0439 userId \u0438 chatId \u043a\u0430\u043d\u0430\u043b\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0441\u0442\u0438\u0442\u044c. \u0412\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/api.telegram.org\/bot1686968362:AAGCx-WDvkT_u720KvEeRZL9nyRbhtkIhG8\/getUpdates\" rel=\"noopener noreferrer nofollow\">https:\/\/api.telegram.org\/bot&lt;\u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c_\u0442\u043e\u043a\u0435\u043d_\u0431\u043e\u0442\u0430>\/getUpdates<\/a>. \u0422\u0430\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u044d\u0432\u0435\u043d\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u0431\u043e\u0442\u043e\u043c.<\/p>\n<pre><code class=\"yaml\">telegram:   name: botname   token: 1793090787:AaaaAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaa   chatId: -1948372984327   adminId: 265765765<\/code><\/pre>\n<h2>\u041f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443<\/h2>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<pre><code class=\"java\">@Entity @Table(name = \"record\") @Data @RequiredArgsConstructor public class Record {     @Id     private long id;     private String fileId;     private String comment;     private String dataType;     private LocalDateTime createDateTime;     private LocalDateTime postDateTime;     private String author; }<\/code><\/pre>\n<p>\u0418 JPA-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043d\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438:<\/p>\n<pre><code class=\"java\">@Repository public interface RecordRepository extends JpaRepository&lt;Record, Long> {      @Query(\"select r from Record r where r.createDateTime = (select min(r1.createDateTime) from Record r1 where r1.postDateTime = null)\")     Optional&lt;Record> getFirstRecordInQueue();      @Query(\"select r from Record r where r.postDateTime = (select max(r1.postDateTime) from Record r1)\")     Optional&lt;Record> getLastPostedRecord();      @Query(\"select count(*) from Record r where r.postDateTime = null\")     long getNumberOfScheduledPosts();      @Transactional     @Modifying     @Query(\"delete from Record r where r.postDateTime = null\")     void clear();  }<\/code><\/pre>\n<p>\u0417\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 <code>TelegramLongPollingBot<\/code>. \u0412 \u043d\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u041c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0441 \u0431\u043e\u0442\u043e\u043c \u043c\u043e\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e userId:<\/p>\n<pre><code class=\"java\">@Component @Getter @RequiredArgsConstructor public class TelegramBotHandler extends TelegramLongPollingBot {     private final RecordRepository recordRepository;      @Value(\"${telegram.name}\")     private String name;      @Value(\"${telegram.token}\")     private String token;      @Value(\"${telegram.chatId}\")     private String chatId;      @Value(\"${telegram.adminId}\")     private Set&lt;Long> adminId;      @Override     public String getBotUsername() {         return name;     }      @Override     public String getBotToken() {         return token;     }      @Override     public void onUpdateReceived(Update update) {         if (update.getMessage() != null) {             Long userId = update.getMessage().getFrom().getId();             if (adminId.contains(userId)) {             processMessage(update.getMessage());             } else {                 reply(userId, \"Permission denied\");             }         }     }        private void reply(Long chatId, String text) {         try {             SendMessage sendMessage = new SendMessage();             sendMessage.setChatId(String.valueOf(chatId));             sendMessage.setText(text);             execute(sendMessage);         } catch (TelegramApiException e) {             e.printStackTrace();         }     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430 \u0432 \u0411\u0414. \u041f\u043e\u043a\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0444\u043e\u0442\u043e, \u043d\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0432\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u043b\u0435\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438, \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439:<\/p>\n<pre><code class=\"java\">    private void processMessage(Message message) {         Long chatId = message.getChatId();         if (message.getPhoto() != null &amp;&amp; !message.getPhoto().isEmpty()) {             Record record = buildRecord(message);             recordRepository.save(record);             reply(chatId, \"\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u043e\u0442\u043b\u043e\u0436\u043a\u0435: \" + recordRepository.getNumberOfScheduledPosts());         } else {             reply(chatId, \"\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u043e\u0442\u043e\");         }     }     private Record buildRecord(Message message) {         Record record = new Record();         String fileId = getLargestFileId(message);         record.setFileId(fileId);         record.setComment(message.getCaption());         record.setDataType(\"PHOTO\");         record.setId(message.getMessageId());         record.setCreateDateTime(LocalDateTime.now());         record.setAuthor(message.getFrom().getUserName());         return record;     }      private String getLargestFileId(Message message) {         return message.getPhoto().stream()                 .max(Comparator.comparing(PhotoSize::getFileSize))                 .orElse(null)                 .getFileId();     }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u0442 \u0432 \u0431\u0430\u0437\u0443 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u043e\u0441\u0442\u0438\u043d\u0433\u0443. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>@Scheduled(fixedDelayString = \"60000\")<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u0443\u044e \u043c\u0438\u043d\u0443\u0442\u0443. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@EnableScheduling<\/code> \u043d\u0430 \u043d\u0430\u0448 Application \u043a\u043b\u0430\u0441\u0441. \u0414\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043f\u043e\u0441\u0442\u0438\u043d\u0433\u0430 \u0432 <code>application.yaml<\/code> \u0443\u043a\u0430\u0436\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 120 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<pre><code class=\"java\">@Component @RequiredArgsConstructor public class RecordService {     private final RecordRepository recordRepository;     private final TelegramBotHandler botHandler;      @Value(\"${schedule.postingInterval}\")     private long postingInterval;      @Scheduled(fixedDelayString = \"60000\")     private void run() {         Optional&lt;Record> recordToPost = recordRepository.getFirstRecordInQueue();         if (recordToPost.isPresent()) {             Optional&lt;Record> lastPostedRecordOptional = recordRepository.getLastPostedRecord();             if (lastPostedRecordOptional.isPresent()) {                 Record lastPostedRecord = lastPostedRecordOptional.get();                 Duration duration = Duration.between(lastPostedRecord.getPostDateTime(), LocalDateTime.now());                 if (duration.toMinutes() >= postingInterval) {                     Record record = recordToPost.get();                     botHandler.sendPhoto(record);                 }             } else {                 Record record = recordToPost.get();                 botHandler.sendPhoto(record);             }         }     } }<\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443 \u0438 \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0411\u0414 \u043d\u0435\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u044b. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u0442\u044b \u0435\u0441\u0442\u044c, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u043b\u0438 120 \u043c\u0438\u043d\u0443\u0442 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043e \u043f\u043e\u0441\u0442\u0438\u043d\u0433\u0435. \u0422\u0430\u043a\u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u0411\u0414.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0443 \u043a\u043e\u043c\u0430\u043d\u0434, \u0447\u0442\u043e\u0431\u044b \u0441 \u0431\u043e\u0442\u043e\u043c \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"317\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1d4\/503\/942\/1d4503942da54f655f4b59a5a8c9cb26.png\" data-width=\"375\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438\u0445 \u0432 \u043a\u043e\u0434\u0435. \u041a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043c\u0438\u0441\u043a\u043b\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"java\">    private void processMessage(Message message) {         Long chatId = message.getChatId();         if (message.getPhoto() != null &amp;&amp; !message.getPhoto().isEmpty()) {             Record record = buildRecord(message);             recordRepository.save(record);                         reply(chatId, \"\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u043e\u0442\u043b\u043e\u0436\u043a\u0435: \" + recordRepository.getNumberOfScheduledPosts());         } else if (message.getText() != null) {             switch (message.getText()) {                 case \"\/info\": {                     reply(chatId, \"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u043e\u0442\u043b\u043e\u0436\u043a\u0435: \" + recordRepository.getNumberOfScheduledPosts());                     break;                 }                 case \"\/clear\": {                     reply(chatId, \"\u0427\u0442\u043e\u0431\u044b \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0448\u0438 \/delete\");                     break;                 }                 case \"\/delete\": {                     recordRepository.clear();                     reply(chatId, \"\u041e\u0447\u0438\u0449\u0435\u043d\u043e. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u043e\u0442\u043b\u043e\u0436\u043a\u0435: \" + recordRepository.getNumberOfScheduledPosts());                     break;                 }                 default: {                     break;                 }             }         } else {             reply(chatId, \"\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u043e\u0442\u043e\");         }     }      public void sendPhoto(Record record) {         try {             SendPhoto sendPhoto = new SendPhoto();             sendPhoto.setChatId(chatId);             sendPhoto.setPhoto(new InputFile(record.getFileId()));             execute(sendPhoto);             afterPost(record);         } catch (TelegramApiException e) {             e.printStackTrace();         }     }      private void afterPost(Record record) {         record.setPostDateTime(LocalDateTime.now());         recordRepository.save(record);     }<\/code><\/pre>\n<h2>\u0417\u0430\u043f\u0443\u0441\u043a \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430<\/h2>\n<p>\u041f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u041f\u043e\u0441\u0442\u044b \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f\" title=\"\u041f\u043e\u0441\u0442\u044b \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f\" height=\"726\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/df7\/fbe\/c7b\/df7fbec7b55ea987d30e7318ace649b7.png\" data-width=\"370\"\/><figcaption>\u041f\u043e\u0441\u0442\u044b \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f<\/figcaption><\/figure>\n<p>\u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u0432 \u043e\u0431\u043b\u0430\u043a\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 Heroku (\u0447\u0442\u043e \u0438 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u0431\u043e\u0442\u043e\u043c) \u043f\u043e <a href=\"https:\/\/devcenter.heroku.com\/articles\/deploying-spring-boot-apps-to-heroku\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c\u0443 \u0433\u0430\u0439\u0434\u0443<\/a>. \u0421 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/Ananac\/otlojka-bot\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. <\/p>\n<\/div>\n<\/div>\n<p> <!----> <!----><br \/> \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\/596579\/\"> https:\/\/habr.com\/ru\/post\/596579\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>TL;DR:<\/strong> \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c Telegram-\u043a\u0430\u043d\u0430\u043b \u0438 \u0432\u044b \u0443\u0441\u0442\u0430\u043b\u0438 \u0440\u0443\u043a\u0430\u043c\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u043a\u0443, \u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0431\u043e\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u0432\u0430\u043c \u0436\u0438\u0437\u043d\u044c.<\/p>\n<figure class=\"\"><figcaption>\u0412\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u043e\u043a\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u0443\u0442\u043e\u043c\u043b\u044f\u0435\u0442<\/figcaption><\/figure>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442\u044c \u043a\u0430\u043d\u0430\u043b<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u0442<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u0438\u043f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 &#171;\u041e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f&#187;<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0441\u0442\u0430\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u043d\u043a\u0442\u044b 1, 2, 5. \u041f\u0440\u0438\u0447\u0435\u043c \u043f\u0443\u043d\u043a\u0442 2 \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c \u0434\u043e &#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b&#187;.<\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043e\u0431\u0438\u043b\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0445 \u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 (\u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u043b\u0430\u0442\u043d\u044b\u043c\u0438) \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0438\u043c\u0438 \u043c\u043e\u0436\u0435\u0442, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 (\u0432\u0438\u0434\u0435\u043e, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e), \u0430 \u043e\u043d \u0431\u044b \u0441\u0430\u043c \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u0438\u0445 \u0432 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430. <\/p>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u043e\u0442\u0443 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0432 \u043a\u0430\u043d\u0430\u043b\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<figure class=\"full-width\"><figcaption>\u0414\u0443\u0440\u043e\u0432, \u043f\u043e\u0447\u0435\u043c\u0443?<\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0442\u043b\u043e\u0436\u043a\u0438 \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c.<\/p>\n<h2>\u0418\u0434\u0435\u044f<\/h2>\n<p>\u0423 \u043b\u044e\u0431\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 Telegram, \u0435\u0441\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 fileId. \u0415\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0431\u043e\u0442\u0443 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e, \u0442\u043e \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 id \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443:<\/p>\n<figure class=\"full-width\"><figcaption>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438<\/figcaption><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u0440\u0435\u043c\u044f, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 fileId, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0441\u0442 \u0432 \u043a\u0430\u043d\u0430\u043b.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n<p>\u0411\u043e\u0442\u0430 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Spring Boot \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/rubenlagus\/TelegramBots\" rel=\"noopener noreferrer nofollow\">TelegramBots<\/a>,. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0411\u0414 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c PostgreSQL. \u041d\u0430 <a href=\"https:\/\/start.spring.io\/\" rel=\"noopener noreferrer nofollow\">Spring Initializr<\/a> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 IDE. \u0412 <code>build.gradle<\/code> \u0432 \u0442\u0435\u0433<code>dependencies<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u0442\u0430\u043c\u0438:<\/p>\n<pre><code>implementation 'org.telegram:telegrambots-spring-boot-starter:5.5.0'<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u043d\u0430\u0448\u0435\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0411\u0414. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 <code>application.yaml<\/code> \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c:<\/p>\n<pre><code class=\"yaml\">spring:   datasource:     url: ${SPRING_DATASOURCE_URL:jdbc:postgresql:\/\/localhost:5432\/postgres}<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0411\u0414:<\/p>\n<pre><code class=\"java\">@Configuration public class DatabaseConfig {      @Value(\"${spring.datasource.url}\")     private String dbUrl;      @Bean     public DataSource dataSource() {         HikariConfig config = new HikariConfig();         config.setJdbcUrl(dbUrl);         return new HikariDataSource(config);     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438:<\/p>\n<figure class=\"float\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"yaml\">databaseChangeLog:   - changeSet:       id: 1-add-record       author: ananac       changes:         - createTable:             tableName: record             columns:               - column:                   name: id                   type: bigint                   constraints:                     primaryKey: true                     nullable: false               - column:                   name: file_id                   type: varchar(255)                   constraints:                     nullable: true               - column:                   name: comment                   type: text                   constraints:                     nullable: true               - column:                   name: data_type                   type: varchar(15)                   constraints:                     nullable: false               - column:                   name: create_date_time                   type: timestamp                   constraints:                     nullable: false               - column:                   name: post_date_time                   type: timestamp                   constraints:                     nullable: true               - column:                   name: author                   type: varchar(255)                   constraints:                     nullable: false<\/code><\/pre>\n<pre><code class=\"yaml\">databaseChangeLog:   - include:       file: db\/changelog\/1-add-record.yaml<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u043a\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u0438 \u0432 \u0411\u0414 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u0430\u0448\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u043e\u0432. <\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u043e\u0442\u0430<\/h2>\n<p>\u0418\u0434\u0435\u043c \u043a @BotFather, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>\/newbot<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c API \u0442\u043e\u043a\u0435\u043d. \u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>application.yaml<\/code>, \u0437\u0430\u043e\u0434\u043d\u043e \u0443\u043a\u0430\u0436\u0435\u043c \u0441\u0432\u043e\u0439 userId \u0438 chatId \u043a\u0430\u043d\u0430\u043b\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0441\u0442\u0438\u0442\u044c. \u0412\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/api.telegram.org\/bot1686968362:AAGCx-WDvkT_u720KvEeRZL9nyRbhtkIhG8\/getUpdates\" rel=\"noopener noreferrer nofollow\">https:\/\/api.telegram.org\/bot&lt;\u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c_\u0442\u043e\u043a\u0435\u043d_\u0431\u043e\u0442\u0430>\/getUpdates<\/a>. \u0422\u0430\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u044d\u0432\u0435\u043d\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u0431\u043e\u0442\u043e\u043c.<\/p>\n<pre><code class=\"yaml\">telegram:   name: botname   token: 1793090787:AaaaAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaa   chatId: -1948372984327   adminId: 265765765<\/code><\/pre>\n<h2>\u041f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443<\/h2>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<pre><code class=\"java\">@Entity @Table(name = \"record\") @Data @RequiredArgsConstructor public class Record {     @Id     private long id;     private String fileId;     private String comment;     private String dataType;     private LocalDateTime createDateTime;     private LocalDateTime postDateTime;     private String author; }<\/code><\/pre>\n<p>\u0418 JPA-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043d\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438:<\/p>\n<pre><code class=\"java\">@Repository public interface RecordRepository extends JpaRepository&lt;Record, Long> {      @Query(\"select r from Record r where r.createDateTime = (select min(r1.createDateTime) from Record r1 where r1.postDateTime = null)\")     Optional&lt;Record> getFirstRecordInQueue();      @Query(\"select r from Record r where r.postDateTime = (select max(r1.postDateTime) from Record r1)\")     Optional&lt;Record> getLastPostedRecord();      @Query(\"select count(*) from Record r where r.postDateTime = null\")     long getNumberOfScheduledPosts();      @Transactional     @Modifying     @Query(\"delete from Record r where r.postDateTime = null\")     void clear();  }<\/code><\/pre>\n<p>\u0417\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 <code>TelegramLongPollingBot<\/code>. \u0412 \u043d\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u041c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0441 \u0431\u043e\u0442\u043e\u043c \u043c\u043e\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e userId:<\/p>\n<pre><code class=\"java\">@Component @Getter @RequiredArgsConstructor public class TelegramBotHandler extends TelegramLongPollingBot {     private final RecordRepository recordRepository;      @Value(\"${telegram.name}\")     private String name;      @Value(\"${telegram.token}\")     private String token;      @Value(\"${telegram.chatId}\")     private String chatId;      @Value(\"${telegram.adminId}\")     private Set&lt;Long> adminId;      @Override     public String getBotUsername() {         return name;     }      @Override     public String getBotToken() {         return token;     }      @Override     public void onUpdateReceived(Update update) {         if (update.getMessage() != null) {             Long userId = update.getMessage().getFrom().getId();             if (adminId.contains(userId)) {             processMessage(update.getMessage());             } else {                 reply(userId, \"Permission denied\");             }         }     }        private void reply(Long chatId, String text) {         try {             SendMessage sendMessage = new SendMessage();             sendMessage.setChatId(String.valueOf(chatId));             sendMessage.setText(text);             execute(sendMessage);         } catch (TelegramApiException e) {             e.printStackTrace();         }     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430 \u0432 \u0411\u0414. \u041f\u043e\u043a\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0444\u043e\u0442\u043e, \u043d\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0432\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u043b\u0435\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438, \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439:<\/p>\n<pre><code class=\"java\">    private void processMessage(Message message) {         Long chatId = message.getChatId();         if (message.getPhoto() != null &amp;&amp; !message.getPhoto().isEmpty()) {             Record record = buildRecord(message);             recordRepository.save(record);             reply(chatId, \"\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u043e\u0442\u043b\u043e\u0436\u043a\u0435: \" + recordRepository.getNumberOfScheduledPosts());         } else {             reply(chatId, \"\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u043e\u0442\u043e\");         }     }     private Record buildRecord(Message message) {         Record record = new Record();         String fileId = getLargestFileId(message);         record.setFileId(fileId);         record.setComment(message.getCaption());         record.setDataType(\"PHOTO\");         record.setId(message.getMessageId());         record.setCreateDateTime(LocalDateTime.now());         record.setAuthor(message.getFrom().getUserName());         return record;     }      private String getLargestFileId(Message message) {         return message.getPhoto().stream()                 .max(Comparator.comparing(PhotoSize::getFileSize))                 .orElse(null)                 .getFileId();     }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u0442 \u0432 \u0431\u0430\u0437\u0443 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u043e\u0441\u0442\u0438\u043d\u0433\u0443. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>@Scheduled(fixedDelayString = \"60000\")<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u0443\u044e \u043c\u0438\u043d\u0443\u0442\u0443. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@EnableScheduling<\/code> \u043d\u0430 \u043d\u0430\u0448 Application \u043a\u043b\u0430\u0441\u0441. \u0414\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043f\u043e\u0441\u0442\u0438\u043d\u0433\u0430 \u0432 <code>application.yaml<\/code> \u0443\u043a\u0430\u0436\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 120 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<pre><code class=\"java\">@Component @RequiredArgsConstructor public class RecordService {     private final RecordRepository recordRepository;     private final TelegramBotHandler botHandler;      @Value(\"${schedule.postingInterval}\")     private long postingInterval;      @Scheduled(fixedDelayString = \"60000\")     private void run() {         Optional&lt;Record> recordToPost = recordRepository.getFirstRecordInQueue();         if (recordToPost.isPresent()) {             Optional&lt;Record> lastPostedRecordOptional = recordRepository.getLastPostedRecord();             if (lastPostedRecordOptional.isPresent()) {                 Record lastPostedRecord = lastPostedRecordOptional.get();                 Duration duration = Duration.between(lastPostedRecord.getPostDateTime(), LocalDateTime.now());                 if (duration.toMinutes() >= postingInterval) {                     Record record = recordToPost.get();                     botHandler.sendPhoto(record);                 }             } else {                 Record record = recordToPost.get();                 botHandler.sendPhoto(record);             }         }     } }<\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443 \u0438<\/p>\n<\/div>\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-327766","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327766","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=327766"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327766\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}