mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-04 21:56:12 +08:00 
			
		
		
		
	- I unified where in file the name of `NotificationProvider.name` is placed - I made sure that all the providers adhere to the signature of `NotificationProvider.send()` - I made sure that all the providers use `okMsg` if returning success messages directly from the function. Here a discussion should be had: Should this be refactored into a constant of `NotificationProvider`? I could imagine that `NotificationProvider.SENDING_SUCCESSFULL` could be a suitable alternative. - I made sure all providers have the URL they `POST`/`GET` to be extraced into a variable. => refactored this way due to Nelsons suggestion
		
			
				
	
	
		
			35 lines
		
	
	
		
			892 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			892 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const NotificationProvider = require("./notification-provider");
 | 
						|
const axios = require("axios");
 | 
						|
 | 
						|
class Kook extends NotificationProvider {
 | 
						|
    name = "Kook";
 | 
						|
 | 
						|
    /**
 | 
						|
     * @inheritdoc
 | 
						|
     */
 | 
						|
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
 | 
						|
        const okMsg = "Sent Successfully.";
 | 
						|
        const url = "https://www.kookapp.cn/api/v3/message/create";
 | 
						|
 | 
						|
        let data = {
 | 
						|
            target_id: notification.kookGuildID,
 | 
						|
            content: msg,
 | 
						|
        };
 | 
						|
        let config = {
 | 
						|
            headers: {
 | 
						|
                "Authorization": "Bot " + notification.kookBotToken,
 | 
						|
                "Content-Type": "application/json",
 | 
						|
            },
 | 
						|
        };
 | 
						|
        try {
 | 
						|
            await axios.post(url, data, config);
 | 
						|
            return okMsg;
 | 
						|
 | 
						|
        } catch (error) {
 | 
						|
            this.throwGeneralAxiosError(error);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
module.exports = Kook;
 |