mirror of https://github.com/louislam/uptime-kuma
				
				
				
			feat: add notification provider `PushPlus` (#5716)
Co-authored-by: Teror Fox <i@trfox.top> Co-authored-by: Frank Elsinga <frank@elsinga.de>pull/5732/head
							parent
							
								
									10a518e72e
								
							
						
					
					
						commit
						30f82b9cb4
					
				| 
						 | 
				
			
			@ -0,0 +1,56 @@
 | 
			
		|||
const NotificationProvider = require("./notification-provider");
 | 
			
		||||
const axios = require("axios");
 | 
			
		||||
const { DOWN, UP } = require("../../src/util");
 | 
			
		||||
 | 
			
		||||
class PushPlus extends NotificationProvider {
 | 
			
		||||
    name = "PushPlus";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @inheritdoc
 | 
			
		||||
     * @param {BeanModel} notification Notification object
 | 
			
		||||
     * @param {string} msg Message content
 | 
			
		||||
     * @param {?object} monitorJSON Monitor details
 | 
			
		||||
     * @param {?object} heartbeatJSON Heartbeat details
 | 
			
		||||
     * @returns {Promise<string>} Success message
 | 
			
		||||
     */
 | 
			
		||||
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
 | 
			
		||||
        const okMsg = "Sent Successfully.";
 | 
			
		||||
        const url = "https://www.pushplus.plus/send";
 | 
			
		||||
        try {
 | 
			
		||||
            const config = {
 | 
			
		||||
                headers: {
 | 
			
		||||
                    "Content-Type": "application/json",
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
            const params = {
 | 
			
		||||
                "token": notification.pushPlusSendKey,
 | 
			
		||||
                "title": this.checkStatus(heartbeatJSON, monitorJSON),
 | 
			
		||||
                "content": msg,
 | 
			
		||||
                "template": "html"
 | 
			
		||||
            };
 | 
			
		||||
            await axios.post(url, params, config);
 | 
			
		||||
            return okMsg;
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            this.throwGeneralAxiosError(error);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the formatted title for message
 | 
			
		||||
     * @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
 | 
			
		||||
     * @param {?object} monitorJSON Monitor details (For Up/Down only)
 | 
			
		||||
     * @returns {string} Formatted title
 | 
			
		||||
     */
 | 
			
		||||
    checkStatus(heartbeatJSON, monitorJSON) {
 | 
			
		||||
        let title = "UptimeKuma Message";
 | 
			
		||||
        if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
 | 
			
		||||
            title = "UptimeKuma Monitor Up " + monitorJSON["name"];
 | 
			
		||||
        }
 | 
			
		||||
        if (heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
 | 
			
		||||
            title = "UptimeKuma Monitor Down " + monitorJSON["name"];
 | 
			
		||||
        }
 | 
			
		||||
        return title;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = PushPlus;
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +39,7 @@ const PromoSMS = require("./notification-providers/promosms");
 | 
			
		|||
const Pushbullet = require("./notification-providers/pushbullet");
 | 
			
		||||
const PushDeer = require("./notification-providers/pushdeer");
 | 
			
		||||
const Pushover = require("./notification-providers/pushover");
 | 
			
		||||
const PushPlus = require("./notification-providers/pushplus");
 | 
			
		||||
const Pushy = require("./notification-providers/pushy");
 | 
			
		||||
const RocketChat = require("./notification-providers/rocket-chat");
 | 
			
		||||
const SerwerSMS = require("./notification-providers/serwersms");
 | 
			
		||||
| 
						 | 
				
			
			@ -128,6 +129,7 @@ class Notification {
 | 
			
		|||
            new Pushbullet(),
 | 
			
		||||
            new PushDeer(),
 | 
			
		||||
            new Pushover(),
 | 
			
		||||
            new PushPlus(),
 | 
			
		||||
            new Pushy(),
 | 
			
		||||
            new RocketChat(),
 | 
			
		||||
            new ServerChan(),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -182,6 +182,7 @@ export default {
 | 
			
		|||
                "SMSManager": "SmsManager (smsmanager.cz)",
 | 
			
		||||
                "WeCom": "WeCom (企业微信群机器人)",
 | 
			
		||||
                "ServerChan": "ServerChan (Server酱)",
 | 
			
		||||
                "PushPlus": "PushPlus (推送加)",
 | 
			
		||||
                "smsc": "SMSC",
 | 
			
		||||
                "WPush": "WPush(wpush.cn)",
 | 
			
		||||
                "YZJ": "YZJ (云之家自定义机器人)"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <div class="mb-3">
 | 
			
		||||
        <label for="pushPlus-sendkey" class="form-label">{{ $t("SendKey") }}</label>
 | 
			
		||||
        <HiddenInput id="pushPlus-sendkey" v-model="$parent.notification.pushPlusSendKey" :required="true" autocomplete="new-password"></HiddenInput>
 | 
			
		||||
    </div>
 | 
			
		||||
    <i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
 | 
			
		||||
        <a href="https://www.pushplus.plus/" target="_blank">https://www.pushplus.plus/</a>
 | 
			
		||||
    </i18n-t>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import HiddenInput from "../HiddenInput.vue";
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    components: {
 | 
			
		||||
        HiddenInput,
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +39,7 @@ import PromoSMS from "./PromoSMS.vue";
 | 
			
		|||
import Pushbullet from "./Pushbullet.vue";
 | 
			
		||||
import PushDeer from "./PushDeer.vue";
 | 
			
		||||
import Pushover from "./Pushover.vue";
 | 
			
		||||
import PushPlus from "./PushPlus.vue";
 | 
			
		||||
import Pushy from "./Pushy.vue";
 | 
			
		||||
import RocketChat from "./RocketChat.vue";
 | 
			
		||||
import ServerChan from "./ServerChan.vue";
 | 
			
		||||
| 
						 | 
				
			
			@ -116,6 +117,7 @@ const NotificationFormList = {
 | 
			
		|||
    "PushByTechulus": TechulusPush,
 | 
			
		||||
    "PushDeer": PushDeer,
 | 
			
		||||
    "pushover": Pushover,
 | 
			
		||||
    "PushPlus": PushPlus,
 | 
			
		||||
    "pushy": Pushy,
 | 
			
		||||
    "rocket.chat": RocketChat,
 | 
			
		||||
    "serwersms": SerwerSMS,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue