How to use the matrix-appservice-bridge.RemoteRoom function in matrix-appservice-bridge

To help you get started, we’ve selected a few matrix-appservice-bridge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matrix-org / matrix-bifrost / src / Store.ts View on Github external
public async storeRoom(matrixId: string, type: MROOM_TYPES, remoteId: string, remoteData: IRemoteRoomData)
    : Promise<{remote: RemoteRoom, matrix: MatrixRoom}> {
        // XXX: If a room with all these identifiers already exists, replace it.
        log.info(`Storing remote room (${type}) ${matrixId}`);
        log.debug("with data ", remoteData);
        const mxRoom = new MatrixRoom(matrixId);
        mxRoom.set("type", type);
        const remote = new RemoteRoom(
            remoteId,
        remoteData);
        try {
            await this.roomStore.linkRooms(mxRoom, remote);
        } catch (ex) {
            log.error("Failed to store room:", ex);
            throw ex;
        }
        return {matrix: mxRoom, remote};
    }
github turt2live / matrix-appservice-instagram-media / src / InstagramBridge.js View on Github external
_onAliasQuery(alias, aliasLocalpart) {
        log.info("InstagramBridge", "Got request for alias #" + aliasLocalpart);

        if (aliasLocalpart.indexOf("_instagram_") !== 0) throw new Error("Invalid alias (" + aliasLocalpart + "): Missing prefix");

        // The server name could contain underscores, but the port won't. We'll try to create a room based on
        // the last argument being a port, or a string if not a number.

        var handle = aliasLocalpart.substring("_instagram_".length);

        var remoteRoom = new RemoteRoom(aliasLocalpart);
        remoteRoom.set("instagram_username", handle);

        var realProfile = null;

        return InstagramStore.hasAuthTokens(handle).then(isAuthed => {
            if (!isAuthed) return Promise.reject(handle + " has not authorized us to use their account");
            return ProfileService.getProfile(handle);
        }).then(profile => {
            realProfile = profile;
            return util.uploadContentFromUrl(this._bridge, profile.avatarUrl, this.getBotIntent(), 'icon.png');
        }).then(avatarMxc => {
            var virtualUserId = "@_instagram_" + handle + ":" + this._bridge.opts.domain;

            var userMap = {};
            userMap[this._bridge.getBot().getUserId()] = 100;
            userMap[virtualUserId] = 50;
github matrix-org / matrix-bifrost / src / store / postgres / PgDatastore.ts View on Github external
return res.rows.map((row) => ({
            matrix: new MatrixRoom(row.room_id, { extras: { type } }),
            // Id is not used.
            remote: new RemoteRoom("", {
                gateway: row.gateway,
                properties: row.properties,
                room_name: row.room_name,
                protocol_id: row.protocol_id,
            } as IRemoteGroupData),
        }));
    }
github Half-Shot / matrix-appservice-twitter / src / HashtagHandler.js View on Github external
HashtagHandler.prototype.processAliasQuery = function (name) {
  log.info("Handler.Hashtag", "Got alias request ''%s'", name);

  if(/^[a-z0-9]+$/i.test(name) == false) {
    return null; //Not alphanumeric
  }

  var remote = new RemoteRoom("hashtag_" + name);
  remote.set("twitter_type", "hashtag");

  return {
    creationOpts: {
      visibility: "public",
      room_alias_name: "twitter_#"+name,
      name: "[Twitter] #"+name,
      topic: "Twitter feed for #"+name,
      initial_state: [
        {
          "type": "m.room.join_rules",
          "content": {
            "join_rule": "public"
          },
          "state_key": ""
        }
github matrix-hacks / matrix-puppet-facebook / src / base.js View on Github external
}).then(matrixRoomId => {
          debug("now's the time to update our local cache for this linked room");
          return roomStore.upsertEntry({
            id: roomAlias,
            remote: new RemoteRoom(thirdPartyRoomId),
            matrix: new MatrixRoom(matrixRoomId)
          }).then(()=> {
            debug("finally return the entry we were looking for in the first place");
            return roomStore.getEntryById(roomAlias);
          });
        });
      }
github matrix-org / matrix-bifrost / src / store / postgres / PgDatastore.ts View on Github external
public async getIMRoom(matrixUserId: string, protocolId: string, remoteUserId: string): Promise {
        const res = await this.pgPool.query(
            "SELECT room_id FROM im_rooms WHERE user_id = $1 AND remote_id = $2 AND protocol_id = $3",
            [ matrixUserId, remoteUserId, protocolId ],
        );
        if (res.rowCount === 0) {
            return null;
        }
        const row = res.rows[0];
        return {
            matrix: new MatrixRoom(row.room_id, { extras: { type: MROOM_TYPE_IM } }),
            remote: new RemoteRoom("", {
                matrixUser: matrixUserId,
                protocol_id: protocolId,
                recipient: remoteUserId,
            }),
        };
    }
github matrix-org / matrix-bifrost / src / store / postgres / PgDatastore.ts View on Github external
} else if (type === "im") {
            remoteData = {
                matrixUser: new MatrixUser(row.user_id),
                recipient: row.remote_id,
                protocol_id: row.protocol_id,
            } as IRemoteImData;
        } else if (type === "user-admin") {
            remoteData = {
                matrixUser: new MatrixUser(row.user_id),
            } as IRemoteUserAdminData;
        } else {
            throw Error("Room was of unknown type!");
        }
        log.debug("Found room ", JSON.stringify(remoteData));
        return {
            remote: new RemoteRoom("", remoteData),
            matrix: new MatrixRoom(roomId, { extras: { type }}),
        };
    }
github Half-Shot / matrix-appservice-twitter / src / AccountServices.js View on Github external
intent.join(event.room_id).then( () => {
    var rroom = new RemoteRoom("service_"+event.sender);
    rroom.set("twitter_type", "service");
    this._bridge.getRoomStore().linkRooms(context.rooms.matrix, rroom);
    intent.sendMessage(event.room_id,
      {
        "body":"This bot can help you link/unlink your twitter account with the " +
        "Matrix Twitter Bridge. If this was not your intention, please kick the bot.",
        "msgtype":"m.text"
      }
    );
    //Add the room to the list.
  });
};
github Half-Shot / matrix-appservice-twitter / src / TimelineHandler.js View on Github external
TimelineHandler.prototype._constructTimelineRoom = function (user, alias, avatar) {
  var botID = this._bridge.getBot().getUserId();

  var roomOwner = "@twitter_" + user.id_str + ":" + this._bridge.opts.domain;
  var users = {};
  users[botID] = 100;
  users[roomOwner] = 75;
  var powers = roomPowers(users);
  var remote = new RemoteRoom("timeline_" + user.id_str);
  remote.set("twitter_type", "timeline");
  remote.set("twitter_user", roomOwner);

  var opts = {
    visibility: "public",
    room_alias_name: "twitter_@"+alias,
    name: "[Twitter] " + user.name,
    topic: user.description,
    invite: [roomOwner],
    initial_state: [
      powers, {
        "type": "m.room.join_rules",
        "content": {
          "join_rule": "public"
        },
        "state_key": ""