Add disco query responder

This commit is contained in:
Bohdan Horbeshko 2022-02-08 12:09:14 -05:00
parent 32036e3f90
commit 76364388ad

View file

@ -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 {