"Hey! It’s under maintenance right now, coming soon!

How to create Background remover Telegram Bot

Estimated read time: 5 min
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

Hello! Welcome to CodeNest.

If you want to How to create Background remover Telegram Bot then this post is just for you.

Free-Background-Remover-Tool-Script-for-blogger

Removing image backgrounds has never been easier! With this simple and professional Telegram Background Remover Bot, you just need to send an image, and the bot will process it and send back the background-removed version — all within seconds!

What is a Telegram Background Remover Bot?

It’s a smart Telegram bot that uses AI to automatically remove backgrounds from your images. Just send any photo to the bot, and it will reply with a transparent version of your image — no clicks, no tools, just pure automation. Perfect for product images, profile pictures, thumbnails, or social posts.

How It Works

This bot is powered by the Remove.bg API, an advanced AI service that detects and separates the subject from the background with high accuracy.

You can see the demo⤵

View Demo

Features

  1. Send JPG or PNG image directly to the bot
  2. Bot instantly processes and removes the background
  3. You’ll receive the transparent version within seconds
  4. Image is processed securely — not stored
  5. Fully works on mobile & desktop Telegram apps

How to Use

  1. Open the Telegram Bot (link below)
  2. Send your JPG or PNG image
  3. Wait a few seconds while the bot processes it
  4. The bot will reply with your new background-free image

Read the Documentation & Set Up the Bot

Read the full documentation and set up your own Telegram bot. Below is the complete code for the Background Remover Bot.

Bot Set-UP Documentation
js
addEventListener("fetch", (event) => {
	event.respondWith(handleRequest(event.request));
  });
  
  const TELEGRAM_BOT_TOKEN = "##########";
  const REMOVE_BG_API_KEY = "##########";
  const TELEGRAM_API_URL = `https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}`;
  
  async function handleRequest(request) {
	const update = await request.json();
  
	if (update.message) {
	  const chat_id = update.message.chat.id;
	  const username = update.message.from.first_name || "User";
	  const text = update.message.text;
  
	  if (text === "/start") return sendWelcomeMessage(chat_id, username);
	  if (update.message.photo) return processImage(chat_id, update.message.photo);
	} else if (update.callback_query) {
	  return handleCallback(update.callback_query);
	}
	
	return new Response("OK");
  }
  
  // **🔹 Updated Welcome Message**
  async function sendWelcomeMessage(chat_id, username) {
	const message = `**Hey ${username}, welcome to BG Remover Pro!**\n\n`
	  + `Get a clean, high-quality cutout instantly with our AI-powered tool. `
	  + `Just upload your image, and let our system handle the rest with precision.\n\n`
	  + `⚡ *No watermarks, no hassle—just smooth, professional results!*`;
  
	const keyboard = {
	  inline_keyboard: [[{ text: "🖼 Remove Background Now", callback_data: "send_image" }]],
	};
  
	await sendTelegramMessage(chat_id, message, keyboard);
	return new Response("Welcome Sent");
  }
  
  // **🔹 Handle Button Click**
  async function handleCallback(callback) {
	const chat_id = callback.message.chat.id;
	const data = callback.data;
  
	if (data === "send_image") {
	  await sendTelegramMessage(chat_id, "📷 *Please send an image to remove the background!*");
	}
	return new Response("Callback Handled");
  }
  
  // **🔹 Process Image**
  async function processImage(chat_id, photo) {
	const processingMessage = await sendTelegramMessage(chat_id, "⏳ **Processing your image...**");
  
	const file_id = photo[photo.length - 1].file_id;
	const file_path = await getTelegramFilePath(file_id);
	const image_url = `https://api.telegram.org/file/bot${TELEGRAM_BOT_TOKEN}/${file_path}`;
  
	const processedImage = await removeBackground(image_url);
  
	if (processedImage) {
	  await deleteMessage(chat_id, processingMessage); // Hide "Processing..." message
	  await sendTelegramPhoto(chat_id, processedImage);
	  await sendTelegramFile(chat_id, processedImage);
	} else {
	  await editTelegramMessage(chat_id, processingMessage, "⚠️ *Background removal failed. Please try again!*");
	}
  
	return new Response("Image Processed");
  }
  
  // **🔹 Get File Path from Telegram**
  async function getTelegramFilePath(file_id) {
	const response = await fetch(`${TELEGRAM_API_URL}/getFile?file_id=${file_id}`);
	const data = await response.json();
	return data.result.file_path;
  }
  
  // **🔹 Remove Background Using API**
  async function removeBackground(image_url) {
	const response = await fetch("https://api.remove.bg/v1.0/removebg", {
	  method: "POST",
	  headers: { "X-Api-Key": REMOVE_BG_API_KEY },
	  body: new URLSearchParams({ image_url }),
	});
  
	if (!response.ok) return null;
	return response.blob();
  }
  
  // **🔹 Send Message to Telegram**
  async function sendTelegramMessage(chat_id, text, keyboard = null) {
	const payload = { chat_id, text, parse_mode: "Markdown" };
	if (keyboard) payload.reply_markup = JSON.stringify(keyboard);
  
	const response = await fetch(`${TELEGRAM_API_URL}/sendMessage`, {
	  method: "POST",
	  headers: { "Content-Type": "application/json" },
	  body: JSON.stringify(payload),
	});
  
	const data = await response.json();
	return data.result.message_id;
  }
  
  // **🔹 Edit Message in Telegram**
  async function editTelegramMessage(chat_id, message_id, new_text) {
	await fetch(`${TELEGRAM_API_URL}/editMessageText`, {
	  method: "POST",
	  headers: { "Content-Type": "application/json" },
	  body: JSON.stringify({
		chat_id,
		message_id,
		text: new_text,
		parse_mode: "Markdown",
	  }),
	});
  }
  
  // **🔹 Delete Message in Telegram**
  async function deleteMessage(chat_id, message_id) {
	await fetch(`${TELEGRAM_API_URL}/deleteMessage`, {
	  method: "POST",
	  headers: { "Content-Type": "application/json" },
	  body: JSON.stringify({ chat_id, message_id }),
	});
  }
  
  // **🔹 Send Processed Image as Photo**
  async function sendTelegramPhoto(chat_id, fileBlob) {
	const formData = new FormData();
	formData.append("chat_id", chat_id);
	formData.append("photo", fileBlob, "removed_bg.png");
  
	await fetch(`${TELEGRAM_API_URL}/sendPhoto`, {
	  method: "POST",
	  body: formData,
	});
  }
  
  // **🔹 Send Processed Image as File**
  async function sendTelegramFile(chat_id, fileBlob) {
	const formData = new FormData();
	formData.append("chat_id", chat_id);
	formData.append("document", fileBlob, "removed_bg.png");
  
	await fetch(`${TELEGRAM_API_URL}/sendDocument`, {
	  method: "POST",
	  body: formData,
	});
  
	await sendTelegramMessage(chat_id, "✅ *Here is your HD background-removed image!*");
  }

Watch this video for better guidance on setting up and using the bot.

Youtube video

Conclusion

This bot makes background removal super easy and fast. Just upload an image, and download the transparent version in seconds – no editing skills needed.

Perfect for blogs, websites, and personal use. Add it to your site in minutes and let your users enjoy it for free!

About the Author

Hey! Im Ankur Kumar, I am a professional part time blogger. Here we share informative and technical information. This blog is made to teach you something new. Buy Me a Coffee

Post a Comment

Please don't share any sensitive or personal details here.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.