def build_message(self, text): """Builds an xhtml message without attributes. If input is not valid xhtml-im fallback to normal.""" try: node = XML2Node(text) # logging.debug('This message is XML : %s' % text) text_plain = xhtml2txt(text) logging.debug('Plain Text translation from XHTML-IM:\n%s' % text_plain) message = Message(body=text_plain) message.addChild(node=node) except ExpatError as ee: if text.strip(): # avoids keep alive pollution logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee)) message = Message(body=text) return message
def build_message(self, text): """Builds an xhtml message without attributes. If input is not valid xhtml-im fallback to normal.""" message = None # keeps the compiler happy try: text = utf8(text) XML2Node(text) # test if is it xml # yes, ok epurate it for hipchat hipchat_html = xhtml2hipchat(text) try: node = XML2Node(hipchat_html) message = Message(body=xhtml2txt(text)) message.addChild(node = node) except ExpatError as ee: logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (hipchat_html, ee)) except ExpatError as ee: if text.strip(): # avoids keep alive pollution logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee)) message = Message(body=text) return message
def invite(self, room, jids, reason=None): """Invites user to muc. Works only if user has permission to invite to muc""" NS_MUCUSER = '******' mess = Message(to=room) for jid in jids: invite = simplexml.Node('invite') invite.setAttr('to', jid) if reason is not None: invite.setTagData('reason', reason) mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite) self.log.info(mess) self.connect().send(mess)
def send(self, recipients, message): """Send message to recipients via xmpp.""" jid = JID(self.user) if self.server: server = self.server else: server = jid.getDomain() cl = Client(server, port=self.port, debug=[]) if not cl.connect(): raise IOError("Couldn't connect to xmpp server %s" % server) if not cl.auth(jid.getNode(), self.password, resource=self.resource): cl.Connection.disconnect() raise IOError("Xmpp auth erro using %s to %s", jid, server) for recip in recipients: cl.send(Message(recip[2], message))
port = conf.get('xmpp_nagios', 'port') if len(args) < 1: print "xmppsend message [to whom, multiple args]" sys.exit(1) msg = args[0] msg = msg.replace('\\n', '\n') c = xmpp.Client(server=server, port=port, debug=[]) con = c.connect() if not con: print "Error: could not connect to server: %s:%s" % (c.Server, c.Port) sys.exit(1) auth = c.auth(user=username, password=password, resource=resource) if not auth: print "Error: Could not authenticate to server: %s:%s" % (c.Server, c.Port) sys.exit(1) if len(args) < 2: r = c.getRoster() for user in r.keys(): if user == username: continue c.send(Message(user, '%s' % msg)) else: for user in args[1:]: c.send(Message(user, '%s' % msg))
def send_frame(self, jid, frame): message = base64.b64encode(repr(frame)) try: self.client.send(Message(to=jid, typ='normal', body=message)) except: self.reconnect()