Add Echobell provider

This commit is contained in:
headlessdev 2025-04-29 22:52:29 +02:00
parent 1a395783b0
commit 1fccc59c01
9 changed files with 43 additions and 24 deletions

View File

@ -86,7 +86,7 @@ func LoadNotifications(db *sql.DB) ([]models.Notification, error) {
rows, err := db.Query(
`SELECT id, enabled, type, "smtpHost", "smtpPort", "smtpFrom", "smtpUser", "smtpPass", "smtpSecure", "smtpTo",
"telegramChatId", "telegramToken", "discordWebhook", "gotifyUrl", "gotifyToken", "ntfyUrl", "ntfyToken",
"pushoverUrl", "pushoverToken", "pushoverUser"
"pushoverUrl", "pushoverToken", "pushoverUser", "echobellUrl"
FROM notification
WHERE enabled = true`,
)
@ -103,7 +103,7 @@ func LoadNotifications(db *sql.DB) ([]models.Notification, error) {
&n.SMTPHost, &n.SMTPPort, &n.SMTPFrom, &n.SMTPUser, &n.SMTPPass, &n.SMTPSecure, &n.SMTPTo,
&n.TelegramChatID, &n.TelegramToken, &n.DiscordWebhook,
&n.GotifyUrl, &n.GotifyToken, &n.NtfyUrl, &n.NtfyToken,
&n.PushoverUrl, &n.PushoverToken, &n.PushoverUser,
&n.PushoverUrl, &n.PushoverToken, &n.PushoverUser, &n.EchobellURL,
); err != nil {
fmt.Printf("Error scanning notification: %v\n", err)
continue

View File

@ -94,4 +94,5 @@ type Notification struct {
PushoverUrl sql.NullString
PushoverToken sql.NullString
PushoverUser sql.NullString
EchobellURL sql.NullString
}

View File

@ -84,6 +84,10 @@ func (ns *NotificationSender) SendSpecificNotification(n models.Notification, me
if n.PushoverUrl.Valid && n.PushoverToken.Valid && n.PushoverUser.Valid {
ns.sendPushover(n, message)
}
case "echobell":
if n.EchobellURL.Valid {
ns.sendEchobell(n, message)
}
}
}
@ -237,3 +241,26 @@ func (ns *NotificationSender) sendPushover(n models.Notification, message string
fmt.Printf("Pushover: ERROR status code: %d\n", resp.StatusCode)
}
}
func (ns *NotificationSender) sendEchobell(n models.Notification, message string) {
jsonData := fmt.Sprintf(`{"message": "%s"}`, message)
req, err := http.NewRequest("POST", n.EchobellURL.String, strings.NewReader(jsonData))
if err != nil {
fmt.Printf("Echobell: ERROR creating request: %v\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Echobell: ERROR sending request: %v\n", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Printf("Echobell: ERROR status code: %d\n", resp.StatusCode)
}
}

View File

@ -22,13 +22,12 @@ interface AddRequest {
pushoverToken?: string;
pushoverUser?: string;
echobellURL?: string;
echobellData?: string;
}
export async function POST(request: NextRequest) {
try {
const body: AddRequest = await request.json();
const { type, name, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, smtpFrom, smtpTo, telegramToken, telegramChatId, discordWebhook, gotifyUrl, gotifyToken, ntfyUrl, ntfyToken, pushoverUrl, pushoverToken, pushoverUser, echobellURL, echobellData } = body;
const { type, name, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, smtpFrom, smtpTo, telegramToken, telegramChatId, discordWebhook, gotifyUrl, gotifyToken, ntfyUrl, ntfyToken, pushoverUrl, pushoverToken, pushoverUser, echobellURL } = body;
const notification = await prisma.notification.create({
data: {
@ -51,8 +50,7 @@ export async function POST(request: NextRequest) {
pushoverUrl: pushoverUrl,
pushoverToken: pushoverToken,
pushoverUser: pushoverUser,
echobellURL: echobellURL,
echobellData: echobellData,
echobellURL: echobellURL
}
});

View File

@ -83,7 +83,6 @@ export default function Settings() {
const [pushoverToken, setPushoverToken] = useState<string>("")
const [pushoverUser, setPushoverUser] = useState<string>("")
const [echobellURL, setEchobellURL] = useState<string>("")
const [echobellData, setEchobellData] = useState<string>("")
const [language, setLanguage] = useState<string>("english")
const [notifications, setNotifications] = useState<any[]>([])
@ -193,7 +192,6 @@ export default function Settings() {
pushoverToken: pushoverToken,
pushoverUser: pushoverUser,
echobellURL: echobellURL,
echobellData: echobellData,
})
getNotifications()
} catch (error: any) {
@ -701,17 +699,7 @@ export default function Settings() {
onChange={(e) => setEchobellURL(e.target.value)}
/>
</div>
<div className="grid w-full items-center gap-1.5">
<Label>{t('Settings.Notifications.AddNotification.Echobell.Data')}</Label>
<Textarea
placeholder={`e.g.:
"title": "Server Status",
"message": "Server is online"
`}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => setEchobellData(e.target.value)}
rows={4}
/>
</div>
<span className="text-xs text-muted-foreground">Add in Echobell the "message" field.</span>
</div>
)}

View File

@ -384,8 +384,7 @@
},
"Echobell": {
"Title": "Echobell",
"Url": "Echobell-URL",
"Data": "Echobell-Data"
"Url": "Echobell-URL"
}
},
"CustomizeText": {

View File

@ -384,8 +384,7 @@
},
"Echobell": {
"Title": "Echobell",
"Url": "Echobell URL",
"Data": "Echobell Data"
"Url": "Echobell URL"
}
},
"CustomizeText": {

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `echobellData` on the `notification` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "notification" DROP COLUMN "echobellData";

View File

@ -105,7 +105,6 @@ model notification {
pushoverToken String?
pushoverUser String?
echobellURL String?
echobellData String?
}
model test_notification {