async def connect(self, opsdroid): # Create connection object with chat library session = aiohttp.ClientSession() mapi = AsyncHTTPAPI(self.homeserver, session) self.session = session login_response = await mapi.login("m.login.password", user=self.mxid, password=self.password) mapi.token = login_response['access_token'] mapi.sync_token = None for roomname, room in self.rooms.items(): response = await mapi.join_room(room['alias']) self.room_ids[roomname] = response['room_id'] self.connection = mapi # Create a filter now, saves time on each later sync self.filter_id = await self.make_filter(mapi, self.room_ids.values()) # Do initial sync so we don't get old messages later. response = await self.connection.sync( timeout_ms=3000, filter='{ "room": { "timeline" : { "limit" : 1 } } }', set_presence="online") self.connection.sync_token = response["next_batch"] if self.nick and await self.connection.get_display_name(self.mxid ) != self.nick: await self.connection.set_display_name(self.mxid, self.nick)
def opsdroid_matrix(): connector = ConnectorMatrix( { "rooms": {"main": "#test:localhost"}, "mxid": "@opsdroid:localhost", "password": "******", "homeserver": "http://localhost:8008", } ) connector.room_ids = {"main": "!notaroomid"} api = AsyncHTTPAPI("https://notaurl.com", None) connector.connection = api with OpsDroid() as opsdroid: opsdroid.connectors.append(connector) yield opsdroid
def setUp(self): """Basic setting up for tests""" self.connector = setup_connector() self.api = AsyncHTTPAPI("https://notaurl.com", None) self.connector.connection = self.api