mirror of
https://github.com/knadh/listmonk.git
synced 2024-11-10 17:13:04 +08:00
6cf43ea674
This is a major feature that builds upon the `Messenger` interface that has been in listmonk since its inception (with SMTP as the only messenger). This commit introduces a new Messenger implementation, an HTTP "postback", that can post campaign messages as a standard JSON payload to arbitrary HTTP servers. These servers can in turn push them to FCM, SMS, or any or any such upstream, enabling listmonk to be a generic campaign messenger for any type of communication, not just e-mails. Postback HTTP endpoints can be defined in settings and they can be selected on campaigns.
42 lines
1 KiB
Go
42 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/knadh/listmonk/internal/manager"
|
|
)
|
|
|
|
const (
|
|
notifTplImport = "import-status"
|
|
notifTplCampaign = "campaign-status"
|
|
notifSubscriberOptin = "subscriber-optin"
|
|
notifSubscriberData = "subscriber-data"
|
|
)
|
|
|
|
// notifData represents params commonly used across different notification
|
|
// templates.
|
|
type notifData struct {
|
|
RootURL string
|
|
LogoURL string
|
|
}
|
|
|
|
// sendNotification sends out an e-mail notification to admins.
|
|
func (app *App) sendNotification(toEmails []string, subject, tplName string, data interface{}) error {
|
|
var b bytes.Buffer
|
|
if err := app.notifTpls.ExecuteTemplate(&b, tplName, data); err != nil {
|
|
app.log.Printf("error compiling notification template '%s': %v", tplName, err)
|
|
return err
|
|
}
|
|
|
|
m := manager.Message{}
|
|
m.From = app.constants.FromEmail
|
|
m.To = toEmails
|
|
m.Subject = subject
|
|
m.Body = b.Bytes()
|
|
m.Messenger = emailMsgr
|
|
if err := app.manager.PushMessage(m); err != nil {
|
|
app.log.Printf("error sending admin notification (%s): %v", subject, err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|