diff --git a/package-lock.json b/package-lock.json index 8974c6ea..0efc1f17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -204,6 +204,11 @@ "resolved": "https://registry.npmjs.org/@types/p-queue/-/p-queue-2.3.2.tgz", "integrity": "sha512-eKAv5Ql6k78dh3ULCsSBxX6bFNuGjTmof5Q/T6PiECDq0Yf8IIn46jCyp3RJvCi8owaEmm3DZH1PEImjBMd/vQ==" }, + "@types/prop-types": { + "version": "15.7.3", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz", + "integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==" + }, "@types/randomstring": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/@types/randomstring/-/randomstring-1.1.6.tgz", @@ -216,6 +221,15 @@ "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==", "dev": true }, + "@types/react": { + "version": "16.9.23", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.23.tgz", + "integrity": "sha512-SsGVT4E7L2wLN3tPYLiF20hmZTPGuzaayVunfgXzUn1x4uHVsKH6QDJQ/TdpHqwsTLd4CwrmQ2vOgxN7gE24gw==", + "requires": { + "@types/prop-types": "*", + "csstype": "^2.2.0" + } + }, "@types/request": { "version": "2.48.4", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.4.tgz", @@ -770,6 +784,11 @@ "which": "^1.2.9" } }, + "csstype": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.9.tgz", + "integrity": "sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q==" + }, "cycle": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", @@ -783,6 +802,11 @@ "assert-plus": "^1.0.0" } }, + "dateformat": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz", + "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==" + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -1639,6 +1663,19 @@ } } }, + "matrix-slack-parser": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/matrix-slack-parser/-/matrix-slack-parser-0.0.1.tgz", + "integrity": "sha512-FnNWMUJtctjb9Jidv+OGo+lFiJz/gsslbtrYL56I4UInAhkP0YZ+XLfisMejGaFgn0ScQbYRvnC8dIK7dwtAPA==", + "requires": { + "dateformat": "^3.0.3", + "escape-html": "^1.0.3", + "node-emoji": "^1.10.0", + "node-html-parser": "^1.1.18", + "slack-markdown": "0.0.2", + "unescape-html": "^1.1.0" + } + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -1885,6 +1922,21 @@ "semver": "^5.7.0" } }, + "node-html-parser": { + "version": "1.2.13", + "resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-1.2.13.tgz", + "integrity": "sha512-RTG5oDk3nh1oXQGYtQQa9w0v9LjltgzzO1tv3cpXzb9M/UkpFIZ5v4osx3OYAcnWx/ETBXjxs2cgtD9fhn6Bjw==", + "requires": { + "he": "1.1.1" + }, + "dependencies": { + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" + } + } + }, "nopt": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", @@ -2476,6 +2528,14 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, + "simple-markdown": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/simple-markdown/-/simple-markdown-0.7.2.tgz", + "integrity": "sha512-XfCvqqzMyzRj4L7eIxJgGaQ2Gaxr20GhTFMB+1yuY8q3xffjzmOg4Q5tC0kcaJPV42NNUHCQDaRK6jzi3/RhrA==", + "requires": { + "@types/react": ">=16.0.0" + } + }, "simple-swizzle": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", @@ -2484,6 +2544,16 @@ "is-arrayish": "^0.3.1" } }, + "slack-markdown": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/slack-markdown/-/slack-markdown-0.0.2.tgz", + "integrity": "sha512-QxOm6aniLL413eVyKMafzSbv9JpVludcdo/V793dcNnzApJztLD4kEh7v8Jm7nUTR7FNWxlBNkSLfXbkIxiW2g==", + "requires": { + "escape-html": "^1.0.3", + "node-emoji": "^1.10.0", + "simple-markdown": "^0.7.2" + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -2770,6 +2840,11 @@ "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.4.4.tgz", "integrity": "sha1-YaajIBBiKvoHljvzJSA88SI51gQ=" }, + "unescape-html": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/unescape-html/-/unescape-html-1.1.0.tgz", + "integrity": "sha512-O9/yBNqIkArjS597iHez5hAaAdn7b8/230SX8IncgXAX5tWI9XlEQYaz6Qbou0Sloa9n6lx9G5s6hg5qhJyzGg==" + }, "unhomoglyph": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/unhomoglyph/-/unhomoglyph-1.0.3.tgz", diff --git a/package.json b/package.json index 9b884c1c..fcf10ed6 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "escape-string-regexp": "^2.0.0", "matrix-appservice": "^0.4.1", "matrix-appservice-bridge": "^1.11.1", + "matrix-slack-parser": "0.0.1", "minimist": "^1.2.5", "nedb": "^1.8.0", "node-emoji": "^1.10.0", diff --git a/src/BridgedRoom.ts b/src/BridgedRoom.ts index d4ba48f6..a4b4a3f9 100644 --- a/src/BridgedRoom.ts +++ b/src/BridgedRoom.ts @@ -16,6 +16,7 @@ limitations under the License. import * as rp from "request-promise-native"; import { Logging, Intent } from "matrix-appservice-bridge"; +import { SlackMessageParser, ISlackMessage, ISlackMessageParserOpts } from "matrix-slack-parser"; import { SlackGhost } from "./SlackGhost"; import { Main, METRIC_SENT_MESSAGES } from "./Main"; import { default as substitutions, getFallbackForMissingEmoji, IMatrixToSlackResult } from "./substitutions"; @@ -630,10 +631,19 @@ export class BridgedRoom { const subtype = message.subtype; - // Transform the text if it is present. if (message.text) { - message.text = substitutions.slackToMatrix(message.text, - subtype === "file_comment" ? message.file : undefined); + const parser = new SlackMessageParser(); + const opts = { + callbacks: { + getUser: async (id: string, name: string) => null, + getChannel: async (id: string, name: string) => null, + getUsergroup: async (id: string, name: string) => null, + getTeam: async (id: string, name: string) => null, + urlToMxc: async (url: string) => null, + }, + } as ISlackMessageParserOpts; + const result = await parser.FormatMessage(opts, message as ISlackMessage); + await ghost.sendMessage(this.matrixRoomId, result, channelId, eventTS); } if (message.thread_ts !== undefined && message.text) {