mirror of
https://github.com/pushbits/server.git
synced 2025-04-29 18:26:49 +02:00
Send formatted messages
This commit is contained in:
parent
0884d5703b
commit
f5560b0c46
1 changed files with 10 additions and 2 deletions
|
@ -2,7 +2,9 @@ package dispatcher
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"html"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/pushbits/server/internal/model"
|
||||
)
|
||||
|
@ -11,9 +13,15 @@ import (
|
|||
func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notification) error {
|
||||
log.Printf("Sending notification to room %s.\n", a.MatrixID)
|
||||
|
||||
text := fmt.Sprintf("%s\n\n%s", n.Title, n.Message)
|
||||
plainTitle := strings.TrimSpace(n.Title)
|
||||
plainMessage := strings.TrimSpace(n.Message)
|
||||
escapedTitle := html.EscapeString(plainTitle)
|
||||
escapedMessage := html.EscapeString(plainMessage)
|
||||
|
||||
_, err := d.client.SendText(a.MatrixID, text)
|
||||
text := fmt.Sprintf("%s\n\n%s", plainTitle, plainMessage)
|
||||
formattedText := fmt.Sprintf("<b>%s</b><br /><br />%s", escapedTitle, escapedMessage)
|
||||
|
||||
_, err := d.client.SendFormattedText(a.MatrixID, text, formattedText)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue