🎬 Create a virtual outfit try-on Telegram bot with async polling and Google Sheets

⚑ 1,298 views · 🎬 Content Creation & Video

Description

πŸ‘— Virtual Try-On Telegram Bot β€” AI Outfit Try-On via Telegram with Async Job Polling

Try on any outfit virtually - right inside Telegram. A user sends a person photo, then a garment photo (captioned garment), and the bot replies with an AI-generated try-on result image using a dedicated Virtual Try-On API. No app. No frontend. Just a Telegram chat.

🎯 Who Is This For?

βš™οΈ What This Workflow Does

  1. Receives a Telegram message and checks if it contains a photo
  2. Person photo (sent without caption) β†’ saves chat_id + file_id to Google Sheets as session state
  3. Garment photo (sent with caption garment) β†’ looks up the saved person photo, resolves both Telegram file URLs, downloads both images, and submits a try-on job to the API
  4. Async polling loop β†’ waits 15 seconds, checks job status, loops until completed or failed
  5. Sends the result back to the user as a photo in Telegram, then cleans up the sheet row

πŸ”‘ Credentials & APIs Required

ServicePurposeWhere to Get It
Telegram Bot TokenReceive messages & send resultsCreate a bot via @BotFather on Telegram β†’ /newbot
Virtual Try-On API KeySubmit and poll try-on jobsSign up at your Try-On API provider (e.g. try-on api or your own deployment)
Google Sheets OAuth2Store per-user session state between messagesConnect via n8n’s built-in Google Sheets OAuth2 credential

> πŸ’‘ Why Google Sheets for state? Each Telegram message triggers a separate workflow execution - there’s no shared memory between runs. Google Sheets acts as a lightweight session store using chat_id as the unique key.

πŸ› οΈ Setup Instructions

Step 1 - Telegram Bot

  1. Open Telegram and message @BotFather
  2. Run /newbot, follow the prompts, copy your Bot Token
  3. Paste the token into the βš™οΈ Config node under botToken

Step 2 - Google Sheet

  1. Create a new Google Sheet
  2. Add a tab named exactly tryon-state
  3. Add two column headers in row 1: chat_id and person_file_id
  4. Copy the Sheet ID from the URL (docs.google.com/spreadsheets/d/**{THIS_PART}**/edit)
  5. Paste it into the βš™οΈ Config node under sheetId

Step 3 - Try-On API

  1. Obtain your API key from your Virtual Try-On provider
  2. Set tryonApiKey in the βš™οΈ Config node
  3. If your API base URL differs, also update tryonApiBase
  4. Verify the API accepts POST /api/v1/tryon with multipart/form-data fields person_images and garment_images, and returns { jobId, statusUrl } - adjust the Submit Try-On Job and Check Job Status nodes if your provider’s schema differs

Step 4 - n8n Credentials

πŸ”„ How the Polling Loop Works

The Try-On API is asynchronous - submitting a job returns a jobId, not the result immediately. The workflow:

  1. Submits the job β†’ gets jobId
  2. Waits 15 seconds
  3. Calls the status endpoint: GET /api/v1/tryon/status/{jobId}
  4. If status === "completed" β†’ downloads and sends the result image
  5. If status === "failed" β†’ sends an error message to the user
  6. Otherwise β†’ loops back to the wait step

Typical total wait: 15–60 seconds depending on the API and queue load.

🎨 How to Customize

πŸ“‹ Workflow Nodes Overview

NodeRole
Telegram TriggerListens for incoming messages
Extract Message InfoPulls out chat_id, caption, hasPhoto, fileId
βš™οΈ ConfigSingle place for all configurable values β€” edit this first
Has Photo?Routes messages that contain a photo
Is Garment Photo?Checks if caption equals garment
Save Person to SheetStores person file_id keyed by chat_id
Lookup Person from SheetRetrieves saved person photo when garment arrives
Has Person Saved?Guards against out-of-order photos
Collect IDsBundles all required IDs for downstream nodes
Get Person/Garment File PathResolves Telegram file_id β†’ file_path via getFile API
Download Person/Garment ImageDownloads actual image binary from Telegram CDN
Submit Try-On JobPOSTs both images to the Try-On API
Wait 15 SecondsGives the API time before first status check
Check Job StatusPolls job status endpoint
Is Job Complete? / Is Job Failed?Routes to success or error path
HTTP Request (result download)Downloads the result image as binary
Send Result PhotoSends the AI try-on image back to the user
Delete Row from SheetCleans up session state after successful result

⚠️ Notes & Gotchas

πŸ”— Nodes Used

Google Sheets, HTTP Request, Telegram, Telegram Trigger

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup