Skip to content

Commit

Permalink
added scheduled "poke" function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmichels committed May 2, 2020
1 parent faaa7af commit bc27eb6
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions firebase/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ const https = require('postman-request');
// response.send("Hello from Firebase!");
// });

exports.scheduledFunction = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
https.post({
url:'https://us-central1-lol-boosted.cloudfunctions.net/sendNotification',
json:{
'event':'poke'
}
},(err,httpsRes,body)=>{
if(err){
// console.error("error:");
console.error(err);
return;
}
else{
// console.log("notification sent");
return;
}
})
return null;
});

exports.sendNotification = functions.https.onRequest((request, response) => {
// console.log("requests:");
// console.log(request.body);
Expand All @@ -27,9 +47,10 @@ exports.sendNotification = functions.https.onRequest((request, response) => {
}
}
else if(request.body.event==='poke'){
response.send('awake');
return;
}
else{
else if(request.body.event==='match found'){
formdata = {
"app_key": process.env.app_key,
"app_secret": process.env.app_secret,
Expand All @@ -38,6 +59,10 @@ exports.sendNotification = functions.https.onRequest((request, response) => {
"pushed_id":request.body.id,
}
}
else{
response.status('400').send('bad format');
return;
}

https.post({
url: 'https://api.pushed.co/1/push',
Expand All @@ -53,6 +78,6 @@ exports.sendNotification = functions.https.onRequest((request, response) => {
return;
}
})
response.send(request.body);
response.send();
return;
});

0 comments on commit bc27eb6

Please sign in to comment.