Easy way to send a message to an XMPP/Jabber conference room? (Shell or Python, Debian wheezy)
Question: What is an easy way to send a message to a XMPP/Jabber conference room? Either
at the command line (Shell), or by using Python? Ideally, all commands and/or
libraries should be available in Debian wheezy (or jessie), without using pip.


Answer: I had some problems in getting python-pyxmpp to work, maybe I was just to
impatient. Anyway I found another solution, that worked for me, but using
sleekxmpp for their website. The solution is not better (nor worse, I hope)
than goncalopps, only I got it faster to work on Debian wheezy.

    
    
    $ sudo apt-get install python-sleekxmpp
    

and here's the code:

    
    
    import optparse
    import sys
    import time
    
    import sleekxmpp
    
    
    class MUCBot(sleekxmpp.ClientXMPP):
        def __init__(self, jid, password, room, nick, message):
            sleekxmpp.ClientXMPP.__init__(self, jid, password)
            self.room = room
            self.nick = nick
            self.add_event_handler("session_start", self.start)
            self.message = message
    
        def start(self, event):
            self.getRoster()
            self.sendPresence()
            self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True)
            self.send_message(mto=self.room, mbody=self.message, mtype='groupchat')
            time.sleep(10)
            self.disconnect()
    
    
    if __name__ == '__main__':
        op = optparse.OptionParser(usage='%prog [options] your message text')
        op.add_option("-j", "--jid", help="JID to use")
        op.add_option("-n", "--nick", help="MUC nickname")
        op.add_option("-p", "--password", help="password to use")
        op.add_option("-r", "--room", help="MUC room to join")
        opts, args = op.parse_args()
    
        if None in [opts.jid, opts.nick, opts.password, opts.room] \
           or len(args) < 1:
            op.print_help()
            sys.exit(1)
    
        xmpp = MUCBot(opts.jid, opts.password, opts.room, opts.nick,
                      " ".join(args))
        xmpp.register_plugin('xep_0030')  # Service Discovery
        xmpp.register_plugin('xep_0045')  # Multi-User Chat
        xmpp.register_plugin('xep_0199')  # XMPP Ping
    
        if xmpp.connect():
            xmpp.process(threaded=False)
        else:
            print "connect() failed"
    

Not sure, whether the plugin for `xep_0199` is really needed.

