Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/notification.js
  • Loading branch information
louislam committed Jul 13, 2021
2 parents 866bf56 + e053ee6 commit 3e4a98b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 9 deletions.
43 changes: 34 additions & 9 deletions server/notification.js
Expand Up @@ -92,6 +92,24 @@ class Notification {
console.log(error)
return false;
}
return await Notification.discord(notification, msg)

} else if (notification.type === "signal") {
try {
let data = {
"message": msg,
"number": notification.signalNumber,
"recipients": notification.signalRecipients.replace(/\s/g, '').split(",")
};
let config = {};

let res = await axios.post(notification.signalURL, data, config)
return true;
} catch (error) {
console.log(error)
return false;
}

} else {
throw new Error("Notification type is not supported")
}
Expand Down Expand Up @@ -135,20 +153,15 @@ class Notification {

static async smtp(notification, msg) {

let data = {
let transporter = nodemailer.createTransport({
host: notification.smtpHost,
port: notification.smtpPort,
secure: notification.smtpSecure,
};

if (notification.smtpUsername) {
data.auth = {
auth: {
user: notification.smtpUsername,
pass: notification.smtpPassword,
};
}

let transporter = nodemailer.createTransport(data);
},
});

// send mail with defined transport object
let info = await transporter.sendMail({
Expand All @@ -160,6 +173,18 @@ class Notification {

return true;
}

static async discord(notification, msg) {
const client = new Discord.Client();
await client.login(notification.discordToken)

const channel = await client.channels.fetch(notification.discordChannelID);
await channel.send(msg);

client.destroy()

return true;
}
}

module.exports = {
Expand Down
36 changes: 36 additions & 0 deletions src/components/NotificationDialog.vue
Expand Up @@ -17,6 +17,7 @@
<option value="webhook">Webhook</option>
<option value="smtp">Email (SMTP)</option>
<option value="discord">Discord</option>
<option value="signal">Signal</option>
</select>
</div>

Expand Down Expand Up @@ -133,6 +134,41 @@
</div>
</template>

<template v-if="notification.type === 'signal'">
<div class="mb-3">
<label for="signal-url" class="form-label">Post URL</label>
<input type="url" pattern="https?://.+" class="form-control" id="signal-url" required v-model="notification.signalURL">

</div>

<div class="mb-3">
<label for="signal-number" class="form-label">Number</label>
<input type="text" class="form-control" id="signal-number" required v-model="notification.signalNumber">

</div>

<div class="mb-3">
<label for="signal-recipients" class="form-label">Recipients</label>
<input type="text" class="form-control" id="signal-recipients" required v-model="notification.signalRecipients">

<div class="form-text">
You need to have a signal client with REST API.

<p style="margin-top: 8px;">
You can check this url to view how to setup one:
</p>

<p style="margin-top: 8px;">
<a href="https://github.com/bbernhard/signal-cli-rest-api" target="_blank">https://github.com/bbernhard/signal-cli-rest-api</a>
</p>

<p style="margin-top: 8px;">
IMPORTANT: You cannot mix groups and numbers in recipients!
</p>
</div>
</div>
</template>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" @click="deleteConfirm" :disabled="processing" v-if="id">Delete</button>
Expand Down

0 comments on commit 3e4a98b

Please sign in to comment.