71 lines
2.7 KiB
JavaScript
71 lines
2.7 KiB
JavaScript
const admin = require("firebase-admin");
|
|
|
|
module.exports = async (req, res) => {
|
|
console.info(
|
|
`[START]\tWEBHOOKS/Conference End\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
|
);
|
|
// MAKE SURE CORRECT EVENT TYPE
|
|
if (req.body.eventType === "Conference.Ended") {
|
|
// MAKE SURE IT'S NOT A DUPLICATE FROM CREATE CONFLICT
|
|
if (req.body.participants.length > 0) {
|
|
// MAKE SURE ELIGIBLE FOR DELETE
|
|
if (req.body.confAlias.startsWith("AUTODELETE_")) {
|
|
const partyName = req.body.confAlias.replace(/AUTODELETE_/, "");
|
|
const existingConference = await admin
|
|
.firestore()
|
|
.collection("rooms")
|
|
.doc(partyName)
|
|
.get()
|
|
.then((snap) => (snap.exists ? snap.data().conference : null));
|
|
// MAKE SURE EXISTS AND HAS NOT BEEN REPLACED
|
|
if (
|
|
existingConference &&
|
|
existingConference._id === req.body.conference.confId
|
|
) {
|
|
// REMOVE CONFERENCE DETAILS
|
|
await admin
|
|
.firestore()
|
|
.collection("rooms")
|
|
.doc(partyName)
|
|
.update({ conference: admin.firestore.FieldValue.delete() })
|
|
.then(() => {
|
|
console.info(
|
|
`[DONE]\tWEBHOOKS/Conference End\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
|
);
|
|
return;
|
|
})
|
|
.catch((err) => {
|
|
console.error(
|
|
`[ERROR]\tWEBHOOKS/Conference End/Firebase Error\tID:${
|
|
req.body.conference.confId
|
|
}\tParty:${
|
|
req.body.conference.confAlias
|
|
}\tError:${JSON.stringify(err)}`
|
|
);
|
|
});
|
|
} else {
|
|
console.info(
|
|
`[DONE]\tWEBHOOKS/Conference End/Conference Was Already Replaced\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
|
);
|
|
}
|
|
res.status(200).send({ message: "Processed conference end" });
|
|
} else {
|
|
console.info(
|
|
`[DONE]\tWEBHOOKS/Conference End/Not Eligible For Autodelete\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
|
);
|
|
res.status(200).send({ message: "Processed conference end" });
|
|
}
|
|
} else {
|
|
console.info(
|
|
`[DONE]\tWEBHOOKS/Conference End/End Of Duplicate Conference\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
|
);
|
|
}
|
|
} else {
|
|
console.error(
|
|
`[ERROR]\tWEBHOOKS/Conference End/Wrong Event Type\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
|
);
|
|
res.status(400).send({ message: "Wrong event type" });
|
|
}
|
|
return;
|
|
};
|