-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (40 loc) · 1.19 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Import Third-party Dependencies
import { type MorphixOptions } from "@sigyn/morphix";
import { type WebhookNotifierOptions, WebhookNotifier } from "@sigyn/notifiers";
export interface TeamsWebhookBodyFormat {
title: string;
text: string;
}
class TeamsNotifier extends WebhookNotifier<TeamsWebhookBodyFormat> {
override contentTemplateOptions(): MorphixOptions {
return {
transform: ({ value, key }) => (key === "logql" || key === "lokiUrl" ? value : `**${value ?? "unknown"}**`),
ignoreMissing: true
};
}
async formatWebhookBody(): Promise<TeamsWebhookBodyFormat> {
if (this.data.ruleConfig?.logql) {
this.data.ruleConfig.logql = this.#formatLogQL(this.data.ruleConfig.logql);
}
const [title, content] = await Promise.all([
this.formatTitle(),
this.formatContent()
]);
return {
title,
text: content.join("\n")
};
}
#formatLogQL(logql: string): string {
return `\`${logql.replaceAll("`", "'")}\``;
}
}
export async function execute(
options: WebhookNotifierOptions
) {
const notifier = new TeamsNotifier(options);
const body = await notifier.formatWebhookBody();
return notifier.execute(
body
);
}