go-xmpp/cmd/fluxxmpp/xmppsend.go

37 lines
711 B
Go
Raw Normal View History

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