Flex Coder
2.05K subscribers
378 photos
66 videos
2 files
339 links
Uɴʟᴇᴀsʜ Tʜᴇ Pᴏᴡᴇʀ Oғ Bᴏᴛ Cᴏᴅɪɴɢ. Gᴇᴛ Fʀᴇᴇ Bᴏᴛ & Cᴏᴅᴇ Oɴ Oᴜʀ Cʜᴀɴɴᴇʟ 🧑‍💻

🔰 Oᴜʀ Yᴏᴜᴛᴜʙᴇ Cʜᴀɴɴᴇʟ: https://www.youtube.com/@Flex_Coder

📞 Cᴏɴᴛᴀᴄᴛ Us Oɴ: @Flex_Help
🌐 Oɴʟɪɴᴇ Fʀᴏᴍ: 3-07-2024
Download Telegram
Day 17/30: Metered Credit Burn & Quota Surcharge Ledger ⚡

SaaS developer tools running batch transforms or container runs cannot wait on manual invoices when an account hits high velocity. Instead of halting live pipelines mid-job, our CLI hits the bot to record usage against a balance and sync aggregate node consumption across the entire fleet in one atomic stroke. FlexGram handles state math directly against Firebase properties using .add() with signed values, eliminating manual read-modify-write race conditions.

📁 Filename: burn.js
👨‍💻 Code:
const [unitsStr, runId] = (params || '').trim().split(' ');
const units = parseInt(unitsStr, 10);
if (!units || !runId) return sendMessage('*Usage:* `/burn <units> <run_id>`');
const current = (await USER.getProp('compute_units').value()) || 0;
if (current < units) {
return sendMessage(`*Burn Rejected:* Insufficient balance.\n*Available:* \`${current}\` | *Requested:* \`${units}\``);
}
USER.add('compute_units', -units);
BOT.add('total_units_consumed', units);
sendMessage(`*Units Deducted:* \`-${units}\`\n*Remaining Balance:* \`${current - units}\`\n*Run Reference:* \`${runId}\``);


📁 Filename: grant.js
👨‍💻 Code:
const [tierName, amountStr] = (params || '').trim().split(' ');
const amount = parseInt(amountStr, 10);
if (!tierName || !amount) return sendMessage('*Usage:* `/grant <tier> <units>`');
USER.setProp('license_tier', tierName);
USER.add('compute_units', amount);
const updated = (await USER.getProp('compute_units').value()) || amount;
sendMessage(`*License Provisioned:* ${tierName}\n*Added Units:* \`+${amount}\`\n*Total Balance:* \`${updated}\``);


📁 Filename: quota.js
👨‍💻 Code:
const balance = (await USER.getProp('compute_units').value()) || 0;
const tier = (await USER.getProp('license_tier').value()) || 'Community';
const clusterBurn = (await BOT.getProp('total_units_consumed').value()) || 0;
sendMessage(`*Tier:* ${tier}\n*Available Units:* \`${balance}\`\n*Global Cluster Burn:* \`${clusterBurn}\``);


Passing negative integers directly into .add() safely decrements numeric properties without requiring manual arithmetic checks before saving 💡

⚠️ Note: Protect grant.js by checking user.telegramid against your authorized admin team IDs before invoking USER.add.


#FlexGram
👍1🐳1
❤1👍1🎉1
Flex Coder
Join Stream now: https://youtube.com/live/Af6flRdJ9PU
This is my first ever long video/stream, so it might not be as good as you expect, but I’d love to hear your thoughts!

As well as drop your valuable comment and like on stream/video 😊
⚡1
Day 18/30: Tiered Binary Fetch & Release Asset Dispatch 📦

Handing out private build tarballs through email links or one-off S3 presigned URLs gets messy fast when customers deploy across air-gapped or restricted VPC environments. With this setup, verified enterprise licensees inspect incoming build summaries and pull cryptographically signed release packages straight through Telegram on demand. The framework queries our internal registry API, displays Telegram's native upload indicator while signing the bundle, and streams the binary artifact directly into the chat session.

📁 Filename: command/changelog.js
👨‍💻 Code:
const tag = (params || 'latest').trim();
sendChatAction('typing');
const res = await HTTP.get({
url: `https://api.licensing.internal/releases/${tag}`,
headers: { 'Authorization': `Bearer ${process.env.REGISTRY_SECRET}` }
});
if (!res || !res.tag) return sendMessage(`❌ Release tag *${tag}* not found.`);
sendMessage(`📦 *Build ${res.tag}*\n\n${res.summary}\n\nSHA256:\n\`${res.sha256}\``, {
buttons: [{ text: `📥 Fetch ${res.tag} Binary`, command: `/download ${res.tag}` }]
});


📁 Filename: command/download.js
👨‍💻 Code:
const tier = await USER.getProp('tier').value();
if (!tier || tier === 'free') return sendMessage('⚠️ Direct binary downloads require an active *Pro* or *Enterprise* license tier.');
const tag = (params || 'latest').trim();
sendChatAction('upload_document');
const build = await HTTP.post({
url: 'https://api.licensing.internal/binaries/sign',
body: { tag, licensee_id: user.id, tier },
headers: { 'Authorization': `Bearer ${process.env.REGISTRY_SECRET}` }
});
if (!build || !build.url) return sendMessage(`❌ Failed to sign binary bundle for *${tag}*. Check tag name.`);
sendDocument(build.url, { caption: `✅ *License Verified: ${tier.toUpperCase()}*\nBuild: \`${build.tag}\`\nExpires: \`${build.expires_in}\`` });


💡 Passing a direct HTTPS download URL to sendDocument offloads file streaming entirely to Telegram's cloud ingestion servers, avoiding Node.js memory exhaustion on large archive payloads. 🚀

⚠️ Note: Define REGISTRY_SECRET in your environment variables to authenticate backend requests against your private binary repository.


#FlexGram
🐳1
Day 19/30: Fleet Security Advisory & Critical Patch Broadcast 📢

Chasing down distributed engineering teams to apply an urgent security hotfix over email or Discord announcements is an exercise in futility. When a critical CVE drops against our engine, we need an instant panic button inside Telegram that blasts the bulletin directly to active runtime administrators, throttles outbound throughput to dodge API caps, and reports delivery metrics in real time. FlexGram makes fleet-wide emergency dispatches trivial by chaining temporary memory drafts with the built-in throttled broadcast utility.

📁 Filename: command/advisory.js
👨‍💻 Code:
sendChatAction('typing');
sendMessage('*Emergency Fleet Dispatch*\nSend the patch bulletin text to broadcast across all provisioned client nodes:');
waitForAnswer('/draft_advisory');


📁 Filename: command/draft_advisory.js
👨‍💻 Code:
clearWait();
TEMP.setProp('patch_text', message);
const actions = [{ text: '🚀 Fire Fleet Broadcast', command: '/dispatch_advisory' }];
sendMessage(`*Bulletin Draft Review:*\n\n${message}\n\nPush this update immediately to all registered operators?`, { buttons: actions });


📁 Filename: command/dispatch_advisory.js
👨‍💻 Code:
answerCallback('Initiating fleet dispatch...');
const bulletin = await TEMP.getProp('patch_text').value();
const records = await getDB('users') || {};
const recipients = Object.keys(records);
const payload = `🚨 *CRITICAL ENGINE ADVISORY*\n\n${bulletin}`;
const buttons = [{ text: 'Download Hotfix Patch', url: 'https://dist.example.com/patches/latest' }];
const stats = await broadcast(recipients, payload, buttons, 40);
sendMessage(`*Broadcast Complete*\nDelivered: ${stats.sent} nodes\nFailed: ${stats.failed} nodes`);


Configuring a delayMs spacing between 40ms and 50ms ensures high-volume dispatches fly beneath Telegram global rate limits without dropping connection sockets. ⚡

⚠️ Note: Restrict the initial /advisory trigger by verifying user.id against an authorized admin list before opening the intake wait state.


#FlexGram
❤1⚡1
✍️ New Rich Message Update (Private message visibility)

📂  Filename: command/start.js
👨‍💻 Code:

const tg = async (method, body) => {
const res = await HTTP.post({
url: `https://api.telegram.org/bot${process.env.BOT_TOKEN}/${method}`,
body,
});
if (!res.ok) throw new Error(`${method}: ${res.description}`);
return res.result;
};

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

export default async function secret(flex) {
const chatId = flex.chat.id;
const userId = flex.user.id;

if (flex.isCallback) {
await answerCallback();
await tg("sendMessage", {
chat_id: chatId,
text: "Only you can see this message.",
ephemeral_message_parameters: {
receiver_user_id: userId,
callback_query_id: flex.callbackQueryId,
replace_callback_query_message: true,
},
});
return;
}

const sent = await tg("sendMessage", {
chat_id: chatId,
text: "Private note for you.",
ephemeral_message_parameters: { receiver_user_id: userId },
});

await sleep(2000);

await tg("editEphemeralMessageText", {
chat_id: chatId,
receiver_user_id: userId,
ephemeral_message_id: sent.message_id,
text: "Edited private note.",
});

await sleep(2000);

await tg("deleteEphemeralMessage", {
chat_id: chatId,
receiver_user_id: userId,
ephemeral_message_id: sent.message_id,
});

await sendMessage("Tap to reveal a private message.", {
buttons: [{ text: "Reveal", command: "/secret reveal" }],
});
}

📍 Credit & Copyrighted by Flex Coder
❤2👍1
🔥 New Button & Keyboard UI

📂 Filename:
command/start.js
📍Button Code
👨‍💻 Code:

export default async function (flex) {
const token = process.env.BOT_TOKEN;

const inline_keyboard = [
[
{ text: "Normal", callback_data: "normal" },
{ text: "Primary", callback_data: "primary", style: "primary" },
],
[
{ text: "Success", callback_data: "success", style: "success" },
{ text: "Danger", callback_data: "danger", style: "danger" },
],
];

await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
chat_id: chat.id,
text: "<b>🔥 New Inline Buttons UI</b>",
parse_mode: "HTML",
reply_to_message_id: message_id,
reply_markup: { inline_keyboard },
}),
});
}
❤‍🔥1👍1🤩1
📂 Filename: command/start.js
📍Keyboard Code
👨‍💻 Code:

export default async function (flex) {
const token = process.env.BOT_TOKEN;

const keyboard = [
[
{ text: "Normal" },
{ text: "Primary", style: "primary" },
],
[
{ text: "Success", style: "success" },
{ text: "Danger", style: "danger" },
],
];

await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
chat_id: chat.id,
text: "<b>🔥 New Keyboard UI</b>",
parse_mode: "HTML",
reply_to_message_id: message_id,
reply_markup: {
keyboard,
resize_keyboard: true,
one_time_keyboard: false,
},
}),
});
}
❤1👍1
Media is too big
VIEW IN TELEGRAM
✨ FlexGram Code Testing Tutorial ✨

Over the past few days, i’ve been sharing FlexGram code snippets. However, i noticed some members are having trouble adding and testing them properly.

Follow this quick guide to run and test all upcoming code.


⚠️ Important Notes:

1. Before running nodemon main.js, make sure nodemon is installed globally or locally using:
npm i nodemon

2. Before running ngrok http 3000, download and set up ngrok from the official website (click here to download)
👏1