Created
April 6, 2023 10:43
-
-
Save parsibox/ee16df89ba538edd26619006be6fa647 to your computer and use it in GitHub Desktop.
getafreenode check remaining Traffic with cloadflare worker
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
addEventListener('scheduled', event => { | |
event.waitUntil( | |
handleScheduledEvent() | |
) | |
}) | |
async function handleScheduledEvent() { | |
//in ghesmat ra taghir bedid | |
const uuid='xxxxx-038D-xxxxx-9F95-xxxxx'; | |
const telegram_token='123123:xxxxxx'; | |
const telegram_chat_id='123123'; | |
// | |
const url = "https://getafreenode.com/vendor/api.php?act=getuserinfo&uuid="+uuid; | |
const response = await fetch(url); | |
const json = await response.json(); | |
console.log( json ); | |
if (json.hasOwnProperty("remainingTraffic")) { | |
const remaining_traffic = parseFloat(json.remainingTraffic); | |
console.log( remaining_traffic ); | |
if (remaining_traffic < 3) { | |
// Call your URL here | |
// Example: | |
// Replace <BOT_TOKEN> and <CHAT_ID> with your actual token and chat ID | |
const url = `https://api.telegram.org/bot${telegram_token}/sendMessage?chat_id=${telegram_chat_id}&text=my-traffic-is-${remaining_traffic}` | |
const response = await fetch(url) | |
// Log the response status to the Cloudflare Workers console | |
console.log(`Telegram API response: ${response.status}`) | |
console.log("Called URL because remaining traffic is less than 3G."); | |
return true; | |
} | |
else { | |
console.log("Remaining traffic is greater than or equal to 3G."+remaining_traffic+""); | |
return true; | |
} | |
} | |
else { | |
console.log("Unable to find remaining traffic information in the response."); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment