add priorty on gotify cmm
This commit is contained in:
parent
8794444e0f
commit
3284792aa7
7 changed files with 13 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue