diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-04 01:15:43 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-04 01:15:43 +0300 |
commit | aaf7233c89af4dfbc2a8b9f5e11b4ff5e9713567 (patch) | |
tree | d449c7a41d1945e249cd066921c7a436f7614f84 /xmpp/component.go | |
parent | 7e036fd795cc0b5710d3b049dc98f4538c32da6a (diff) |
Presence/iq handling and rudimental telegram client
Diffstat (limited to 'xmpp/component.go')
-rw-r--r-- | xmpp/component.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/xmpp/component.go b/xmpp/component.go index d55ed6b..1562224 100644 --- a/xmpp/component.go +++ b/xmpp/component.go @@ -1,16 +1,25 @@ package xmpp import ( - "log" - "dev.narayana.im/narayana/telegabber/config" "gosrc.io/xmpp" ) +var jid *xmpp.Jid +var tgConf config.TelegramConfig + // NewComponent starts a new component and wraps it in // a stream manager that you should start yourself -func NewComponent(conf config.XMPPConfig) *xmpp.StreamManager { +func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.StreamManager, error) { + var err error + jid, err = xmpp.NewJid(conf.Jid) + if err != nil { + return nil, err + } + + tgConf = tc + options := xmpp.ComponentOptions{ Address: conf.Host + ":" + conf.Port, Domain: conf.Jid, @@ -19,14 +28,16 @@ func NewComponent(conf config.XMPPConfig) *xmpp.StreamManager { } router := xmpp.NewRouter() + router.HandleFunc("iq", HandleIq) + router.HandleFunc("presence", HandlePresence) router.HandleFunc("message", HandleMessage) component, err := xmpp.NewComponent(options, router) if err != nil { - log.Fatalf("%+v", err) + return nil, err } cm := xmpp.NewStreamManager(component, nil) - return cm + return cm, nil } |