Пример #1
0
func NewClient() (*JabberClient, error) {
	tlsConfig := tls.Config{}
	tlsConfig.ServerName = "talk.google.com"
	options := xmpp.Options{
		Host:      "talk.google.com:443",
		User:      services.Config.Jabber.Jid,
		Password:  services.Config.Jabber.Pass,
		Debug:     false,
		Session:   false,
		TLSConfig: &tlsConfig,
	}
	talk, err := options.NewClient()
	if err != nil {
		return nil, err
	}
	ret := JabberClient{
		talk,
		make(chan interface{}, 1),
		make(chan xmpp.Chat, 1),
	}

	go recvChannel(talk, ret.recv)

	// keepalive interval to reconnect, otherwise the connection dies
	interval := time.Minute * 15
	keepalive := time.NewTicker(interval)
	go func() {
		for {
			select {
			case <-keepalive.C:
				talk.Close()
				talk, err = options.NewClient()
				if err != nil {
					log.Fatal(err)
				}
				go recvChannel(talk, ret.recv)
			case chat := <-ret.send:
				talk.Send(chat)
			}

		}
	}()

	return &ret, nil
}
Пример #2
0
// NewBot creates a new Bot instance. Please note that Jabber ID and
// nickname must match the ones in the Hipchat acoount settings
func NewBot(userJabberID, nickname, password string) (*Bot, error) {
	b := &Bot{}
	b.fullName = nickname

	options := xmpp.Options{
		Host:          "hipchat.wnb:5222",
		User:          userJabberID,
		Password:      password,
		NoTLS:         true,
		StartTLS:      true,
		Debug:         false,
		Session:       false,
		Status:        "",
		StatusMessage: "",
		Resource:      "bot",
	}
	var err error
	b.c, err = options.NewClient()
	return b, err
}