package xmpp import ( "encoding/xml" "fmt" "log" "math/rand" ) type message struct { XMLName xml.Name `xml:"jabber:client message"` Type string `xml:"type,attr,omitempty"` Id string `xml:"id,attr,omitempty"` From string `xml:"from,attr,omitempty"` To string `xml:"to,attr,omitempty"` // FIXME The lang attribute should have the `xml` prefix for the standard // XML namespace. There was no option found so far which allows this with // the standard library XML implementation and the xml.Encoder.Encode(v // any) function. Lang string `xml:"lang,attr,omitempty"` Body string `xml:"body,omitempty"` } func handleMessage(s *session, m message) { if m.Type == "chat" && m.Body != "" { reply := fmt.Sprintf("Got %s", m.Body) err := s.sendMessage(reply, m.From) if err != nil { log.Printf("Could not send message: %v\n", err) } } } func (s *session) sendMessage(m, j string) error { msg := message{ From: s.jid, Id: fmt.Sprintf("%016x", rand.Uint64()), To: j, Type: "chat", Lang: "en", Body: m, } return s.tx.Encode(msg) }