diff --git a/main.go b/main.go index b280e5e..3858989 100644 --- a/main.go +++ b/main.go @@ -200,8 +200,15 @@ func main() { return } + msg = strings.TrimSuffix(msg, "\n") + + if msg == "" { + fmt.Fprintf(w, "empty message") + return + } + log.Printf("GOT: sending '%s'\n", msg) - err = plugins.SendMDNotice(cli, got_room, msg) + err = plugins.SendNotice(cli, got_room, msg) if err != nil { http.Error(w, fmt.Sprintf("can not send commit info: %s", err), http.StatusInternalServerError) return diff --git a/plugins/plugins.go b/plugins/plugins.go index df2510f..c6d1515 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -177,6 +177,26 @@ func SendMDNotice(c *gomatrix.Client, roomID, message string) error { return nil } +// SendNotice sends an text notice to a given room. It pretends to be +// "typing" by calling UserTyping for the caller. +func SendNotice(c *gomatrix.Client, roomID, message string) error { + _, err := c.UserTyping(roomID, true, 3) + if err != nil { + return err + } + + _, err = c.SendMessageEvent(roomID, "m.room.message", gomatrix.GetHTMLMessage("m.notice", message)) + if err != nil { + return err + } + + _, err = c.UserTyping(roomID, false, 0) + if err != nil { + return err + } + return nil +} + // SendMD takes markdown and converts it to an html message. func SendMD(c *gomatrix.Client, roomID, message string) error { md := []byte(message)