0

誰かが私がこのコードを修正するのを手伝ってくれますか、私は本当にそれが必要ですが、次に何をすべきかわかりません。グループチャットを作成して、招待された人にメッセガを送信する必要があります。現在は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

仕様( 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 に答える
0

間違いを見つけました。問題は、サーバーからの回答を得るのに十分な待ち時間がなく、サーバーがチャットルームを作成できるようになる前に人々を招待したことです。サーバーから回答が得られるまで待ってから、招待メッセージを送信します。

于 2012-07-10T10:08:43.983 に答える