Skip to content

Instantly share code, notes, and snippets.

@bagaskarala
Last active August 4, 2022 09:34
Show Gist options
  • Save bagaskarala/9876216f497a7847ed6f3e68ac146a2e to your computer and use it in GitHub Desktop.
Save bagaskarala/9876216f497a7847ed6f3e68ac146a2e to your computer and use it in GitHub Desktop.
Telegram broadcast multiple groups using bot

Usage:

  • create bot in @BotFather, get the token.
  • add our bot to group.
  • get group chat id, by adding @RawDataBot. After got the id, remove this bot from group.
  • fill some data in script.
  • run the script in online compiler, example: https://www.typescriptlang.org/play.
const chatIdList = ['xxx','yyy','zzz'];
const botToken = 'xxx';
const message = 'your message here';
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
for (let i = 0; i < chatIdList.length; i++) {
fetch(`https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatIdList[i]}&text=${message}&parse_mode=markdown`)
.then(response => response.json())
.then(response => {
console.log({ status: `${chatIdList[i]}: ${response.ok}` });
}).catch(err => {
console.log('error! ', err);
});
await sleep(1000);
}
console.log("done");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment