diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-04-18 14:20:57 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-04-18 14:46:03 +0300 |
commit | bb36996194492db6cc17f9cfd91769f31df7003b (patch) | |
tree | a10b83a338615e5386a05d38913b3f97165b1792 /matrix | |
parent | 3750d5007fe31b1a4d706357f43774d08944213e (diff) |
Add support for sending Markdown messages
Diffstat (limited to 'matrix')
-rw-r--r-- | matrix/matrix.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go index 3a37e64..3c97dbb 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -31,6 +31,7 @@ import ( "strings" "time" + "gopkg.in/russross/blackfriday.v2" "maunium.net/go/gomatrix" "maunium.net/go/gomuks/config" "maunium.net/go/gomuks/debug" @@ -326,6 +327,30 @@ func (c *Container) SendMessage(roomID, msgtype, text string) (string, error) { return resp.EventID, nil } +func (c *Container) SendMarkdownMessage(roomID, msgtype, text string) (string, error) { + defer c.gmx.Recover() + + html := string(blackfriday.Run([]byte(text))) + if html == text { + return c.SendMessage(roomID, msgtype, text) + } + debug.Print(html) + debug.Print(text) + + c.SendTyping(roomID, false) + resp, err := c.client.SendMessageEvent(roomID, "m.room.message", + map[string]interface{}{ + "msgtype": msgtype, + "body": text, + "format": "org.matrix.custom.html", + "formatted_body": html, + }) + if err != nil { + return "", err + } + return resp.EventID, nil +} + // SendTyping sets whether or not the user is typing in the given room. func (c *Container) SendTyping(roomID string, typing bool) { defer c.gmx.Recover() |