Skip to content

Instantly share code, notes, and snippets.

@emindeniz99
Created June 8, 2021 13:35
Show Gist options
  • Save emindeniz99/91f11627715c7f2a2a271cd455633c7a to your computer and use it in GitHub Desktop.
Save emindeniz99/91f11627715c7f2a2a271cd455633c7a to your computer and use it in GitHub Desktop.
turknet vdsl port sorgulama, aws lambda + telegram notification with daily report
const https = require('https');
exports.handler = async(event) => {
// CHANGE BBK
const data = JSON.stringify({ "Key": "BBK", "Value": "Your BBK code (integer)" });
let dataString = "";
const response = await new Promise((resolve, reject) => {
const req = https.request({
hostname: 'turk.net',
port: 443,
path: '/service/AddressServ.svc/CheckServiceAvailability',
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
// CHANGE token
"token": "Your JWT Token that includes sales id"
}
}, function(res) {
res.on('data', chunk => {
dataString += chunk;
});
res.on('end', () => {
resolve({
statusCode: 200,
// body: JSON.stringify(JSON.parse(dataString), null, 4)
body: JSON.parse(dataString)
});
});
});
req.write(data)
req.on('error', (e) => {
reject({
statusCode: 500,
body: 'Something went wrong!'
});
});
});
console.log(JSON.stringify(response, null, 4), new Date().getHours())
if (response.body.Result.VDSLServiceAvailability.IsAvailable || new Date().getHours() == 14) {
// CHANGE chatid
const tgdata = JSON.stringify({ chat_id: -0000000, text: (response.body.Result.VDSLServiceAvailability.IsAvailable ? "VDSL PORT VAR \n " : "Daily Report\n") + JSON.stringify(response, null, 4) });
let tgdataString = "";
const tgresponse = await new Promise((resolve, reject) => {
const req = https.request({
hostname: 'api.telegram.org',
port: 443,
// CHANGE bot token
path: '/bot:......../sendMessage',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': tgdata.length,
}
}, function(res) {
res.on('data', chunk => {
tgdataString += chunk;
});
res.on('end', () => {
resolve({
statusCode: 200,
// body: JSON.stringify(JSON.parse(dataString), null, 4)
body: JSON.parse(tgdataString)
});
});
});
req.write(tgdata)
req.on('error', (e) => {
reject({
statusCode: 500,
body: 'Something went wrong!'
});
});
});
return tgresponse;
}
else {
return {
statusCode: 200,
body: 'No VDSL port!'
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment