hook2xmpp/runtime/xmpp.go

48 lines
921 B
Go
Raw Normal View History

2019-02-13 03:24:38 +01:00
package runtime
2017-06-09 10:55:47 +02:00
import (
2019-06-25 03:26:53 +02:00
"gosrc.io/xmpp"
2017-06-09 10:55:47 +02:00
)
2019-02-13 19:51:23 +01:00
func NotifyImage(client *xmpp.Client, hook Hook, url string, desc string) {
2019-06-25 03:26:53 +02:00
msg := xmpp.Message{
Attrs: xmpp.Attrs{Type: xmpp.MessageTypeGroupchat},
Body: url,
Extensions: []xmpp.MsgExtension{
xmpp.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-06-25 03:26:53 +02:00
msg.To = muc
client.Send(msg)
2019-02-13 03:24:38 +01:00
}
2019-06-25 03:26:53 +02:00
msg.Type = xmpp.MessageTypeChat
2019-02-13 03:24:38 +01:00
for _, user := range hook.NotifyUser {
2019-06-25 03:26:53 +02:00
msg.To = user
client.Send(msg)
2019-02-13 03:24:38 +01:00
}
}
2019-06-25 03:26:53 +02:00
func Notify(client *xmpp.Client, hook Hook, text, html string) {
msg := xmpp.Message{
Attrs: xmpp.Attrs{Type: xmpp.MessageTypeGroupchat},
Body: text,
Extensions: []xmpp.MsgExtension{
xmpp.HTML{Body: xmpp.HTMLBody{InnerXML: html}},
},
}
2017-06-09 10:55:47 +02:00
for _, muc := range hook.NotifyMuc {
2019-06-25 03:26:53 +02:00
msg.To = muc
client.Send(msg)
2017-06-09 10:55:47 +02:00
}
2019-06-25 03:26:53 +02:00
msg.Type = xmpp.MessageTypeChat
2017-06-09 10:55:47 +02:00
for _, user := range hook.NotifyUser {
2019-06-25 03:26:53 +02:00
msg.To = user
client.Send(msg)
2017-06-09 10:55:47 +02:00
}
}