0

任何人都可以帮助我修复此代码,我真的需要它,但不知道下一步该做什么。我需要创建一个群聊并将messega发送给被邀请的人,现在是example2@gmail.com,但它没有......
有错误吗?

#!/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"
4

2 回答 2

0

我发现我的错误。问题是我没有等待足够长的时间从服务器获得答案,我在服务器能够创建聊天室之前邀请了人们。现在我等到我从服务器得到答案,然后发送邀请消息。

于 2012-07-10T10:08:43.983 回答
0

根据规范 - http://xmpp.org/extensions/xep-0045.html#createroom - 发送加入一个不存在的房间的请求应该创建那个房间(或MUC)

创建和配置此类房间的工作流程如下:

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.

所以这样的事情应该根据文档工作。

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')
于 2012-07-05T07:26:31.267 回答