@@ -2,6 +2,7 @@ package wigo
22
33import (
44 "bytes"
5+ "context"
56 "crypto/tls"
67 "encoding/json"
78 "fmt"
@@ -11,6 +12,7 @@ import (
1112 "net/mail"
1213 "net/smtp"
1314 "net/url"
15+ "os/exec"
1416 "time"
1517)
1618
@@ -257,3 +259,60 @@ func CallbackHttp(json string) (e error) {
257259
258260 return nil
259261}
262+
263+ func SendApprise (summary string , message string ) {
264+
265+ log .Printf ("We're gonna launch apprise notif..." )
266+
267+ config := GetLocalWigo ().GetConfig ().Notifications
268+
269+ // Check if Apprise is enabled
270+ if config .AppriseEnabled == 0 {
271+ return
272+ }
273+
274+ // Check if URLs are configured
275+ if len (config .AppriseUrls ) == 0 {
276+ log .Printf ("Apprise is enabled but no URLs are configured" )
277+ return
278+ }
279+
280+ apprisePath := config .ApprisePath
281+
282+ // Ensure summary is not empty (Apprise requires it)
283+ appriseSummary := summary
284+ if appriseSummary == "" {
285+ appriseSummary = message
286+ if appriseSummary == "" {
287+ appriseSummary = "Wigo notification"
288+ }
289+ }
290+
291+ // Send to each URL in a separate goroutine
292+ for _ , url := range config .AppriseUrls {
293+ go func (appriseUrl string ) {
294+ // Create context with timeout (10 seconds)
295+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
296+ defer cancel ()
297+
298+ // Create command: apprise -v -t "title" -b "body" url
299+ cmd := exec .CommandContext (ctx , apprisePath , "-v" , "-t" , message , "-b" , appriseSummary , appriseUrl )
300+
301+ // Execute command
302+ output , err := cmd .CombinedOutput ()
303+ if err != nil {
304+ log .Printf ("Error sending apprise notification to %s : %s" , appriseUrl , err )
305+ if len (output ) > 0 {
306+ log .Printf ("Apprise verbose output for %s : %s" , appriseUrl , string (output ))
307+ }
308+ return
309+ }
310+
311+ // Log verbose output even on success for debugging
312+ if len (output ) > 0 {
313+ log .Printf ("Apprise verbose output for %s : %s" , appriseUrl , string (output ))
314+ }
315+ log .Printf (" - Sent to apprise url : %s" , appriseUrl )
316+ }(url )
317+ }
318+ }
0 commit comments