IntegrationsBeginner

How to auto-post to a Telegram channel from a script

Make a bot an admin of your channel and push formatted posts automatically with a single API call.

7 minBeginner

Channels are Telegram's broadcast surface: one author, many readers. A bot that is an admin of a channel can publish posts on a schedule or whenever an event happens, with no human in the loop. This guide gets you from an empty channel to an automated post.

What you need

  • A Telegram channel you own
  • A bot token from BotFather
  • The channel username (e.g. @my_channel) or its numeric ID

Step 1: Add the bot as a channel admin

Open the channel, go to Manage Channel, then Administrators, then Add Admin. Search for your bot's username and add it. Make sure the Post Messages permission is enabled, because that is the one that lets the bot publish.

Channel - Administrators
Add Admin: @order_helper_bot
----------------------------------
[x] Post Messages
[x] Edit Messages
[x] Delete Messages
[ ] Add New Admins
Post Messages must be on for auto-posting to work.

Step 2: Post with sendMessage

Use the channel's public username as the chat_id. If the channel is private, use its numeric ID instead (the one starting with -100).

curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
  -d chat_id="@my_channel" \
  -d parse_mode="HTML" \
  -d text="<b>New drop</b>%0AThe summer batch is live now."
Formatting
Set parse_mode to HTML or MarkdownV2 for bold, links, and code. HTML is the most forgiving because MarkdownV2 forces you to escape many punctuation characters.

Step 3: Wrap it in a reusable script

A tiny Node script makes posting repeatable. Drop this in your project and call it from a cron job, a CI step, or any event handler.

post.mjs
const token = process.env.TELEGRAM_BOT_TOKEN;
const channel = "@my_channel";

async function post(text) {
  const res = await fetch(
    `https://api.telegram.org/bot${token}/sendMessage`,
    {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        chat_id: channel,
        parse_mode: "HTML",
        text,
      }),
    }
  );
  const data = await res.json();
  if (!data.ok) throw new Error(data.description);
  console.log("Posted message", data.result.message_id);
}

post("<b>Auto post</b> from a script.");
Telegram - @my_channel
Agent
New drop. The summer batch is live now.

Result

Running the script publishes a formatted post to your channel under the channel's name, not the bot's. Schedule it and you have hands-off broadcasting.

Watch related tutorials

Tags
#telegram#channel#auto-post#bot