def on_feed_output(self, feed):
        from xmpp import Client, Message, JID, Presence

        config = self.get_config(feed)
        if config['enabled'] is None or feed.manager.options.learn:
            log.debug('XMPP plugin disabled or in learning mode, skipping.')
            return

        for entry in feed.accepted:
            body = entry.render(config.get('message_format'))
            if feed.manager.options.test:
                log.info("XMPP message: %s", body)
                continue
            msg = Message(body=body)
            for dest in [x.strip() for x in config['to'].split(',')]:
                if dest[0] == '@':
                    dest = dest[1:]
                    if not dest in self.rooms:
                        self.client.send(Presence("%s/%s" % (dest, config['nickname'])))                   
                    msg.setAttr('to', dest)
                    msg.setType('groupchat')
                else:
                    msg.setAttr('to', dest)
                    msg.setType(config['message_type'])
                self.client.send(msg)
Exemple #2
0
 def send(self, envelope, content):
     message = Message(to=JID('%s@%s' % (envelope.room, self.configuration.conference_server)),
                       typ='groupchat', body=content.raw)
     html = simplexml.Node('html', {'xmlns': 'http://jabber.org/protocol/xhtml-im'})
     html.addChild(node=simplexml.XML2Node((
         "<body xmlns='http://www.w3.org/1999/xhtml'>" +
         content.html +
         "</body>"
     ).encode('utf-8')))
     message.addChild(node=html)
     self.connection.send(message)
Exemple #3
0
    def test_XMPP_participant_jid_from_MUC_message_normal(self):
        # Real message from Hipchat MUC
        msg_txt = """
                <message xmlns="jabber:client" to="[email protected]/HipchatBot" type="groupchat" from="[email protected]/Guillaume BINET">
                   <body>test</body>
                </message>"""

        message = XMPPMessage(node=msg_txt)

        self.assertEqual(str(message.getFrom()), "[email protected]/Guillaume BINET")
        self.assertEqual(str(get_jid_from_message(message)), "[email protected]/Guillaume BINET")
Exemple #4
0
    def test_XMPP_participant_jid_from_MUC_message_normal(self):
        # Real message from Hipchat MUC
        msg_txt = """
                <message xmlns="jabber:client" to="[email protected]/HipchatBot" type="groupchat" from="[email protected]/Guillaume BINET">
                   <body>test</body>
                </message>"""

        message = Message(node=msg_txt)

        self.assertEqual(str(message.getFrom()),
                         "[email protected]/Guillaume BINET")
        self.assertEqual(str(get_jid_from_message(message)),
                         "[email protected]/Guillaume BINET")
Exemple #5
0
def test():

	client = Client('localhost')

	def message_handler(conn, mess_node):
		client.send(Message('tim@localhost', 'reponse!'))

	if not client.connect(server=('127.0.0.1', 5222)):
		raise IOError('Can not connect to server.')

	if not client.auth('abitbol', 'abitbol', 'abitbol'):
		raise IOError('Can not auth with server.')

	client.RegisterHandler('message', message_handler)

	client.sendInitPresence()

	client.send(Message('tim@localhost', 'Test message'))

	while 1:
		client.Process(1)
Exemple #6
0
	def message_handler(conn, mess_node):
		client.send(Message('tim@localhost', 'reponse!'))
Exemple #7
0
 def send(self, destination, action):
     self.client.send(Message('tim@localhost', str(action)))