diff --git a/src/Connections/GenericHook.ts b/src/Connections/GenericHook.ts index 0d2004661..47dfe055c 100644 --- a/src/Connections/GenericHook.ts +++ b/src/Connections/GenericHook.ts @@ -23,6 +23,7 @@ import { ExecuteResultContent, ExecuteResultWebhookResponse, WebhookTransformer, + RelatesTo, } from "../generic/WebhookTransformer"; import { GetConnectionsResponseItem } from "../widgets/Api"; import { ConnectionType } from "./type"; @@ -591,9 +592,9 @@ export class GenericHookConnection } } - public transformHookData(data: unknown): { plain: string; html?: string } { + public transformHookData(data: unknown): { plain: string; html?: string, relates_to?: RelatesTo } { // Supported parameters https://developers.mattermost.com/integrate/incoming-webhooks/#parameters - const msg: { plain: string; html?: string } = { plain: "" }; + const msg: { plain: string; html?: string, relates_to?: RelatesTo } = { plain: "" }; const safeData = typeof data === "object" && data !== null ? (data as Record) @@ -620,6 +621,10 @@ export class GenericHookConnection msg.html = `${safeData.username}: ${msg.html}`; } } + + if (typeof safeData?.relates_to === "object") { + msg.relates_to = safeData.relates_to ?? undefined; + } // TODO: Transform Slackdown into markdown. return msg; } @@ -713,6 +718,9 @@ export class GenericHookConnection ...(content.mentions ? { "m.mentions": content.mentions } : undefined), + ...(content.relates_to + ? { "m.relates_to": content.relates_to } + : undefined), ...(content.html ? { format: "org.matrix.custom.html" } : undefined), ...(safeData ? { "uk.half-shot.hookshot.webhook_data": safeData } diff --git a/src/generic/WebhookTransformer.ts b/src/generic/WebhookTransformer.ts index 7191a8e22..8daeae509 100644 --- a/src/generic/WebhookTransformer.ts +++ b/src/generic/WebhookTransformer.ts @@ -10,7 +10,6 @@ interface Mentions { user_ids?: string[]; room?: boolean; } - interface FunctionResultObject { version: string; plain?: string; @@ -21,6 +20,14 @@ interface FunctionResultObject { mentions?: Mentions; } +export interface RelatesTo { + event_id?: string; + is_falling_back?: boolean; + key?: string; + "m.in_reply_to"?: { event_id?: string }; + rel_type?: string; +} + export interface ExecuteResultWebhookResponse { body: string; contentType?: string; @@ -32,6 +39,7 @@ export interface ExecuteResultContent { html?: string; msgtype?: string; mentions?: Mentions; + relates_to?: RelatesTo; } export interface ExecuteResult {