Question

Can anybody help me to fix this code, I really need it, but have no idea what to do next. I need to create a groupchat and send messega to invited persons, now it is example2@gmail.com, but it does not...
Is there mistake?

#!/usr/bin/python
import sys,os,xmpp,time                                          
jid = 'example1@gmail.com'
psw = 'psw'
jid=xmpp.protocol.JID(jid)
cl=xmpp.Client(jid.getDomain(),debug=[])
cl.connect()
cl.auth(jid.getNode(),psw)
node = jid.getNode()
domain = 'talk.google.com'
room = node + '@' + domain
nroom = room + '/' + 'Maria'
mes = xmpp.Presence(to=nroom) 
cl.sendInitPresence()
cl.send(mes)


NS_MUCUSER = 'http://jabber.org/protocol/muc#user'
invite = xmpp.simplexml.Node('invite')
invite.setAttr('to', 'example2@gmail.com')
invite.setTagData('reason', 'I really need it!') 
mess = xmpp.Message(to=room)
mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite)
cl.send(mess)


msg = xmpp.protocol.Message(body="Hello there!")
msg.setTo(room)
msg.setType('groupchat')
cl.send(msg)
time.sleep(1)   # some older servers will not send the message if you disconnect immediately after sending
cl.disconnect()
print "Done"
Was it helpful?

Solution 2

I find my mistake. Problem is that I didn't wait enough to get answer from the server and I invited people before server was able to create a chat room. Now I wait until I get answer from server and then send invite message.

OTHER TIPS

According to the specs - http://xmpp.org/extensions/xep-0045.html#createroom - sending a request to join a room that doesn't exist should create that room (or MUC)

The workflow for creating and configuring such rooms is as follows:

The user sends presence to <room@service/nick> and signal his or her support
for the Multi-User Chat protocol by including extended presence information 
in an empty <x/> child element qualified by the 'http://jabber.org/protocol/muc' 
namespace (note the lack of an '#owner' or '#user' fragment).

If this user is allowed to create a room and the room does not yet exist, the
service MUST create the room according to some default configuration, assign the
requesting user as the initial room owner, and add the owner to the room but not 
allow anyone else to enter the room (effectively "locking" the room). The initial
presence stanza received by the owner from the room MUST include extended 
presence information indicating the user's status as an owner and acknowledging
that the room has been created (via status code 201) and is awaiting 
configuration.

So something like this is supposed to work according to the documentation.

jid=xmpp.protocol.JID('example@gmail.com')
cl=xmpp.Client(jid.getDomain(),debug=[])

jid = xmpp.protocol.JID('example@gmail.com')
client = xmpp.Client(jid.getDomain(), debug=[])
client.connect()
client.auth(jid.getNode(), 'my secret password')
client.send(xmpp.Presence(to='room@talk.google.com/ANick')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top