Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Connections/GenericHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ExecuteResultContent,
ExecuteResultWebhookResponse,
WebhookTransformer,
RelatesTo,
} from "../generic/WebhookTransformer";
import { GetConnectionsResponseItem } from "../widgets/Api";
import { ConnectionType } from "./type";
Expand Down Expand Up @@ -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<string, unknown>)
Expand All @@ -620,6 +621,10 @@ export class GenericHookConnection
msg.html = `<strong>${safeData.username}</strong>: ${msg.html}`;
}
}

if (typeof safeData?.relates_to === "object") {
msg.relates_to = safeData.relates_to ?? undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs stronger validation, at least checking whether the object looks like a relates_to object?

}
// TODO: Transform Slackdown into markdown.
return msg;
}
Expand Down Expand Up @@ -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 }
Expand Down
10 changes: 9 additions & 1 deletion src/generic/WebhookTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface Mentions {
user_ids?: string[];
room?: boolean;
}

interface FunctionResultObject {
version: string;
plain?: string;
Expand All @@ -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;
Expand All @@ -32,6 +39,7 @@ export interface ExecuteResultContent {
html?: string;
msgtype?: string;
mentions?: Mentions;
relates_to?: RelatesTo;
}

export interface ExecuteResult {
Expand Down