TBH Broadcast Example - supports links buttons , image , video almost all
Command: /broadcast
TBL Code:const ADMIN_ID = 123456789
if (user.telegramid != ADMIN_ID) {
return
}
if (!request.reply_to_message) {
return Bot.sendMessage(
"❌ Reply to a message with /broadcast"
)
}
let users = await Bot.getUsers({
chatType: "private"
})
if (!users?.length) {
return Bot.sendMessage(
"❌ No users found"
)
}
let msg = request.reply_to_message
let sent = 0
let failed = 0
let status = await Api.sendMessage({
text:
"📢 Broadcast Started\n\n" +
"👥 Total: " + users.length
})
let hasButtons =
msg.reply_markup?.inline_keyboard
let methods = {
photo: "sendPhoto",
video: "sendVideo",
document: "sendDocument",
animation: "sendAnimation",
audio: "sendAudio",
voice: "sendVoice"
}
let type = Object.keys(methods)
.find(x => msg[x])
for (let chat_id of users) {
try {
if (!hasButtons) {
await Api.copyMessage({
chat_id,
from_chat_id: msg.chat.id,
message_id: msg.message_id
})
} else {
let data = {
chat_id,
reply_markup: msg.reply_markup
}
if (type) {
data[type] =
type === "photo"
? msg.photo.at(-1).file_id
: msg[type].file_id
data.caption = msg.caption
data.caption_entities =
msg.caption_entities
await Api.call(
methods[type],
data
)
} else {
data.text =
msg.text ||
msg.caption ||
""
data.entities =
msg.entities ||
msg.caption_entities
await Api.sendMessage(data)
}
}
sent++
} catch {
try {
await Api.forwardMessage({
chat_id,
from_chat_id: msg.chat.id,
message_id: msg.message_id
})
sent++
} catch {
failed++
}
}
}
await status.editText(
"📢 Broadcast Completed\n\n" +
"👥 Total: " + users.length +
"\n✅ Sent: " + sent +
"\n❌ Failed: " + failed
)
Note: Customize it based on your needs
platform: telebothost.comDeveloper: @CyberXCoding