From 76364388ad2d7baa0718dff50902eacd4c090edf Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Tue, 8 Feb 2022 12:09:14 -0500 Subject: [PATCH] Add disco query responder --- xmpp/handlers.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 0f4b949..d14fd31 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -35,6 +35,12 @@ func HandleIq(s xmpp.Sender, p stanza.Packet) { _, ok := iq.Payload.(*extensions.IqVcardTemp) if ok { go handleGetVcardTempIq(s, iq) + return + } + _, ok = iq.Payload.(*stanza.DiscoInfo) + if ok { + go handleGetDiscoInfo(s, iq) + return } } } @@ -295,6 +301,33 @@ func handleGetVcardTempIq(s xmpp.Sender, iq *stanza.IQ) { _ = gateway.ResumableSend(component, &answer) } +func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ) { + answer, err := stanza.NewIQ(stanza.Attrs{ + Type: stanza.IQTypeResult, + From: iq.To, + To: iq.From, + Id: iq.Id, + Lang: "en", + }) + if err != nil { + log.Errorf("Failed to create answer IQ: %v", err) + } + + disco := answer.DiscoInfo() + disco.AddIdentity("Telegram Gateway", "gateway", "telegram") + answer.Payload = disco + + log.Debugf("%#v", answer) + + component, ok := s.(*xmpp.Component) + if !ok { + log.Error("Not a component") + return + } + + _ = gateway.ResumableSend(component, answer) +} + func splitFrom(from string) (string, string, bool) { fromJid, err := stanza.NewJid(from) if err != nil {