Question

I'm writing a XMPP bot in Python (using xmpppy). I want (after user's request) check his PubSub status (mood, tune) and do something with it. How do I do that?

I know how to parse a stanza send by user when he changes status but I don't know how to force him to send me such stanza.

Was it helpful?

Solution

Read XEP-163. Essentially, you need to implement the send-side of entity caps (XEP-115), so that you send your presence like this:

<presence from='romeo@example.net/home'>
  <c xmlns='http://jabber.org/protocol/caps' 
     hash='sha-1'
     node='http://example.com/MYBOT'
     ver='/FpawanrJ31ymsv4ApCMGcyJmUk='/>
</presence>

When you get get a disco#info request like this:

<iq to='romeo@example.net/home'
    id='disco1'
    from='example.net' 
    type='get'>
  <query xmlns='http://jabber.org/protocol/disco#info'
         node='http://example.com/MYBOT#/FpawanrJ31ymsv4ApCMGcyJmUk='/>
</iq>

You respond with the list of features you implement:

<iq from='romeo@example.net/home'
    id='disco1'
    to='example.net' 
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'
         node='http://example.com/MYBOT#/FpawanrJ31ymsv4ApCMGcyJmUk='>
    <identity category='client' type='bot' name='MYBOT'/>
    <feature var='http://jabber.org/protocol/mood+notify'/>
    <feature var='http://jabber.org/protocol/tune+notify'/>
  </query>
</iq>

Add a +notify to each node name that you want to implicitly subscribe to, and add the resulting string as a feature, as above. Ensuring that the SHA-1 hash in your outbound presence is correct is the only hard part.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top