<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rahul K</title>
    <description>The latest articles on DEV Community by Rahul K (@rahulkhunte).</description>
    <link>https://dev.to/rahulkhunte</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3901269%2Fd3594741-6d20-4047-8c9e-96fb70ff7184.jpeg</url>
      <title>DEV Community: Rahul K</title>
      <link>https://dev.to/rahulkhunte</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahulkhunte"/>
    <language>en</language>
    <item>
      <title>I built a Telegram bot that generates AI images using Stable Diffusion — here's how</title>
      <dc:creator>Rahul K</dc:creator>
      <pubDate>Mon, 27 Apr 2026 23:28:34 +0000</pubDate>
      <link>https://dev.to/rahulkhunte/i-built-a-telegram-bot-that-generates-ai-images-using-stable-diffusion-heres-how-2n59</link>
      <guid>https://dev.to/rahulkhunte/i-built-a-telegram-bot-that-generates-ai-images-using-stable-diffusion-heres-how-2n59</guid>
      <description>&lt;p&gt;🔗 Live portfolio page&lt;br&gt;
&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://rahulkhunte.github.io/portfolio/AI_Image_Bot_Portfolio.html" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Frahulkhunte%2Fai-image-bot%2Fmain%2Fbot_payment.jpg" height="1020" class="m-0" width="637"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://rahulkhunte.github.io/portfolio/AI_Image_Bot_Portfolio.html" rel="noopener noreferrer" class="c-link"&gt;
            AI Image Generation Telegram Bot - Rahul Khunte
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Full-stack AI-as-a-Service bot with GPU inference, payment integration, and production deployment
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
          rahulkhunte.github.io
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;A few months ago I wanted AI image generation accessible &lt;br&gt;
directly in Telegram — no web UI, no waiting, just type &lt;br&gt;
a prompt and get an image back in the chat. So I built it.&lt;/p&gt;

&lt;p&gt;128 developers cloned the repo in the last 2 weeks with &lt;br&gt;
zero promotion. Apparently others wanted the same thing.&lt;/p&gt;

&lt;p&gt;Here's exactly how it works.&lt;/p&gt;
&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Send any text prompt to the bot&lt;/li&gt;
&lt;li&gt;Bot generates an image using SDXL / Juggernaut XL&lt;/li&gt;
&lt;li&gt;Returns image directly in Telegram chat&lt;/li&gt;
&lt;li&gt;Supports custom models via ComfyUI workflows&lt;/li&gt;
&lt;li&gt;Runs on any GPU server (I use free Kaggle/Colab 
and a VPS with GPU)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;python-telegram-bot&lt;/strong&gt; — handles all Telegram API&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ComfyUI&lt;/strong&gt; — the image generation backend&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SDXL / Juggernaut XL&lt;/strong&gt; — the actual models&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;websockets&lt;/strong&gt; — connects bot to ComfyUI API&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Oracle Cloud ARM&lt;/strong&gt; — hosts the bot 24/7 for free&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;ComfyUI exposes a REST API. The bot sends your prompt &lt;br&gt;
to ComfyUI via websocket, waits for the image, then &lt;br&gt;
sends it back to Telegram. That's the whole loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Build ComfyUI workflow with your prompt
&lt;/span&gt;    &lt;span class="n"&gt;workflow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_workflow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Send to ComfyUI API
&lt;/span&gt;    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;websockets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;COMFYUI_WS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;queue_prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;workflow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;image_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;wait_for_output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;image_data&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;handle_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reply_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Generating... &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generate_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reply_photo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  The tricky parts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. ComfyUI workflow as JSON&lt;/strong&gt;&lt;br&gt;
ComfyUI workflows are JSON graphs. Export any workflow &lt;br&gt;
from the UI, save as a template, then inject the user &lt;br&gt;
prompt at runtime. This lets you swap models without &lt;br&gt;
changing bot code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Queue management&lt;/strong&gt;&lt;br&gt;
Multiple users sending prompts simultaneously = queue &lt;br&gt;
needed. I use asyncio queues to process one generation &lt;br&gt;
at a time, with the user getting a "position X in queue" &lt;br&gt;
message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. GPU access without paying&lt;/strong&gt;&lt;br&gt;
For development: Kaggle notebooks (30hrs GPU/week free), &lt;br&gt;
Google Colab free tier.&lt;br&gt;
For production hosting the bot itself (not the GPU), &lt;br&gt;
you need almost nothing — it's just a Python process &lt;br&gt;
making API calls.&lt;/p&gt;

&lt;p&gt;Good free/cheap options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Railway.app&lt;/strong&gt; — free tier, deploy straight from GitHub, 
zero config&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render.com&lt;/strong&gt; — free tier, auto-deploys on git push&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fly.io&lt;/strong&gt; — free allowance, great for bots&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Any $4/month VPS&lt;/strong&gt; — DigitalOcean, Hetzner, Vultr&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The bot uses ~80MB RAM idle. A $4 Hetzner ARM server &lt;br&gt;
handles it perfectly.&lt;/p&gt;
&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;The bot handles ~20-30 image requests per day on a &lt;br&gt;
single deployment. Average generation time: 8-15 seconds &lt;br&gt;
on a mid-range GPU.&lt;/p&gt;

&lt;p&gt;Users can also send style keywords:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"realistic portrait of a cat --style photorealistic"&lt;/li&gt;
&lt;li&gt;"cyberpunk city at night --style anime"&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;Currently adding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image-to-image (send a photo + prompt = transformed image)&lt;/li&gt;
&lt;li&gt;Multiple model selection via /model command
&lt;/li&gt;
&lt;li&gt;DALL-E 3 fallback when GPU is unavailable&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Full source code
&lt;/h2&gt;

&lt;p&gt;Everything is open source:&lt;br&gt;
👉 Github&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/rahulkhunte" rel="noopener noreferrer"&gt;
        rahulkhunte
      &lt;/a&gt; / &lt;a href="https://github.com/rahulkhunte/ai-image-bot" rel="noopener noreferrer"&gt;
        ai-image-bot
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;🤖 Jenerator Bot - AI Image Generation&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;Production-ready Telegram bot with GPU-accelerated image generation using Stable Diffusion XL Turbo. Generate high-quality images in under 4 seconds with natural language prompts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.me/Jenerator_bot" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/35698f3b3c9ada687c5234002cf05003a8a30c73d33a6e5f76807db4b430a4b1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d50726f64756374696f6e5f52656164792d627269676874677265656e" alt="Status"&gt;&lt;/a&gt;
&lt;a href="https://www.nvidia.com/en-us/data-center/l40/" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/f04d50a23f4f77aaffb0ae18138490d0564c3c31616963b19ad1ce8164d15ca4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4750552d4c34305f343847422d3736423930303f6c6f676f3d6e7669646961" alt="GPU"&gt;&lt;/a&gt;
&lt;a href="https://www.python.org/" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/3bcaf5ebe3652b8fe6627c8a0eb07a81ba6dbaa1f4372fe2a7862a8b1d451e27/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f507974686f6e2d332e31302b2d3337373641423f6c6f676f3d707974686f6e" alt="Python"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;📄 &lt;strong&gt;&lt;a href="https://rahulkhunte.github.io/portfolio/AI_Image_Bot_Portfolio.html" rel="nofollow noopener noreferrer"&gt;View Full Project Portfolio&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Note:&lt;/strong&gt; Demo currently paused for infrastructure optimization. Full codebase and deployment guide available.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;✨ Features&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Core Capabilities&lt;/h3&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;⚡ &lt;strong&gt;Lightning-fast generation&lt;/strong&gt; - Sub-4 second image creation (L40 GPU)&lt;/li&gt;
&lt;li&gt;🎨 &lt;strong&gt;High-quality outputs&lt;/strong&gt; - SDXL Turbo model for photorealistic results&lt;/li&gt;
&lt;li&gt;🔧 &lt;strong&gt;ComfyUI backend&lt;/strong&gt; - Professional workflow management&lt;/li&gt;
&lt;li&gt;💬 &lt;strong&gt;Telegram integration&lt;/strong&gt; - Intuitive bot interface with inline buttons&lt;/li&gt;
&lt;li&gt;💰 &lt;strong&gt;Payment system&lt;/strong&gt; - Cryptocurrency payment integration&lt;/li&gt;
&lt;li&gt;📊 &lt;strong&gt;Usage tracking&lt;/strong&gt; - Credit system with transaction history&lt;/li&gt;
&lt;li&gt;🖼️ &lt;strong&gt;Gallery system&lt;/strong&gt; - Browse and regenerate previous images&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Technical Highlights&lt;/h3&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;GPU-optimized inference pipeline&lt;/li&gt;
&lt;li&gt;Asynchronous request handling&lt;/li&gt;
&lt;li&gt;Docker containerization&lt;/li&gt;
&lt;li&gt;Production-grade error handling&lt;/li&gt;
&lt;li&gt;Automatic queue management&lt;/li&gt;
&lt;li&gt;Real-time generation status updates&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;🎯 Why This Project Matters&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;This bot demonstrates:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Production ML deployment&lt;/strong&gt; - Not a toy…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/rahulkhunte/ai-image-bot" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;👉 🔗 Live portfolio page&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://rahulkhunte.github.io/portfolio/AI_Image_Bot_Portfolio.html" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Frahulkhunte%2Fai-image-bot%2Fmain%2Fbot_payment.jpg" height="1020" class="m-0" width="637"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://rahulkhunte.github.io/portfolio/AI_Image_Bot_Portfolio.html" rel="noopener noreferrer" class="c-link"&gt;
            AI Image Generation Telegram Bot - Rahul Khunte
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Full-stack AI-as-a-Service bot with GPU inference, payment integration, and production deployment
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
          rahulkhunte.github.io
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Includes the full bot, ComfyUI workflow templates, &lt;br&gt;
deployment guide on Cloud, and systemd service &lt;br&gt;
config for 24/7 running.&lt;/p&gt;

&lt;p&gt;If you build something with it or have questions, &lt;br&gt;
drop a comment — happy to help.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>telegram</category>
      <category>stablediffusion</category>
    </item>
  </channel>
</rss>
