diff options
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 } |