Pushing product announcements or community updates to thousands of users in a raw JavaScript loop is a fast track to Telegram API 429 rate-limit errors. FlexGram includes a built-in throttled broadcast helper that safely queues messages with custom delays while returning total delivery counts. Here is how to build a clean two-step admin dispatcher that pulls subscriber IDs straight from Firebase.
📁 Filename:
command/start.js👨💻 Code:
await FLEX.setProperty('active', true)
const statusText = 'Welcome! You are now subscribed to automated community alerts.'
sendMessage(statusText, { buttons: [{ text: 'Check Status', command: '/status' }] })📁 Filename:
command/status.js👨💻 Code:
const isActive = await FLEX.getProperty('active').value()
const text = isActive ? 'Subscription: *Active*' : 'Subscription: *Inactive*'
sendMessage(text)📁 Filename:
command/announce.js👨💻 Code:
if (String(user.telegramid) !== process.env.ADMIN_ID) return sendMessage('Access denied.')
sendMessage('Send the text you want to broadcast across all active subscribers:')
waitForAnswer('dispatch_announce')📁 Filename:
command/dispatch_announce.js👨💻 Code:
clearWait()
const usersData = await getDB('users') || {}
const subscriberIds = Object.keys(usersData)
sendMessage(`Dispatching updates to ${subscriberIds.length} users with 100ms throttle...`)
const stats = await broadcast(subscriberIds, message, null, 100)
sendMessage(`Dispatch finished! Delivered: *${stats.sent}* | Failed: *${stats.failed}*`)
💡 Passing a 100ms delay to
broadcast keeps your API requests well under Telegram's global 30 messages per second limit during big announcements.⚠️ Note: Ensure your ADMIN_ID environment variable is set to your numeric Telegram user ID to restrict access to the broadcast trigger.#FlexGram