Xmpp chat invisible presence

2020-08-01 06:08发布

问题:

I'm building a bot that monitor friends presences but doesn't need to be visible. I have tried to set presence using priority, show, type with all knowns values but without success. Is possibile to be invisibile and just receive presence notifications?

Thanks!

回答1:

See XEP-0126: Invisibility, section 3.1:

<iq from='bilbo@tolkien.lit/shire' type='set' id='inv1'>
  <query xmlns='jabber:iq:privacy'>
    <list name='invisible'>
      <item action='deny' order='1'>
        <presence-out/>
      </item>
    </list>
  </query>
</iq>


回答2:

Have a look at the rfc. Presence has a subscription status. If your bot is subscribed to receive presence from your users but your users are not, they are not going to be notified of the bot's presence.

In other words, your bot should send:

<presence to="user@example.com" type="subscribe" />

followed by the user's authorization,

<presence to="bot@example.com" type="subscribed" />

Now the bot will receive presence from the user, but not the opposite.



回答3:

To set status for become invisible, you must send a presence with type "invisible".

<presence type="invisible"/>

And here is the code (in ios):

XMPPPresence *presence = [XMPPPresence presenceWithType:@"invisible"];
[[self xmppStream] sendElement:presence];

I use this code to set my status as "invisible". For more details, please read the documentation on http://xmpp.org/extensions/xep-0018.html#sect-id86210



回答4:

Last I knew from Facebook, it's not possible to implement invisibility via XMPP commands: https://developers.facebook.com/bugs/315067461919373. See also https://developers.facebook.com/docs/chat/ under Limitations.