Doorbell works, added user friendliness for setup
This commit is contained in:
26
index.mjs
26
index.mjs
@@ -13,6 +13,17 @@ const homeserverUrl = config.homeserver;
|
||||
const token = config.token;
|
||||
const prefix = config.prefix;
|
||||
const rooms = config.rooms;
|
||||
const doorbellWebhook = config.doorbellWebhook;
|
||||
|
||||
function configNotFound(name) {
|
||||
throw new Error(`ERROR: Config option "${name}" not found`);
|
||||
}
|
||||
|
||||
if (!homeserverUrl) configNotFound("homeserver");
|
||||
if (!token) configNotFound("token");
|
||||
if (!prefix) configNotFound("prefix");
|
||||
if (!rooms) configNotFound("rooms");
|
||||
if (!doorbellWebhook) configNotFound("doorbellWebhook");
|
||||
|
||||
// We'll want to make sure the bot doesn't have to do an initial sync every
|
||||
// time it restarts, so we need to prepare a storage provider. Here we use
|
||||
@@ -59,12 +70,15 @@ async function handleCommand(roomId, event) {
|
||||
const text = rawText.substring(prefix.length);
|
||||
|
||||
if (["doorbell", "open", "ring", "knock", "ding", "dong", "dingdong"].includes(text)) {
|
||||
fetch('https://homeassistant.pvv.ntnu.no:8123/api/webhook/doorbell-oRkXU_ZUFzkc4wTtc6_m9PFR', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type' : 'application/json'
|
||||
},
|
||||
})
|
||||
|
||||
fetch(doorbellWebhook, { method: 'POST' }).then(response => {
|
||||
if (response.ok) {
|
||||
console.log("DING DONG!");
|
||||
} else {
|
||||
console.log("No ding dong :(");
|
||||
console.log(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var tags = [];
|
||||
|
||||
Reference in New Issue
Block a user