Skip to content

Commit 33037b8

Browse files
Initial commit
Signed-off-by: Lyns <lotsofthoughts@lynsei.com>
1 parent cbfe6d2 commit 33037b8

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/func_report.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,48 @@ import { logColor } from "./declare_const.ts";
33
import { logToReport } from "./func_streams.ts";
44
import { TEAMS_WEB_HOOK } from "./func_webhook.ts";
55
import * as $error from "./func_error.ts";
6+
67
/**
78
* @function notifyTeams
89
* @description Sends a notification to Microsoft Teams using a TEAMS_WEB_HOOK URL.
910
* @param message - The message to be sent to Teams Hook URL via POST.
1011
* @returns responseText - The response object text from the TEAMS_WEB_HOOK promise response
1112
*/
12-
export async function notifyTeams(message: string): Promise<string | boolean> {
13+
export async function notifyTeams(message: string) {
1314
$error.logErrorWithType(
14-
`Attempted Teams Webhook Message: ${message}`,
15-
"",
16-
"brightBlue",
17-
" ╰─── ",
18-
);
19-
if (typeof TEAMS_WEB_HOOK === "string" && TEAMS_WEB_HOOK.length > 0) {
15+
`Attempted Teams Webhook Message: ${message}`,
16+
'', 'brightBlue', ' ╰─── '
17+
)
18+
if (typeof TEAMS_WEB_HOOK === 'string' && TEAMS_WEB_HOOK.length > 0) {
2019
const response = await fetch(TEAMS_WEB_HOOK, {
21-
method: "POST",
22-
headers: { "Content-Type": "application/json" },
23-
body: JSON.stringify({ text: message }),
24-
});
25-
const responseText = await response.text();
26-
return responseText;
27-
} else return false;
20+
method: 'POST',
21+
headers: { 'Content-Type': 'application/json' },
22+
body: JSON.stringify(
23+
{
24+
type: 'message',
25+
attachments: [
26+
{
27+
contentType: 'application/vnd.microsoft.card.adaptive',
28+
contentUrl: null,
29+
content: {
30+
"$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
31+
"type":"AdaptiveCard",
32+
"version":"1.2",
33+
"body":[
34+
{
35+
"type": "TextBlock",
36+
"text": message
37+
}
38+
]
39+
}
40+
}
41+
]
42+
}
43+
),
44+
})
45+
const responseText = await response.text()
46+
return responseText
47+
} else return false
2848
}
2949

3050
/**

0 commit comments

Comments
 (0)