#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from gi.repository import TelepathyGLib as Tp from test import main, TestConnection MESSAGE = 'Test from telepathy-phoenix' class TextConnection(TestConnection): def message_sent(self, channel, message, flags, token, data): (message, flags) = message.to_text() self.t.assertEqual(MESSAGE, message) self.channel.close_async(None, None) self.t.done() def create_channel_finished(self, req, r, u): TestConnection.create_channel_finished(self, req, r, u) self.channel.connect('message-sent', self.message_sent, None) m = Tp.ClientMessage.new_text(Tp.ChannelTextMessageType.NORMAL, MESSAGE) self.channel.send_message_async(m, 0, None, None) def handle_capabilities(self): caps = self.contact.get_capabilities() account = self.contact.get_account() if not caps.supports_text_chats(): print 'no caps for text chats' self.t.done(False) return req = Tp.AccountChannelRequest.new_text(account, 0) req.set_target_contact(self.contact) req.create_and_observe_channel_async('', None, self.create_channel_finished, None) if __name__ == '__main__': main(sys.argv, 'Text', TextConnection)