How to use the m.new_content function in m

To help you get started, we’ve selected a few m 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-appservice-slack / src / BridgedRoom.ts View on Github external
public async onMatrixEdit(message: any) {
        if (!this.botClient) { return false; }

        const event = await this.main.datastore.getEventByMatrixId(
            message.room_id,
            message.content["m.relates_to"].event_id,
        );

        if (!event) {
            log.debug("Skipping matrix edit because couldn't find event in datastore");
            return false;
        }
        // re-write the message so the matrixToSlack converter works as expected.
        let newMessage = JSON.parse(JSON.stringify(message));
        newMessage.content = message.content["m.new_content"];
        newMessage = await this.stripMatrixReplyFallback(newMessage);

        const body = await substitutions.matrixToSlack(newMessage, this.main, this.SlackTeamId!);

        if (!body || !body.text) {
            log.warn(`Dropped edit ${message.event_id}, message content could not be identified`);
            // Could not handle content, dropped
            return false;
        }

        const res = (await this.botClient.chat.update({
            ts: event.slackTs,
            as_user: false,
            channel: this.slackChannelId!,
            ...body,
            // We include this for type safety as Typescript isn't aware that body.text is defined
github matrix-org / matrix-appservice-slack / lib / BridgedRoom.js View on Github external
BridgedRoom.prototype.onMatrixEdit = async function(message) {
    if (!this._slack_webhook_uri && !this._slack_bot_token) return Promise.resolve();

    const eventStore = this._main.getEventStore();
    const event = await eventStore.getEntryByMatrixId(message.room_id, message.content['m.relates_to'].event_id);

    // re-write the message so the matrixToSlack converter works as expected.
    const new_message = JSON.parse(JSON.stringify(message));
    new_message.content = message.content['m.new_content'];

    const body = await substitutions.matrixToSlack(new_message, this._main, this._slack_team_id);

    const sendMessageParams = {
        method: "POST",
        json: true,
        uri: "https://slack.com/api/chat.update",
        body: body,
    };
    sendMessageParams.body.ts = event.remoteEventId;
    sendMessageParams.body.as_user = false;
    sendMessageParams.body.channel = this._slack_channel_id;

    if (this._slack_bot_token) {
        sendMessageParams.headers = {
            Authorization: 'Bearer ' + this._slack_bot_token
github mozilla / releases-comm-central / chat / protocols / matrix / lib / matrix-sdk / models / event.js View on Github external
getContent: function () {
        if (this._localRedactionEvent) {
            return {};
        } else if (this._replacingEvent) {
            return this._replacingEvent.getContent()["m.new_content"] || {};
        } else {
            return this.getOriginalContent();
        }
    },
github matrix-org / matrix-js-sdk / src / models / event.js View on Github external
getContent: function() {
        if (this._localRedactionEvent) {
            return {};
        } else if (this._replacingEvent) {
            return this._replacingEvent.getContent()["m.new_content"] || {};
        } else {
            return this.getOriginalContent();
        }
    },