How to schedule Telegram channel posts with cron
Use a cron job and a small script to publish queued posts to a Telegram channel at fixed times.
If you want a Telegram channel to post at 9 am every day without you touching anything, cron plus a posting script is the simplest setup that just works. This guide builds a queue of posts and a scheduler that drains one entry per run.
What you need
- A bot that is an admin of your channel
- A Linux or macOS machine that stays on (or a small VPS)
- Node installed and your bot token in the environment
Step 1: Create a post queue
Keep your scheduled content in a plain JSON file. Each run pops the first item and posts it. This keeps the logic dead simple and easy to edit by hand.
[
{ "text": "Monday tip: batch your DMs into one daily window." },
{ "text": "Tuesday tip: pin your best post for new subscribers." },
{ "text": "Wednesday tip: ask one question to spark replies." }
]Step 2: Write the scheduler script
import { readFile, writeFile } from "node:fs/promises";
const token = process.env.TELEGRAM_BOT_TOKEN;
const channel = "@my_channel";
const queue = JSON.parse(await readFile("queue.json", "utf8"));
if (queue.length === 0) {
console.log("Queue empty, nothing to post.");
process.exit(0);
}
const next = queue.shift();
const res = await fetch(
`https://api.telegram.org/bot${token}/sendMessage`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ chat_id: channel, text: next.text }),
}
);
const data = await res.json();
if (!data.ok) throw new Error(data.description);
await writeFile("queue.json", JSON.stringify(queue, null, 2));
console.log("Posted and removed one item. Remaining:", queue.length);Step 3: Add the cron entry
Open your crontab with crontab -e and add a line that runs the script every weekday at 9 am. Load your token from a file the cron environment can read.
# minute hour day month weekday command
0 9 * * 1-5 cd /home/me/tg && /usr/bin/node --env-file=.env drain.mjs >> post.log 2>&1Result
Every weekday morning the scheduler posts the next queued item and shortens the file by one. Top up the queue once a week and your channel runs itself.
Watch related tutorials
13:10
1:42:18
28:14
41:09
9:47
8:23