hook2xmpp/runtime/xmpp.go

71 lines
1.5 KiB
Go
Raw Permalink Normal View History

2019-02-13 03:24:38 +01:00
package runtime
2017-06-09 10:55:47 +02:00
import (
2019-02-13 03:55:07 +01:00
"github.com/bdlm/log"
2019-07-15 23:57:26 +02:00
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
2017-06-09 10:55:47 +02:00
)
2019-07-15 23:57:26 +02:00
func NotifyImage(client xmpp.Sender, hook Hook, url string, desc string) {
msg := stanza.Message{
Attrs: stanza.Attrs{Type: stanza.MessageTypeGroupchat},
Body: url,
Extensions: []stanza.MsgExtension{
stanza.OOB{URL: url, Desc: desc},
},
2017-06-09 10:55:47 +02:00
}
2019-02-13 03:24:38 +01:00
for _, muc := range hook.NotifyMuc {
2019-07-15 23:57:26 +02:00
msg.To = muc
if err := client.Send(msg); err != nil {
log.WithFields(map[string]interface{}{
"muc": muc,
"url": url,
}).Errorf("error on image notify: %s", err)
}
2019-02-13 03:24:38 +01:00
}
2019-07-15 23:57:26 +02:00
msg.Type = stanza.MessageTypeChat
2019-02-13 03:24:38 +01:00
for _, user := range hook.NotifyUser {
2019-07-15 23:57:26 +02:00
msg.To = user
if err := client.Send(msg); err != nil {
log.WithFields(map[string]interface{}{
"user": user,
"url": url,
}).Errorf("error on image notify: %s", err)
}
2019-02-13 03:24:38 +01:00
}
}
2019-07-15 23:57:26 +02:00
func Notify(client xmpp.Sender, hook Hook, text, html string) {
msg := stanza.Message{
Attrs: stanza.Attrs{Type: stanza.MessageTypeGroupchat},
Body: text,
Extensions: []stanza.MsgExtension{
stanza.HTML{Body: stanza.HTMLBody{InnerXML: html}},
},
}
2017-06-09 10:55:47 +02:00
for _, muc := range hook.NotifyMuc {
2019-07-15 23:57:26 +02:00
msg.To = muc
if err := client.Send(msg); err != nil {
log.WithFields(map[string]interface{}{
"muc": muc,
"text": text,
}).Errorf("error on notify: %s", err)
}
2017-06-09 10:55:47 +02:00
}
2019-07-15 23:57:26 +02:00
msg.Type = stanza.MessageTypeChat
2017-06-09 10:55:47 +02:00
for _, user := range hook.NotifyUser {
2019-07-15 23:57:26 +02:00
msg.To = user
if err := client.Send(msg); err != nil {
log.WithFields(map[string]interface{}{
"user": user,
"text": text,
}).Errorf("error on notify: %s", err)
}
2017-06-09 10:55:47 +02:00
}
}