How to use matrix-js-snippets - 10 common examples

To help you get started, we’ve selected a few matrix-js-snippets 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 turt2live / matrix-voyager-bot / src / bot / voyager.ts View on Github external
private onLeave(roomId: string, event: any) {
        if (event['sender'] === VoyagerBot.userId) {
            // Probably a self kick or operator action
            // TODO: Record soft kick (#160)
        } else if (event['content'] && event['content']['membership'] === 'ban') {
            // Banned
            this.addKickBan(roomId, event, 'ban');
        } else if (event['unsigned'] && event['unsigned']['prev_content'] && event['unsigned']['prev_content']['membership'] === 'ban') {
            // TODO: Handle unbanned state?
            LogService.info("Voyager", event['sender'] + " has unbanned us in " + roomId);
        } else {
            // Kicked
            this.addKickBan(roomId, event, 'kick');
        }
    }
github turt2live / matrix-dimension / src / api / dimension / DimensionIrcService.ts View on Github external
public async unlink(@QueryParam("scalar_token") scalarToken: string, @PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string, @PathParam("roomId") roomId: string): Promise {
        const userId = await this.accountController.getTokenOwner(scalarToken);

        const parsed = IrcBridge.parseNetworkId(networkId);
        const bridge = await IrcBridgeRecord.findByPk(parsed.bridgeId);
        if (!bridge) throw new ApiError(404, "Bridge not found");

        const client = new IrcBridge(userId);
        await client.removeLink(bridge, parsed.bridgeNetworkId, "#" + channelNoHash, roomId);

        LogService.info("DimensionIrcService", userId + " unlinked #" + channelNoHash + " on " + networkId + " from " + roomId);
        return {}; // 200 OK
    }
}
github turt2live / matrix-dimension / src / api / Webserver.ts View on Github external
private loadRoutes() {
        // TODO: Rename services to controllers, and controllers to services. They're backwards.

        const apis = ["scalar", "dimension", "admin", "matrix"].map(a => path.join(__dirname, a, "*.js"));
        const router = express.Router();
        Server.useIoC();
        Server.registerAuthenticator(new MatrixSecurity());
        apis.forEach(a => Server.loadServices(router, [a]));
        const routes = _.uniq(router.stack.map(r => r.route.path));
        for (const route of routes) {
            this.app.options(route, (_req, res) => res.sendStatus(200));
            LogService.info("Webserver", "Registered route: " + route);
        }
        this.app.use(router);

        // We register the default route last to make sure we don't override anything by accident.
        // We'll pass off all other requests to the web app
        this.app.get(/(widgets\/|riot\/|\/)*/, (_req, res) => {
            res.sendFile(path.join(__dirname, "..", "..", "web", "index.html"));
        });

        // Set up the error handler
        this.app.use((err: any, _req, res, next) => {
            if (err instanceof ApiError) {
                // Don't do anything for 'connection reset'
                if (res.headersSent) return next(err);

                LogService.warn("Webserver", "Handling ApiError " + err.statusCode + " " + JSON.stringify(err.jsonResponse));
github turt2live / matrix-dimension / src / api / matrix / MatrixAppServiceApiService.ts View on Github external
public async getRoom(@QueryParam("access_token") homeserverToken: string, @PathParam("alias") roomAlias: string): Promise {
        try {
            const appservice = await AppserviceStore.getByHomeserverToken(homeserverToken);

            // We don't support room lookups
            LogService.verbose("MatrixAppServiceApiService", "404ing request for room " + roomAlias + " at appservice " + appservice.id);
            throw new ApiError(404, {errcode: "IO.T2BOT.DIMENSION.ROOMS_NOT_SUPPORTED"});
        } catch (err) {
            if (err instanceof ApiError) throw err;
            LogService.error("MatrixAppServiceApiService", err);
            throw new ApiError(403, {errcode: "M_FORBIDDEN"});
        }
    }
github turt2live / matrix-dimension / src / db / AppserviceStore.ts View on Github external
public static async registerUser(appserviceId: string, userId: string): Promise {
        const appservice = await AppService.findOne({where: {id: appserviceId}});
        if (!appservice) throw new Error("Appservice not found");

        LogService.info("AppserviceStore", "Registering to own " + userId + " in appservice " + appserviceId);
        const client = new MatrixAppserviceClient(appservice);
        const localpart = AppserviceStore.getSafeUserId(userId.substring(1).split(":")[0]);
        const response = await client.registerUser(localpart);
        LogService.info("AppserviceStore", "Successfully registered " + userId);

        return await AppServiceUser.create({
            id: userId,
            appserviceId: appserviceId,
            accessToken: response.access_token,
        });
    }
github turt2live / matrix-dimension / src / api / admin / AdminCustomSimpleBotService.ts View on Github external
public async createBot(@QueryParam("scalar_token") scalarToken: string, request: BotRequest): Promise {
        const userId = await AdminService.validateAndGetAdminTokenOwner(scalarToken);

        const bot = await BotStore.createCustom(request);
        LogService.info("AdminCustomSimpleBotService", userId + " created a simple bot");
        Cache.for(CACHE_INTEGRATIONS).clear();
        return bot;
    }
github turt2live / matrix-appservice-webhooks / src / provisioning / ProvisioningService.js View on Github external
deleteWebhook(roomId, userId, hookId) {
        LogService.info("ProvisioningService", "Processing delete hook (" + hookId + ") request for " + roomId + " by " + userId);

        return this.hasPermission(userId, roomId)
            .then(async () => {
                const webhooks = await WebhookStore.listWebhooks(roomId);
                if (webhooks.length === 1 && webhooks[0].id === hookId) {
                    await this._intent.leave(roomId);
                }
                return WebhookStore.deleteWebhook(roomId, hookId)
            }, () => Promise.reject(this.PERMISSION_ERROR_MESSAGE));
    }
github turt2live / matrix-dimension / src / api / dimension / DimensionSlackService.ts View on Github external
public async getAuthUrl(@QueryParam("scalar_token") scalarToken: string): Promise<{ authUrl: string }> {
        const userId = await this.accountController.getTokenOwner(scalarToken);

        try {
            const slack = new SlackBridge(userId);
            const authUrl = await slack.getAuthUrl();
            return {authUrl};
        } catch (e) {
            LogService.error("DimensionSlackService", e);
            throw new ApiError(400, "Error getting auth info");
        }
    }
}
github turt2live / matrix-dimension / src / api / dimension / DimensionSlackService.ts View on Github external
public async getChannels(@QueryParam("scalar_token") scalarToken: string, @PathParam("teamId") teamId: string): Promise {
        const userId = await this.accountController.getTokenOwner(scalarToken);

        try {
            const slack = new SlackBridge(userId);
            return slack.getChannels(teamId);
        } catch (e) {
            LogService.error("DimensionSlackService", e);
            throw new ApiError(400, "Error getting channel info");
        }
    }
github turt2live / matrix-dimension / src / api / dimension / DimensionGitterService.ts View on Github external
public async getLink(@QueryParam("scalar_token") scalarToken: string, @PathParam("roomId") roomId: string): Promise {
        const userId = await this.accountController.getTokenOwner(scalarToken);

        try {
            const gitter = new GitterBridge(userId);
            return gitter.getLink(roomId);
        } catch (e) {
            LogService.error("DimensionGitterService", e);
            throw new ApiError(400, "Error getting bridge info");
        }
    }

matrix-js-snippets

A small collection of JS snippets for matrix bots

MIT
Latest version published 7 years ago

Package Health Score

46 / 100
Full package analysis