diff --git a/internal/canvaslms/message.go b/internal/canvaslms/message.go index c0cd641..cb9578c 100644 --- a/internal/canvaslms/message.go +++ b/internal/canvaslms/message.go @@ -30,7 +30,7 @@ func (h *Handler) SendGradeMessage(conf config.CanvasLMSMessage) error { Grades: grades, LastRefresh: h.respCache.requestTime.Format(time.RFC3339), }, - }); err != nil { + }, false); err != nil { log.Printf("error sending grade message: %v", err) return err } diff --git a/internal/comm/api.go b/internal/comm/api.go index 73e3630..0219b04 100644 --- a/internal/comm/api.go +++ b/internal/comm/api.go @@ -22,7 +22,7 @@ func (c *Communicator) RegisterAPIRoute(g *echo.Group) { if err := ctx.Bind(&msg); err != nil { return err } - if err := c.SendGenericMessage("", msg); err != nil { + if err := c.SendGenericMessage("", msg, ctx.QueryParam("force") == "1"); err != nil { return err } return nil @@ -32,7 +32,7 @@ func (c *Communicator) RegisterAPIRoute(g *echo.Group) { if err := ctx.Bind(&msg); err != nil { return err } - if err := c.SendGenericMessage(ctx.Param("method"), msg); err != nil { + if err := c.SendGenericMessage(ctx.Param("method"), msg, ctx.QueryParam("force") == "1"); err != nil { return err } return nil diff --git a/internal/comm/communicator.go b/internal/comm/communicator.go index 50df296..a3b632f 100644 --- a/internal/comm/communicator.go +++ b/internal/comm/communicator.go @@ -61,11 +61,15 @@ func (e ErrorSentWithFallback) Error() string { // if the preferred method failed to send the message, fallback methods will be tried, // and an ErrorSentWithFabback will be returned if any fallback method succeeded. // if fallback methods failed as well the original error will be returned. -func (c *Communicator) SendGenericMessage(preferredMethod string, message model.GenericMessage) error { +func (c *Communicator) SendGenericMessage(preferredMethod string, message model.GenericMessage, force bool) error { if preferredMethod == "" { preferredMethod = c.fallbackCommunicators[0] } if origErr := c.actualSendGenericMessage(preferredMethod, message); origErr != nil { + if force { + log.Printf("Failed to send message using preferred method %s: %v", preferredMethod, origErr) + return origErr + } log.Printf("Failed to send message using preferred method %s: %v. trying fallback methods", preferredMethod, origErr) for _, fallback := range c.fallbackCommunicators { if fallback == preferredMethod { diff --git a/internal/comm/convert.go b/internal/comm/convert.go index 3c8450f..b79f966 100644 --- a/internal/comm/convert.go +++ b/internal/comm/convert.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "html/template" - "log" "path" "strings" textTemplate "text/template" @@ -77,7 +76,6 @@ func ConvertGenericMessage(msgOrig *model.GenericMessage, supportedMIMES []strin return nil, err } } - log.Printf("template name is: %s %s", tpl.Name(), tpl.DefinedTemplates()) if err := tpl.ExecuteTemplate(&output, tplName, msgOrig.Context); err != nil { return nil, err } @@ -97,7 +95,6 @@ func ConvertGenericMessage(msgOrig *model.GenericMessage, supportedMIMES []strin return nil, err } } - log.Printf("template name is: %s %s", tpl.Name(), tpl.DefinedTemplates()) if err := tpl.ExecuteTemplate(&output, tplName, msgOrig.Context); err != nil { return nil, err } diff --git a/internal/comm/gotify/send.go b/internal/comm/gotify/send.go index 55e25be..2373466 100644 --- a/internal/comm/gotify/send.go +++ b/internal/comm/gotify/send.go @@ -66,8 +66,9 @@ func NewClient() (*Client, error) { func (c *Client) SendGenericMessage(gmsg model.GenericMessage) error { msg := Message{ - Message: gmsg.Body, - Title: gmsg.Subject, + Message: gmsg.Body, + Title: gmsg.Subject, + Priority: gmsg.Priority + 5, } msg.Extras.ClientDisplay.ContentType = gmsg.MIME return c.SendMessage(msg) diff --git a/internal/comm/model/generic.go b/internal/comm/model/generic.go index 99540bf..ef4c7b0 100644 --- a/internal/comm/model/generic.go +++ b/internal/comm/model/generic.go @@ -4,6 +4,7 @@ type GenericMessage struct { Subject string `json:"subject" form:"subject" query:"subject"` Body string `json:"body" form:"body" query:"body"` MIME string `json:"mime" form:"mime" query:"mime"` + Priority int `json:"priority" form:"priority" query:"priority"` ThreadID uint64 `json:"thread_id" form:"thread_id" query:"thread_id"` Context interface{} diff --git a/internal/comm/model/interface.go b/internal/comm/model/interface.go index 407c2b4..b63713a 100644 --- a/internal/comm/model/interface.go +++ b/internal/comm/model/interface.go @@ -16,5 +16,5 @@ type CommMethodWithRoute interface { type Communicator interface { GetMethod(method string) CommMethod GetMethodsByMIME(mime string) []CommMethod - SendGenericMessage(preferredMethod string, message GenericMessage) error + SendGenericMessage(preferredMethod string, message GenericMessage, force bool) error }