mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-24 11:32:00 -08:00
35 lines
698 B
Go
35 lines
698 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/bdlm/log"
|
||
|
|
||
|
"gosrc.io/xmpp"
|
||
|
"gosrc.io/xmpp/stanza"
|
||
|
)
|
||
|
|
||
|
func send(c xmpp.Sender, receiver []string, msgText string) {
|
||
|
msg := stanza.Message{
|
||
|
Attrs: stanza.Attrs{Type: stanza.MessageTypeChat},
|
||
|
Body: msgText,
|
||
|
}
|
||
|
if receiverMUC {
|
||
|
msg.Type = stanza.MessageTypeGroupchat
|
||
|
}
|
||
|
for _, to := range receiver {
|
||
|
msg.To = to
|
||
|
if err := c.Send(msg); err != nil {
|
||
|
log.WithFields(map[string]interface{}{
|
||
|
"muc": receiverMUC,
|
||
|
"to": to,
|
||
|
"text": msgText,
|
||
|
}).Errorf("error on send message: %s", err)
|
||
|
} else {
|
||
|
log.WithFields(map[string]interface{}{
|
||
|
"muc": receiverMUC,
|
||
|
"to": to,
|
||
|
"text": msgText,
|
||
|
}).Info("send message")
|
||
|
}
|
||
|
}
|
||
|
}
|