Code done task
const headers = {
accept: "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
lang: "en",
origin: "https://telegram.blum.codes",
priority: "u=1, i",
"sec-ch-ua": '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128", "Microsoft Edge WebView2";v="128"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0"
};
async function authenticate() {
const query = window.Telegram.WebView.initParams.tgWebAppData;
if (!query) {
console.log("🥹 CANNOT GET LOGIN INFORMATION. END 🥹");
return;
}
const response = await fetch('https://user-domain.blum.codes/api/v1/auth/provider/PROVIDER_TELEGRAM_MINI_APP', {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ query })
});
delete headers['Content-Type'];
if (response.ok) {
const { token: { access: token } } = await response.json();
headers['authorization'] = `Bearer ${token}`;
return 'OK';
}
return false;
}
async function getTasks() {
const response = await fetch('https://game-domain.blum.codes/api/v1/tasks', { headers });
if (response.ok) {
const data = await response.json();
const subSections = data[0]?.subSections || [];
if (subSections.length === 0) {
console.log("Cannot get Tasks information...");
return [];
}
return subSections.flatMap(info => info.tasks || []);
}
console.log("Failed to fetch tasks");
return [];
}
async function validateTask() {
const response = await fetch('https://game-domain.blum.codes/api/v1/tasks/38f6dd88-57bd-4b42-8712-286a06dac0a0/validate', {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ keyword: 'VALUE' })
});
delete headers['Content-Type'];
return response.ok ? 'OK' : false;
}
async function startTask(taskId) {
for (let i = 0; i < 3; i++) {
const response = await fetch(`https://game-domain.blum.codes/api/v1/tasks/${taskId}/start`, {
method: 'POST',
headers
});
if (response.ok) {
await response.json();
return 'OK';
}
console.log(" + Status: False.. try again");
await sleep(5000);
}
return false;
}
async function claimTask(taskId) {
for (let i = 0; i < 3; i++) {
const response = await fetch(`https://game-domain.blum.codes/api/v1/tasks/${taskId}/claim`, {
method: 'POST',
headers
});
if (response.ok) {
await response.json();
return 'Claim OK';
}
console.log(" + Status: False.. try again");
await sleep(5000);
}
return false;
}
async function start() {
let claim = false;
const authResult = await authenticate();
if (!authResult) {
console.log("CAN'T LOGIN");
return;
}
console.log("🐻 Start do BLUM Tasks..");
for (let i = 0; i < 2; i++) {
const allTasks = await getTasks();
if (!allTasks.length) return;
for (const task of allTasks) {
const { status: taskStatus, id: taskId, title: taskTitle } = task;
if (['Invite', 'Farm', 'Connect to wallet'].includes(taskTitle)) continue;
if (claim && taskStatus === 'READY_FOR_CLAIM') {
console.log(` - 🎁 Claim reward: ${taskTitle}`);
if (await claimTask(taskId)) {
console.log(` + Status: +${task.reward}BP`);
console.log(` - Waiting: ${getRandomInt(3, 7)} seconds to next task`);
}
await sleep(getRandomInt(3, 7) * 1000);
}
if (taskStatus === 'NOT_STARTED') {
console.log(` - 👨💻 Do tasks: ${taskTitle}`);
console.log(` + Status: ${await startTask(taskId)}`);
if (taskId === '38f6dd88-57bd-4b42-8712-286a06dac0a0') {
await sleep(5000);
await validateTask();
}
console.log(` - Waiting: ${getRandomInt(5, 10)} seconds to next task`);
await sleep(getRandomInt(5, 10) * 1000);
}
}
console.log("Do all Tasks.. Waiting 10 seconds to claim reward");
claim = true;
await sleep(10000);
console.log("Start claim reward..");
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
start().then(() => console.log("\n\n🥳🎆 DONE ALL 🥳🎆\n\n"));
Last updated