Created
August 18, 2023 17:44
-
-
Save Haythamasalama/f60813df6aef30ee25314500bb5bd311 to your computer and use it in GitHub Desktop.
Automated Telegram Topic Generation using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subjects = [ | |
{ | |
name: "Quizzes", | |
icon_custom_emoji_id: "5433614043006903194", | |
text: "Quizzes Topic", | |
}, | |
// etc | |
]; | |
const telegramToken = ""; | |
const chatId = ""; | |
const createForumTopic = async ({ name, chat_id, icon_custom_emoji_id, text }) => { | |
const response = await ( | |
await fetch( | |
`https://api.telegram.org/bot${telegramToken}/createForumTopic?name=${name}&chat_id=${chat_id}&icon_custom_emoji_id=${icon_custom_emoji_id}` | |
) | |
).json(); | |
await ( | |
await fetch( | |
`https://api.telegram.org/bot${telegramToken}/sendMessage?chat_id=${chat_id}&text=${text}&message_thread_id=${response?.result?.message_thread_id}` | |
) | |
).json(); | |
console.log(response); | |
}; | |
const main = async () => { | |
await ( | |
await fetch( | |
`https://api.telegram.org/bot${telegramToken}/sendMessage?chat_id=${chatId}&text=started creating topics ...` | |
) | |
).json(); | |
for (const subject of subjects) { | |
await createForumTopic({ | |
name: subject.name, | |
chat_id: chatId, | |
icon_custom_emoji_id: subject.icon_custom_emoji_id, | |
text: subject.text, | |
}); | |
await new Promise((resolve) => setTimeout(resolve, 5 * 1000)); | |
} | |
await ( | |
await fetch( | |
`https://api.telegram.org/bot${telegramToken}/sendMessage?chat_id=${chatId}&text=finished creating topics ...` | |
) | |
).json(); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment