{"id":458055,"date":"2025-04-29T15:00:09","date_gmt":"2025-04-29T15:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=458055"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=458055","title":{"rendered":"<span>Telegram\u2011\u0431\u043e\u0442 \u043d\u0430 Supabase<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u0438<\/h3>\n<p>\u041c\u0435\u0441\u044f\u0446 \u043d\u0430\u0437\u0430\u0434 \u044f \u0431\u0430\u043b\u043e\u0432\u0430\u043b\u0441\u044f \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c <strong>Lovable<\/strong>\u00a0\u2014 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u0440\u0438\u043a\u043e\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u043c\u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0411\u0414 \u043d\u0430 Supabase \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0440\u044b \u043a\u043b\u0438\u043a\u043e\u0432: \u0431\u0430\u0437\u0430 Postgres \u0443\u0436\u0435 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f, \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0432\u0441\u0451 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u0438, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e <strong>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e<\/strong> \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u0432\u043e\u0442.<\/p>\n<p>\u041f\u043e\u043a\u0430 \u0449\u0451\u043b\u043a\u0430\u043b UI \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0440\u0430\u0437\u0434\u0435\u043b <em>Functions<\/em>. \u00ab\u0427\u0442\u043e\u2011\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 <em>AWS\u00a0Lambda<\/em>, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u044f\u043c\u043e \u0440\u044f\u0434\u043e\u043c \u0441 \u0431\u0430\u0437\u043e\u0439\u00bb &#8212; \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u044f. \u0418 \u0442\u0430\u043a \u0432 &#171;\u0434\u043e\u043b\u0433\u043e\u043c \u044f\u0449\u0438\u043a\u0435&#187; \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0438\u0434\u0435\u044f \u043f\u043e\u0442\u044b\u043a\u0430\u0442\u044c \u0432 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u0440\u0435\u043b\u0438\u0437 OpenAI\u00a0<strong>Images\u00a0API<\/strong>. \u041c\u044b \u043a\u0430\u043a-\u0442\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u043a\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0432 \u0442\u0435\u043b\u0435\u0433\u0435 \u0434\u043b\u044f \u0440\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0445 \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e ChatGPT-plus \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043b \u043f\u0440\u043e Supabase\u202f\u2192\u202f\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u043d\u0441 \u043f\u043e\u0449\u0443\u043f\u0430\u0442\u044c edge\u2011\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0434\u043d\u044f\u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430.<\/p>\n<p>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u043d\u0430\u043a\u0438\u0434\u0430\u043b \u043c\u044b\u0441\u043b\u0438 \u043f\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u043e\u0442 \u0438 \u043d\u0430 \u0447\u0435\u043c, \u0438 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b ChatGPT \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u0438 \u0422\u0417. \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u043e\u043a \u0438 \u043f\u043b\u044e\u0441-\u043c\u0438\u043d\u0443\u0441 \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u044b\u043b\u043e \u043d\u0430 \u0440\u0443\u043a\u0430\u0445. \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u0448\u0451\u043b \u0432 <strong>Claude<\/strong> \u0447\u0435\u0440\u0435\u0437 OpenRouter \u2014 \u043e\u043d \u0432\u044b\u043f\u043b\u044e\u043d\u0443\u043b \u0441\u043a\u0435\u043b\u0435\u0442 \u043a\u043e\u0434\u0430 \u043f\u043e\u0434  Supabase edge functions. \u0418\u043c\u0435\u044f \u043d\u0430 \u0440\u0443\u043a\u0430\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u044f \u043f\u043e\u0448\u0435\u043b \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u044f\u0441\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>\u0411\u043e\u0442 \u043c\u043e\u0436\u043d\u043e<a href=\"https:\/\/t.me\/StylifAIer_bot\" rel=\"noopener noreferrer nofollow\"> \u043f\u043e\u0442\u044b\u043a\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c<\/a>, \u0430 \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0435\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0435 \u0438 \u043d\u0430 <a href=\"https:\/\/t.me\/databites\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0439 \u043a\u0430\u043d\u0430\u043b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a><\/p>\n<h4>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h4>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d1\/a83\/8fc\/9d1a838fc595e4470abac981e87c089e.png\" alt=\"\" title=\"\" width=\"3430\" height=\"844\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/9d1\/a83\/8fc\/9d1a838fc595e4470abac981e87c089e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d1\/a83\/8fc\/9d1a838fc595e4470abac981e87c089e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e Supabase<\/h4>\n<ol>\n<li>\n<p><strong>Edge Functions<\/strong> \u043d\u0430\u00a0Deno\u00a0\u2014 \u0441\u0443\u043f\u0435\u0440 \u043b\u0435\u0433\u043a\u0438\u0439 \u0434\u0435\u043f\u043b\u043e\u0439 <code>supabase functions deploy bot<\/code> \u0438 \u0433\u043e\u0442\u043e\u0432\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u0417\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u043c\u043d\u0435 Postgres <\/strong>\u2014 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 policies +\u00a0row\u2011level security.<\/p>\n<\/li>\n<li>\n<p><strong>\u0415\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 Storage<\/strong>\u00a0S3\u2014 \u0435\u0441\u043b\u0438 \u0440\u0435\u0448\u0443 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0442\u044f\u043d\u0435\u0442 500\u202f\u0442\u044b\u0441. Edge\u2011\u0438\u043d\u0432\u043e\u043a\u0430\u0446\u0438\u0439\u202f\/\u202f10\u202f\u0413\u0411\u2011\u0442\u0440\u0430\u0444\u0438\u043a\u0430 \u2014 \u043d\u0430 \u0445\u043e\u0431\u0431\u0438\u2011\u0431\u043e\u0442  \u0437\u0430 \u0433\u043b\u0430\u0437\u0430 \u0445\u0432\u0430\u0442\u0430\u0435\u0442.<\/p>\n<\/li>\n<\/ol>\n<h4>\u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c<\/h4>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aa4\/07f\/d5f\/aa407fd5f2103ebec8925f0a78aeb2ab.png\" alt=\"logic model\" title=\"logic model\" width=\"2846\" height=\"1642\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/aa4\/07f\/d5f\/aa407fd5f2103ebec8925f0a78aeb2ab.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aa4\/07f\/d5f\/aa407fd5f2103ebec8925f0a78aeb2ab.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>logic model<\/figcaption><\/div>\n<\/figure>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>users<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0443\u0447\u0451\u0442 TG\u2011\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>channel_subscribers<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u043f\u0440\u043e\u043c\u043e\u2011\u043a\u0430\u043d\u0430\u043b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>sessions<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">FSM (finite state machine\u00a0\u2014 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442)\u2011\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u043e\u0442\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>generations<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043b\u043e\u0433 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0422\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u0447\u0435\u0440\u0435\u0437 \u0438\u0445 \u0443\u0434\u043e\u0431\u043d\u0443\u044e SQL \u0441\u0442\u0443\u0434\u0438\u044e, \u0442\u0430\u043c \u0436\u0435 \u043d\u0430\u043a\u0438\u043d\u0443\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043b-\u0432\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <\/p>\n<h4>Edge\u00a0Function bot<\/h4>\n<ul>\n<li>\n<p><strong>URL<\/strong>\u00a0<code>https:\/\/xyz.supabase.co\/functions\/v1\/bot\/&lt;WEBHOOK_SECRET&gt;<\/code> \u2014 \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0443\u0434\u0430 Telegram \u00ab\u043f\u043e\u0441\u0442\u0443\u0447\u0438\u0442\u0441\u044f\u00bb \u043c\u0435\u0442\u043e\u0434\u043e\u043c POST, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f JSON-\u043e\u0431\u044a\u0435\u043a\u0442 TelegramUpdate \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u0444\u043e\u0442\u043e, callback-\u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c <code>req.method === 'POST'<\/code> \u0438 \u0441\u0435\u043a\u0440\u0435\u0442 \u0432 path.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0441\u0438\u043c <code>TelegramUpdate<\/code>, \u0440\u043e\u0443\u0442\u0438\u043c \u0432\u00a0<code>states.ts<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0431\u043e\u0442\u0430<\/h4>\n<p><code>states.ts<\/code><\/p>\n<pre><code>WAITING_PHOTO \u2500\u25b6 WAITING_PROMPT \u2500\u25b6 GENERATING \u2500\u25b6 WAITING_PHOTO             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 SUBSCRIPTION_OFFER<\/code><\/pre>\n<p>FSM (finite state machine) \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 <code>sessions<\/code> \u2014 \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h2>\u0413\u043b\u0443\u0431\u0436\u0435 \u0432 \u043a\u043e\u0434<\/h2>\n<h4>1. database.ts<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c Supabase\u2011\u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<pre><code>const supabase = createClient(supabaseUrl, supabaseKey);<\/code><\/pre>\n<p>\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0435\u0445\u0430\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/p>\n<ul>\n<li>\n<p><code>getUser \/ createUser \/ updateUserInteraction<\/code> .<\/p>\n<\/li>\n<li>\n<p>RPC (Remote Procedure Call) \u0447\u0435\u0440\u0435\u0437 <code>supabase.rpc('decrease_generation_count')<\/code> \u2014 \u0434\u0451\u0440\u0433\u0430\u0435\u0442 \u0437\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e DB, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0442\u0430\u043c \u043d\u0435\u0442, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0435\u0449\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0435\u043b\u0435\u0433\u0435 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434<code>getChatMember<\/code>. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u043c\u043e\u0435\u0433\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430, \u0442\u043e \u043e\u043d \u043d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0440\u0430\u0441\u0442\u0435\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<h4>2. states.ts \u2014 \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0430<\/h4>\n<ul>\n<li>\n<p><code>\/start<\/code> \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>handlePhoto<\/code> \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 <code>photo_url<\/code> \u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0432 WAITING_PROMPT.<\/p>\n<\/li>\n<li>\n<p><code>handleCallbackQuery<\/code> \u2014 \u043c\u0435\u043d\u044e \u0441\u0442\u0438\u043b\u0435\u0439 + \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>handlePromptWithPhoto<\/code> \u2014 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0431\u043b\u044e\u0434\u043e: \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u043e\u0442\u043e, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>generateImageBytes<\/code>, \u0448\u043b\u0451\u043c <code>sendPhoto<\/code>, \u043c\u0438\u043d\u0443\u0441\u0443\u0435\u043c \u0444\u0440\u0438\u043f\u0430\u0441\u0441.<\/p>\n<\/li>\n<\/ul>\n<h4>3. openai.ts &#8212; \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 OpenAI<\/h4>\n<pre><code>\/\/ 1. \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 const res = await fetch(srcUrl); if (!res.ok) throw new Error(\"Failed to fetch source image\"); const blob = await res.blob();  \/\/ 2. \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0438 MIME const ext  = srcUrl.match(\/\\.(png|jpe?g|webp)$\/i)?.[1]?.toLowerCase() ?? \"png\"; const mime = ext.startsWith(\"jp\") ? \"image\/jpeg\" :              ext === \"webp\"      ? \"image\/webp\"  : \"image\/png\";  \/\/ 3. \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c Blob \u0432 File (openai \u0436\u0434\u0451\u0442 File | Buffer) const file = new File([blob], `source.${ext}`, { type: mime });  \/\/ 4. \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c Images API const { data } = await openai.images.edit({   model  : 'gpt-image-1',   image  : file,   prompt,   n      : 1,   size   : '1024x1024',   quality: 'low', });  \/\/ 5. \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c base64 const bytes = Uint8Array.from(atob(data[0].b64_json!), c =&gt; c.charCodeAt(0));<\/code><\/pre>\n<p><strong>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0448\u0435<\/strong><\/p>\n<ol>\n<li>\n<p><strong>fetch\u202f\u2192\u202fblob<\/strong>\u00a0\u2014 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c URL \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0446\u0435\u043b\u0438\u043a\u043e\u043c (Images\u00a0API \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 URL, \u043d\u0443 \u0438\u043b\u0438 \u044f \u0441\u043b\u0435\u043f\u043e\u0439 \u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b).<\/p>\n<\/li>\n<li>\n<p><strong>ext \/ mime<\/strong>\u00a0\u2014 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430 \u0440\u0435\u0448\u0430\u0435\u043c, \u043a\u0430\u043a\u043e\u0439 <code>Content\u2011Type<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c OpenAI. \u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432: PNG, JPEG\/JPG, WEBP.<\/p>\n<\/li>\n<li>\n<p><strong>File()<\/strong>\u00a0\u2014 OpenAI SDK \u0432 Deno\/Node \u0436\u0434\u0451\u0442 <code>File<\/code> \u0438\u043b\u0438 <code>Buffer<\/code>; \u043e\u0431\u044b\u0447\u043d\u044b\u0439 <code>Blob<\/code> \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>openai.images.edit()<\/strong>\u00a0\u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p><code>model<\/code>: \u0441\u0435\u0439\u0447\u0430\u0441 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u00a0\u2014 <code>gpt-image-1<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>image<\/code>: \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 <code>File<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>prompt<\/code>: \u0442\u0435\u043a\u0441\u0442\u2011\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>n<\/code>: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 (1\u201110).<\/p>\n<\/li>\n<li>\n<p><code>size<\/code>: <code>'256x256' | '512x512' | '1024x1024'<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>quality<\/code>: <code>'low' | 'standard' | 'hd'<\/code> \u2014 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0446\u0435\u043d\u0443 \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>base64 \u2192 Uint8Array<\/strong>\u00a0\u2014 Telegram\u00a0API \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u043a\u0430\u043a <code>FormData<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u044b\u0440\u044b\u0435 \u0431\u0430\u0439\u0442\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>b64_json<\/code>, \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0432 <code>Uint8Array<\/code>, \u043a\u0438\u0434\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 Telegram.<\/p>\n<h4>4. \u0414\u0435\u043f\u043b\u043e\u0439<\/h4>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e <\/p>\n<pre><code>supabase functions serve bot --env-file .env --no-verify-jwt  # \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e (\u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c JWT) supabase functions deploy bot --no-verify-jwt                       # \u043f\u0440\u043e\u0434  (\u0431\u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u0435\u043a\u0440\u0435\u0442\u0443 \u0432 URL)<\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c hook:<\/p>\n<pre><code>curl \"https:\/\/api.telegram.org\/bot$TELEGRAM_BOT_TOKEN\/setWebhook?url=https:\/\/xyz.supabase.co\/functions\/v1\/bot\/&lt;WEBHOOK_SECRET&gt;\"<\/code><\/pre>\n<h3>\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438<\/h3>\n<h4>JWT\u2011\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430<\/h4>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Edge\u00a0Functions \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0439 JWT \u0432\u00a0\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <code>Authorization<\/code> \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 <strong>401 Unauthorized<\/strong>, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442. \u0414\u043b\u044f \u0432\u0435\u0431\u2011\u0445\u0443\u043a\u043e\u0432 (Stripe, Telegram, Viber) Supabase \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043e\u043f\u0446\u0438\u044e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443:<\/p>\n<pre><code># \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e supabase functions serve bot --no-verify-jwt # \u0434\u0435\u043f\u043b\u043e\u0439 supabase functions deploy bot --no-verify-jwt<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u044d\u0442\u0443 \u00ab\u0434\u044b\u0440\u043a\u0443\u00bb \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u043a\u0440\u0435\u0442\u043e\u043c \u0432 URL (\u043a\u0430\u043a <code>\/&lt;WEBHOOK_SECRET&gt;<\/code>), \u0438\u043d\u0430\u0447\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>\u0417\u0430 \u043f\u0430\u0440\u0443 \u0447\u0430\u0441\u043e\u0432 \u043d\u0430 Supabase \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e <a href=\"https:\/\/t.me\/StylifAIer_bot\" rel=\"noopener noreferrer nofollow\"><strong>\u0431\u0435\u0437\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439<\/strong> Telegram\u2011\u0431\u043e\u0442<\/a> \u043d\u0430 Supabase function, \u0438 \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0431\u0435\u0437 \u0442\u0430\u043d\u0446\u0435\u0432 \u0441 VPS \u0438 Docker. <\/p>\n<p>\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u043d\u0430 &#171;low&#187;, \u0442\u0430\u043a \u043a\u0430\u043a \u0441 medium \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0430 \u0432\u043e\u0442 \u0436\u0440\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 4 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u043f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u043d\u044c \u041e\u0427\u0415\u041d\u042c \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/p>\n<figure class=\"float full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/753\/ddb\/486\/753ddb4867b168d2de7b1627f815c4ca.jpg\" alt=\"Low\" title=\"Low\" width=\"1024\" height=\"1024\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/753\/ddb\/486\/753ddb4867b168d2de7b1627f815c4ca.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/753\/ddb\/486\/753ddb4867b168d2de7b1627f815c4ca.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>Low<\/figcaption><\/div>\n<\/figure>\n<div class=\"floating-image\">\n<\/div>\n<div class=\"floating-image\">\n<figure class=\"float full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/689\/714\/f87\/689714f87def6a3588006f92825fa118.png\" alt=\"medium\" title=\"medium\" width=\"1024\" height=\"1024\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/689\/714\/f87\/689714f87def6a3588006f92825fa118.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/689\/714\/f87\/689714f87def6a3588006f92825fa118.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>medium<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<div class=\"floating-image\">\n<figure class=\"float full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/264\/cd5\/a95\/264cd5a951ffe10255e6d5ba6fc756d9.png\" alt=\"hight\" title=\"hight\" width=\"1024\" height=\"1024\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/264\/cd5\/a95\/264cd5a951ffe10255e6d5ba6fc756d9.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/264\/cd5\/a95\/264cd5a951ffe10255e6d5ba6fc756d9.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>hight<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<div class=\"floating-image\">\n<p>\u041c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0435\u0449\u0435 \u0438 \u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430 \u0434\u0435\u043d\u044c\u0433\u0438, \u043d\u043e \u043d\u0443\u0436\u043d\u044b \u043b\u0438 \u043e\u043d\u0438 \u043a\u043e\u043c\u0443 \u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0443\u0434\u0443\u0442 \u044f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u0434, \u0442\u043e \u0442\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u043d\u043e <a href=\"https:\/\/github.com\/Ildar-agliukov\/telegram-bot-supabase\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0434\u0435\u0441\u044c<\/a> <\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/905338\/\"> https:\/\/habr.com\/ru\/articles\/905338\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u0438<\/h3>\n<p>\u041c\u0435\u0441\u044f\u0446 \u043d\u0430\u0437\u0430\u0434 \u044f \u0431\u0430\u043b\u043e\u0432\u0430\u043b\u0441\u044f \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c <strong>Lovable<\/strong>\u00a0\u2014 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u0440\u0438\u043a\u043e\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u043c\u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0411\u0414 \u043d\u0430 Supabase \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0440\u044b \u043a\u043b\u0438\u043a\u043e\u0432: \u0431\u0430\u0437\u0430 Postgres \u0443\u0436\u0435 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f, \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0432\u0441\u0451 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u0438, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e <strong>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e<\/strong> \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u0432\u043e\u0442.<\/p>\n<p>\u041f\u043e\u043a\u0430 \u0449\u0451\u043b\u043a\u0430\u043b UI \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0440\u0430\u0437\u0434\u0435\u043b <em>Functions<\/em>. \u00ab\u0427\u0442\u043e\u2011\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 <em>AWS\u00a0Lambda<\/em>, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u044f\u043c\u043e \u0440\u044f\u0434\u043e\u043c \u0441 \u0431\u0430\u0437\u043e\u0439\u00bb &#8212; \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u044f. \u0418 \u0442\u0430\u043a \u0432 &#171;\u0434\u043e\u043b\u0433\u043e\u043c \u044f\u0449\u0438\u043a\u0435&#187; \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0438\u0434\u0435\u044f \u043f\u043e\u0442\u044b\u043a\u0430\u0442\u044c \u0432 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u0440\u0435\u043b\u0438\u0437 OpenAI\u00a0<strong>Images\u00a0API<\/strong>. \u041c\u044b \u043a\u0430\u043a-\u0442\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u043a\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0432 \u0442\u0435\u043b\u0435\u0433\u0435 \u0434\u043b\u044f \u0440\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0445 \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e ChatGPT-plus \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043b \u043f\u0440\u043e Supabase\u202f\u2192\u202f\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u043d\u0441 \u043f\u043e\u0449\u0443\u043f\u0430\u0442\u044c edge\u2011\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0434\u043d\u044f\u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430.<\/p>\n<p>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u043d\u0430\u043a\u0438\u0434\u0430\u043b \u043c\u044b\u0441\u043b\u0438 \u043f\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u043e\u0442 \u0438 \u043d\u0430 \u0447\u0435\u043c, \u0438 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b ChatGPT \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u0438 \u0422\u0417. \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u043e\u043a \u0438 \u043f\u043b\u044e\u0441-\u043c\u0438\u043d\u0443\u0441 \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u044b\u043b\u043e \u043d\u0430 \u0440\u0443\u043a\u0430\u0445. \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u0448\u0451\u043b \u0432 <strong>Claude<\/strong> \u0447\u0435\u0440\u0435\u0437 OpenRouter \u2014 \u043e\u043d \u0432\u044b\u043f\u043b\u044e\u043d\u0443\u043b \u0441\u043a\u0435\u043b\u0435\u0442 \u043a\u043e\u0434\u0430 \u043f\u043e\u0434  Supabase edge functions. \u0418\u043c\u0435\u044f \u043d\u0430 \u0440\u0443\u043a\u0430\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u044f \u043f\u043e\u0448\u0435\u043b \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u044f\u0441\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>\u0411\u043e\u0442 \u043c\u043e\u0436\u043d\u043e<a href=\"https:\/\/t.me\/StylifAIer_bot\" rel=\"noopener noreferrer nofollow\"> \u043f\u043e\u0442\u044b\u043a\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c<\/a>, \u0430 \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0435\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0435 \u0438 \u043d\u0430 <a href=\"https:\/\/t.me\/databites\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0439 \u043a\u0430\u043d\u0430\u043b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a><\/p>\n<h4>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h4>\n<figure class=\"full-width\"><\/figure>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e Supabase<\/h4>\n<ol>\n<li>\n<p><strong>Edge Functions<\/strong> \u043d\u0430\u00a0Deno\u00a0\u2014 \u0441\u0443\u043f\u0435\u0440 \u043b\u0435\u0433\u043a\u0438\u0439 \u0434\u0435\u043f\u043b\u043e\u0439 <code>supabase functions deploy bot<\/code> \u0438 \u0433\u043e\u0442\u043e\u0432\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u0417\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u043c\u043d\u0435 Postgres <\/strong>\u2014 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 policies +\u00a0row\u2011level security.<\/p>\n<\/li>\n<li>\n<p><strong>\u0415\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 Storage<\/strong>\u00a0S3\u2014 \u0435\u0441\u043b\u0438 \u0440\u0435\u0448\u0443 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0442\u044f\u043d\u0435\u0442 500\u202f\u0442\u044b\u0441. Edge\u2011\u0438\u043d\u0432\u043e\u043a\u0430\u0446\u0438\u0439\u202f\/\u202f10\u202f\u0413\u0411\u2011\u0442\u0440\u0430\u0444\u0438\u043a\u0430 \u2014 \u043d\u0430 \u0445\u043e\u0431\u0431\u0438\u2011\u0431\u043e\u0442  \u0437\u0430 \u0433\u043b\u0430\u0437\u0430 \u0445\u0432\u0430\u0442\u0430\u0435\u0442.<\/p>\n<\/li>\n<\/ol>\n<h4>\u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c<\/h4>\n<figure class=\"full-width\">\n<div><figcaption>logic model<\/figcaption><\/div>\n<\/figure>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>users<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0443\u0447\u0451\u0442 TG\u2011\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>channel_subscribers<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u043f\u0440\u043e\u043c\u043e\u2011\u043a\u0430\u043d\u0430\u043b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>sessions<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">FSM (finite state machine\u00a0\u2014 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442)\u2011\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u043e\u0442\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>generations<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043b\u043e\u0433 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0422\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u0447\u0435\u0440\u0435\u0437 \u0438\u0445 \u0443\u0434\u043e\u0431\u043d\u0443\u044e SQL \u0441\u0442\u0443\u0434\u0438\u044e, \u0442\u0430\u043c \u0436\u0435 \u043d\u0430\u043a\u0438\u043d\u0443\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043b-\u0432\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <\/p>\n<h4>Edge\u00a0Function bot<\/h4>\n<ul>\n<li>\n<p><strong>URL<\/strong>\u00a0<code>https:\/\/xyz.supabase.co\/functions\/v1\/bot\/&lt;WEBHOOK_SECRET&gt;<\/code> \u2014 \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0443\u0434\u0430 Telegram \u00ab\u043f\u043e\u0441\u0442\u0443\u0447\u0438\u0442\u0441\u044f\u00bb \u043c\u0435\u0442\u043e\u0434\u043e\u043c POST, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f JSON-\u043e\u0431\u044a\u0435\u043a\u0442 TelegramUpdate \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u0444\u043e\u0442\u043e, callback-\u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c <code>req.method === 'POST'<\/code> \u0438 \u0441\u0435\u043a\u0440\u0435\u0442 \u0432 path.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0441\u0438\u043c <code>TelegramUpdate<\/code>, \u0440\u043e\u0443\u0442\u0438\u043c \u0432\u00a0<code>states.ts<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0431\u043e\u0442\u0430<\/h4>\n<p><code>states.ts<\/code><\/p>\n<pre><code>WAITING_PHOTO \u2500\u25b6 WAITING_PROMPT \u2500\u25b6 GENERATING \u2500\u25b6 WAITING_PHOTO             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 SUBSCRIPTION_OFFER<\/code><\/pre>\n<p>FSM (finite state machine) \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 <code>sessions<\/code> \u2014 \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h2>\u0413\u043b\u0443\u0431\u0436\u0435 \u0432 \u043a\u043e\u0434<\/h2>\n<h4>1. database.ts<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c Supabase\u2011\u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<pre><code>const supabase = createClient(supabaseUrl, supabaseKey);<\/code><\/pre>\n<p>\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0435\u0445\u0430\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/p>\n<ul>\n<li>\n<p><code>getUser \/ createUser \/ updateUserInteraction<\/code> .<\/p>\n<\/li>\n<li>\n<p>RPC (Remote Procedure Call) \u0447\u0435\u0440\u0435\u0437 <code>supabase.rpc('decrease_generation_count')<\/code> \u2014 \u0434\u0451\u0440\u0433\u0430\u0435\u0442 \u0437\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e DB, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0442\u0430\u043c \u043d\u0435\u0442, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0435\u0449\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0435\u043b\u0435\u0433\u0435 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434<code>getChatMember<\/code>. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u043c\u043e\u0435\u0433\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430, \u0442\u043e \u043e\u043d \u043d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0440\u0430\u0441\u0442\u0435\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<h4>2. states.ts \u2014 \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0430<\/h4>\n<ul>\n<li>\n<p><code>\/start<\/code> \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>handlePhoto<\/code> \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 <code>photo_url<\/code> \u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0432 WAITING_PROMPT.<\/p>\n<\/li>\n<li>\n<p><code>handleCallbackQuery<\/code> \u2014 \u043c\u0435\u043d\u044e \u0441\u0442\u0438\u043b\u0435\u0439 + \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>handlePromptWithPhoto<\/code> \u2014 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0431\u043b\u044e\u0434\u043e: \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u043e\u0442\u043e, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>generateImageBytes<\/code>, \u0448\u043b\u0451\u043c <code>sendPhoto<\/code>, \u043c\u0438\u043d\u0443\u0441\u0443\u0435\u043c \u0444\u0440\u0438\u043f\u0430\u0441\u0441.<\/p>\n<\/li>\n<\/ul>\n<h4>3. openai.ts &#8212; \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 OpenAI<\/h4>\n<pre><code>\/\/ 1. \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 const res = await fetch(srcUrl); if (!res.ok) throw new Error(\"Failed to fetch source image\"); const blob = await res.blob();  \/\/ 2. \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0438 MIME const ext  = srcUrl.match(\/\\.(png|jpe?g|webp)$\/i)?.[1]?.toLowerCase() ?? \"png\"; const mime = ext.startsWith(\"jp\") ? \"image\/jpeg\" :              ext === \"webp\"      ? \"image\/webp\"  : \"image\/png\";  \/\/ 3. \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c Blob \u0432 File (openai \u0436\u0434\u0451\u0442 File | Buffer) const file = new File([blob], `source.${ext}`, { type: mime });  \/\/ 4. \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c Images API const { data } = await openai.images.edit({   model  : 'gpt-image-1',   image  : file,   prompt,   n      : 1,   size   : '1024x1024',   quality: 'low', });  \/\/ 5. \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c base64 const bytes = Uint8Array.from(atob(data[0].b64_json!), c =&gt; c.charCodeAt(0));<\/code><\/pre>\n<p><strong>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0448\u0435<\/strong><\/p>\n<ol>\n<li>\n<p><strong>fetch\u202f\u2192\u202fblob<\/strong>\u00a0\u2014 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c URL \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0446\u0435\u043b\u0438\u043a\u043e\u043c (Images\u00a0API \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 URL, \u043d\u0443 \u0438\u043b\u0438 \u044f \u0441\u043b\u0435\u043f\u043e\u0439 \u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b).<\/p>\n<\/li>\n<li>\n<p><strong>ext \/ mime<\/strong>\u00a0\u2014 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430 \u0440\u0435\u0448\u0430\u0435\u043c, \u043a\u0430\u043a\u043e\u0439 <code>Content\u2011Type<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c OpenAI. \u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432: PNG, JPEG\/JPG, WEBP.<\/p>\n<\/li>\n<li>\n<p><strong>File()<\/strong>\u00a0\u2014 OpenAI SDK \u0432 Deno\/Node \u0436\u0434\u0451\u0442 <code>File<\/code> \u0438\u043b\u0438 <code>Buffer<\/code>; \u043e\u0431\u044b\u0447\u043d\u044b\u0439 <code>Blob<\/code> \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>openai.images.edit()<\/strong>\u00a0\u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p><code>model<\/code>: \u0441\u0435\u0439\u0447\u0430\u0441 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u00a0\u2014 <code>gpt-image-1<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>image<\/code>: \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 <code>File<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>prompt<\/code>: \u0442\u0435\u043a\u0441\u0442\u2011\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>n<\/code>: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 (1\u201110).<\/p>\n<\/li>\n<li>\n<p><code>size<\/code>: <code>'256x256' | '512x512' | '1024x1024'<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>quality<\/code>: <code>'low' | 'standard' | 'hd'<\/code> \u2014 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0446\u0435\u043d\u0443 \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>base64 \u2192 Uint8Array<\/strong>\u00a0\u2014 Telegram\u00a0API \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u043a\u0430\u043a <code>FormData<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u044b\u0440\u044b\u0435 \u0431\u0430\u0439\u0442\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>b64_json<\/code>, \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0432 <code>Uint8Array<\/code>, \u043a\u0438\u0434\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 Telegram.<\/p>\n<h4>4. \u0414\u0435\u043f\u043b\u043e\u0439<\/h4>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e <\/p>\n<pre><code>supabase functions serve bot --env-file .env --no-verify-jwt  # \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e (\u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c JWT) supabase functions deploy bot --no-verify-jwt                       # \u043f\u0440\u043e\u0434  (\u0431\u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u0435\u043a\u0440\u0435\u0442\u0443 \u0432 URL)<\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c hook:<\/p>\n<pre><code>curl \"https:\/\/api.telegram.org\/bot$TELEGRAM_BOT_TOKEN\/setWebhook?url=https:\/\/xyz.supabase.co\/functions\/v1\/bot\/&lt;WEBHOOK_SECRET&gt;\"<\/code><\/pre>\n<h3>\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438<\/h3>\n<h4>JWT\u2011\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430<\/h4>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Edge\u00a0Functions \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0439 JWT \u0432\u00a0\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <code>Authorization<\/code> \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 <strong>401 Unauthorized<\/strong>, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442. \u0414\u043b\u044f \u0432\u0435\u0431\u2011\u0445\u0443\u043a\u043e\u0432 (Stripe, Telegram, Viber) Supabase \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043e\u043f\u0446\u0438\u044e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443:<\/p>\n<pre><code># \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e supabase functions serve bot --no-verify-jwt # \u0434\u0435\u043f\u043b\u043e\u0439 supabase functions deploy bot --no-verify-jwt<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u044d\u0442\u0443 \u00ab\u0434\u044b\u0440\u043a\u0443\u00bb \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u043a\u0440\u0435\u0442\u043e\u043c \u0432 URL (\u043a\u0430\u043a <code>\/&lt;WEBHOOK_SECRET&gt;<\/code>), \u0438\u043d\u0430\u0447\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>\u0417\u0430 \u043f\u0430\u0440\u0443 \u0447\u0430\u0441\u043e\u0432 \u043d\u0430 Supabase \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e <a href=\"https:\/\/t.me\/StylifAIer_bot\" rel=\"noopener noreferrer nofollow\"><strong>\u0431\u0435\u0437\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439<\/strong> Telegram\u2011\u0431\u043e\u0442<\/a> \u043d\u0430 Supabase function, \u0438 \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0431\u0435\u0437 \u0442\u0430\u043d\u0446\u0435\u0432 \u0441 VPS \u0438 Docker. <\/p>\n<p>\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u043d\u0430 &#171;low&#187;, \u0442\u0430\u043a \u043a\u0430\u043a \u0441 medium \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0430 \u0432\u043e\u0442 \u0436\u0440\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 4 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u043f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u043d\u044c \u041e\u0427\u0415\u041d\u042c \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/p>\n<figure class=\"float full-width\">\n<div><figcaption>Low<\/figcaption><\/div>\n<\/figure>\n<div class=\"floating-image\">\n<\/div>\n<div class=\"floating-image\">\n<figure class=\"float full-width\">\n<div><figcaption>medium<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<div class=\"floating-image\">\n<figure class=\"float full-width\">\n<div><figcaption>hight<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<div class=\"floating-image\">\n<p>\u041c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0435\u0449\u0435 \u0438 \u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430 \u0434\u0435\u043d\u044c\u0433\u0438, \u043d\u043e \u043d\u0443\u0436\u043d\u044b \u043b\u0438 \u043e\u043d\u0438 \u043a\u043e\u043c\u0443 \u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0443\u0434\u0443\u0442 \u044f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u0434, \u0442\u043e \u0442\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u043d\u043e <a href=\"https:\/\/github.com\/Ildar-agliukov\/telegram-bot-supabase\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0434\u0435\u0441\u044c<\/a> <\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/905338\/\"> https:\/\/habr.com\/ru\/articles\/905338\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-458055","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458055","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=458055"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458055\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}