2019-07-16 22:31:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bdlm/log"
|
|
|
|
|
|
|
|
"gosrc.io/xmpp"
|
|
|
|
"gosrc.io/xmpp/stanza"
|
|
|
|
)
|
|
|
|
|
2019-07-27 23:50:10 +00:00
|
|
|
func send(c xmpp.Sender, recipient []string, msgText string) {
|
2019-07-16 22:31:33 +00:00
|
|
|
msg := stanza.Message{
|
|
|
|
Attrs: stanza.Attrs{Type: stanza.MessageTypeChat},
|
|
|
|
Body: msgText,
|
|
|
|
}
|
2019-07-27 23:50:10 +00:00
|
|
|
|
|
|
|
if isMUCRecipient {
|
2019-07-16 22:31:33 +00:00
|
|
|
msg.Type = stanza.MessageTypeGroupchat
|
|
|
|
}
|
2019-07-27 23:50:10 +00:00
|
|
|
|
|
|
|
for _, to := range recipient {
|
2019-07-16 22:31:33 +00:00
|
|
|
msg.To = to
|
|
|
|
if err := c.Send(msg); err != nil {
|
|
|
|
log.WithFields(map[string]interface{}{
|
2019-07-27 23:50:10 +00:00
|
|
|
"muc": isMUCRecipient,
|
2019-07-16 22:31:33 +00:00
|
|
|
"to": to,
|
|
|
|
"text": msgText,
|
|
|
|
}).Errorf("error on send message: %s", err)
|
|
|
|
} else {
|
|
|
|
log.WithFields(map[string]interface{}{
|
2019-07-27 23:50:10 +00:00
|
|
|
"muc": isMUCRecipient,
|
2019-07-16 22:31:33 +00:00
|
|
|
"to": to,
|
|
|
|
"text": msgText,
|
|
|
|
}).Info("send message")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|