Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
getContent: function () {
if (this._localRedactionEvent) {
return {};
} else if (this._replacingEvent) {
return this._replacingEvent.getContent()["m.new_content"] || {};
} else {
return this.getOriginalContent();
}
},
getContent: function() {
if (this._localRedactionEvent) {
return {};
} else if (this._replacingEvent) {
return this._replacingEvent.getContent()["m.new_content"] || {};
} else {
return this.getOriginalContent();
}
},