Here is the basic implementation for sending a message to a room chat. You need to send your presence to the group, and also set the message type to 'groupchat'.
Tested with Openfire server
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,time,xmpp
def sendMessageToGroup(server, user, password, room, message):
jid = xmpp.protocol.JID(user)
user = jid.getNode()
client = xmpp.Client(server)
connection = client.connect(secure=False)
if not connection:
print 'connection failed'
sys.exit(1)
auth = client.auth(user, password)
if not auth:
print 'authentication failed'
sys.exit(1)
# Join a room by sending your presence to the room
client.send(xmpp.Presence(to="%s/%s" % (room, user)))
msgObj = xmpp.protocol.Message(room, message)
#Set message type to 'groupchat' for conference messages
msgObj.setType('groupchat')
client.send(msgObj)
# some older servers will not send the message if you disconnect immediately after sending
time.sleep(1)
client.disconnect()