@narumitw/pi-notify 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -12
- package/dist/chunks/chunk-YXQ43SWY.ts +318 -0
- package/dist/chunks/chunk-YXQ43SWY.ts.map +7 -0
- package/dist/chunks/menu-2A2EKOVH.ts +988 -0
- package/dist/chunks/menu-2A2EKOVH.ts.map +7 -0
- package/dist/index.ts +1096 -0
- package/dist/index.ts.map +7 -0
- package/docs/settings.md +109 -5
- package/package.json +11 -2
- package/src/destination-ui.ts +22 -0
- package/src/menu.ts +82 -3
- package/src/provider.ts +16 -1
- package/src/providers/line.ts +91 -0
- package/src/providers/teams.ts +156 -0
- package/src/providers.ts +4 -0
package/src/menu.ts
CHANGED
|
@@ -59,6 +59,9 @@ type Action =
|
|
|
59
59
|
| "addDiscord"
|
|
60
60
|
| "addBark"
|
|
61
61
|
| "addWebhook"
|
|
62
|
+
| "addTeams"
|
|
63
|
+
| "addLine"
|
|
64
|
+
| "recipientId"
|
|
62
65
|
| "userKey"
|
|
63
66
|
| "bearerToken"
|
|
64
67
|
| "ntfyTopic"
|
|
@@ -94,6 +97,8 @@ export const helpLines = [
|
|
|
94
97
|
"Gotify labels are generated automatically. Edit the label or optional safe-integer priority from the destination review. An empty priority uses the server default.",
|
|
95
98
|
"For Slack, enable Incoming Webhooks in a Slack app and add a webhook to your workspace. Its installation fixes the channel. Paste the complete hooks.slack.com URL only into the masked field; never into Pi chat.",
|
|
96
99
|
"Slack webhook URLs are secrets. Reviews and Status show only that a webhook is configured. Revoke an exposed webhook in the Slack app before replacing it.",
|
|
100
|
+
"For Microsoft Teams, create a Workflows webhook with Anyone authentication. Enter its complete current signed URL only in the masked field. The workflow owns its target. HTTP 202 means trigger acceptance, not proof of a Teams post; live interoperability is not yet verified. See docs/settings.md for supported URLs, setup, and revocation.",
|
|
101
|
+
"For LINE, enable Messaging API on an Official Account and enter its channel access token and user/group/room ID in masked inputs. Recipient eligibility and account quotas apply. LINE Notify is not supported. See docs/settings.md for setup and revocation.",
|
|
97
102
|
"For ntfy, subscribe to a topic and configure server authentication and topic permissions. Topic secrecy is not access control. Review the server, optional Bearer token, and priority from 1 to 5.",
|
|
98
103
|
"For Pushover, enter the application token and user key in masked inputs. Delivery uses normal priority only, without emergency acknowledgement or retries.",
|
|
99
104
|
"For Discord, paste a normal text-channel webhook URL into the masked input. Mentions and link embeds are disabled; forum/media channels and thread selection are not supported.",
|
|
@@ -180,9 +185,12 @@ export async function showNotifyMenu(ctx: ExtensionCommandContext, options: Menu
|
|
|
180
185
|
draft = undefined;
|
|
181
186
|
return { kind: "to", screen: "main" } as const;
|
|
182
187
|
};
|
|
183
|
-
const addWebhook = async (provider: "discord" | "webhook", actionSignal: AbortSignal) => {
|
|
188
|
+
const addWebhook = async (provider: "discord" | "webhook" | "teams", actionSignal: AbortSignal) => {
|
|
184
189
|
const result = await runSecretInput(menuCtx, {
|
|
185
|
-
title:
|
|
190
|
+
title:
|
|
191
|
+
provider === "teams"
|
|
192
|
+
? "Teams workflow webhook URL"
|
|
193
|
+
: `${provider === "discord" ? "Discord" : "Generic webhook"} URL`,
|
|
186
194
|
signal: actionSignal,
|
|
187
195
|
isCurrent,
|
|
188
196
|
onError: reportError,
|
|
@@ -193,7 +201,12 @@ export async function showNotifyMenu(ctx: ExtensionCommandContext, options: Menu
|
|
|
193
201
|
if (result.kind !== "submitted") return { kind: "stay" } as const;
|
|
194
202
|
const destination = providers.get(provider)?.validate({
|
|
195
203
|
provider,
|
|
196
|
-
label:
|
|
204
|
+
label:
|
|
205
|
+
provider === "teams"
|
|
206
|
+
? "Microsoft Teams notifications"
|
|
207
|
+
: provider === "discord"
|
|
208
|
+
? "Discord notifications"
|
|
209
|
+
: "Generic webhook notifications",
|
|
197
210
|
webhookUrl: result.value,
|
|
198
211
|
});
|
|
199
212
|
if (!destination) throw new Error("Use a valid webhook URL.");
|
|
@@ -248,6 +261,8 @@ export async function showNotifyMenu(ctx: ExtensionCommandContext, options: Menu
|
|
|
248
261
|
{ id: "addDiscord", label: "Add Discord destination", action: "addDiscord" },
|
|
249
262
|
{ id: "addBark", label: "Add Bark destination", action: "addBark" },
|
|
250
263
|
{ id: "addWebhook", label: "Add Generic webhook destination", action: "addWebhook" },
|
|
264
|
+
{ id: "addLine", label: "Add LINE destination", action: "addLine" },
|
|
265
|
+
{ id: "addTeams", label: "Add Microsoft Teams destination", action: "addTeams" },
|
|
251
266
|
],
|
|
252
267
|
}),
|
|
253
268
|
destination: () => ({
|
|
@@ -429,6 +444,9 @@ export async function showNotifyMenu(ctx: ExtensionCommandContext, options: Menu
|
|
|
429
444
|
...(assertDraft().provider === "pushover"
|
|
430
445
|
? [{ id: "userKey", label: "Replace user key…", action: "userKey" as const }]
|
|
431
446
|
: []),
|
|
447
|
+
...(assertDraft().provider === "line"
|
|
448
|
+
? [{ id: "recipientId", label: "Replace recipient ID…", action: "recipientId" as const }]
|
|
449
|
+
: []),
|
|
432
450
|
{ id: "label", label: "Change label…", to: "label" },
|
|
433
451
|
...(assertDraft().provider === "webhook"
|
|
434
452
|
? [{ id: "bearerToken", label: "Set Bearer token (empty for none)…", action: "bearerToken" as const }]
|
|
@@ -615,8 +633,60 @@ export async function showNotifyMenu(ctx: ExtensionCommandContext, options: Menu
|
|
|
615
633
|
draft = destination;
|
|
616
634
|
return { kind: "to", screen: "review" };
|
|
617
635
|
},
|
|
636
|
+
addLine: async ({ signal: actionSignal }) => {
|
|
637
|
+
const token = await runSecretInput(menuCtx, {
|
|
638
|
+
title: "LINE channel access token",
|
|
639
|
+
signal: actionSignal,
|
|
640
|
+
isCurrent,
|
|
641
|
+
onError: reportError,
|
|
642
|
+
});
|
|
643
|
+
actionSignal.throwIfAborted();
|
|
644
|
+
current();
|
|
645
|
+
if (token.kind === "closed" && token.reason === "close") return { kind: "close" };
|
|
646
|
+
if (token.kind !== "submitted") return { kind: "stay" };
|
|
647
|
+
const recipient = await runSecretInput(menuCtx, {
|
|
648
|
+
title: "LINE recipient ID (user, group, or room)",
|
|
649
|
+
signal: actionSignal,
|
|
650
|
+
isCurrent,
|
|
651
|
+
onError: reportError,
|
|
652
|
+
});
|
|
653
|
+
actionSignal.throwIfAborted();
|
|
654
|
+
current();
|
|
655
|
+
if (recipient.kind === "closed" && recipient.reason === "close") return { kind: "close" };
|
|
656
|
+
if (recipient.kind !== "submitted") return { kind: "stay" };
|
|
657
|
+
const destination = providers.get("line")?.validate({
|
|
658
|
+
provider: "line",
|
|
659
|
+
label: "LINE notifications",
|
|
660
|
+
channelAccessToken: token.value.trim(),
|
|
661
|
+
recipientId: recipient.value.trim(),
|
|
662
|
+
});
|
|
663
|
+
if (!destination) throw new Error("Use a valid LINE token and recipient ID.");
|
|
664
|
+
selectedId = randomUUID();
|
|
665
|
+
draft = destination;
|
|
666
|
+
return { kind: "to", screen: "review" };
|
|
667
|
+
},
|
|
668
|
+
recipientId: async ({ signal: actionSignal }) => {
|
|
669
|
+
const result = await runSecretInput(menuCtx, {
|
|
670
|
+
title: "Replace LINE recipient ID",
|
|
671
|
+
signal: actionSignal,
|
|
672
|
+
isCurrent,
|
|
673
|
+
onError: reportError,
|
|
674
|
+
});
|
|
675
|
+
actionSignal.throwIfAborted();
|
|
676
|
+
current();
|
|
677
|
+
if (result.kind === "closed" && result.reason === "close") return { kind: "close" };
|
|
678
|
+
if (result.kind === "submitted") {
|
|
679
|
+
const destination = assertDraft();
|
|
680
|
+
const valid = providers.get("line")?.validate({ ...destination, recipientId: result.value.trim() });
|
|
681
|
+
if (destination.provider !== "line" || valid?.provider !== "line")
|
|
682
|
+
throw new Error("Use a valid LINE user, group, or room ID.");
|
|
683
|
+
destination.recipientId = valid.recipientId;
|
|
684
|
+
}
|
|
685
|
+
return { kind: "stay" };
|
|
686
|
+
},
|
|
618
687
|
addDiscord: ({ signal: actionSignal }) => addWebhook("discord", actionSignal),
|
|
619
688
|
addWebhook: ({ signal: actionSignal }) => addWebhook("webhook", actionSignal),
|
|
689
|
+
addTeams: ({ signal: actionSignal }) => addWebhook("teams", actionSignal),
|
|
620
690
|
addBark: async ({ signal: actionSignal }) => {
|
|
621
691
|
const result = await runSecretInput(menuCtx, {
|
|
622
692
|
title: "Bark device key",
|
|
@@ -759,6 +829,15 @@ export async function showNotifyMenu(ctx: ExtensionCommandContext, options: Menu
|
|
|
759
829
|
destination.deviceKey = valid.deviceKey;
|
|
760
830
|
break;
|
|
761
831
|
}
|
|
832
|
+
case "line": {
|
|
833
|
+
const valid = providers
|
|
834
|
+
.get("line")
|
|
835
|
+
?.validate({ ...destination, channelAccessToken: result.value.trim() });
|
|
836
|
+
if (valid?.provider !== "line") throw new Error("Use a valid LINE channel access token.");
|
|
837
|
+
destination.channelAccessToken = valid.channelAccessToken;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
case "teams":
|
|
762
841
|
case "discord":
|
|
763
842
|
case "webhook": {
|
|
764
843
|
const valid = providers.get(destination.provider)?.validate({ ...destination, webhookUrl: result.value });
|
package/src/provider.ts
CHANGED
|
@@ -49,6 +49,19 @@ export interface BarkDestination {
|
|
|
49
49
|
deviceKey: string;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export interface TeamsDestination {
|
|
53
|
+
provider: "teams";
|
|
54
|
+
label: string;
|
|
55
|
+
webhookUrl: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface LineDestination {
|
|
59
|
+
provider: "line";
|
|
60
|
+
label: string;
|
|
61
|
+
channelAccessToken: string;
|
|
62
|
+
recipientId: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
export interface WebhookDestination {
|
|
53
66
|
provider: "webhook";
|
|
54
67
|
label: string;
|
|
@@ -64,7 +77,9 @@ export type Destination =
|
|
|
64
77
|
| PushoverDestination
|
|
65
78
|
| DiscordDestination
|
|
66
79
|
| BarkDestination
|
|
67
|
-
| WebhookDestination
|
|
80
|
+
| WebhookDestination
|
|
81
|
+
| LineDestination
|
|
82
|
+
| TeamsDestination;
|
|
68
83
|
|
|
69
84
|
export interface BodyEmphasis {
|
|
70
85
|
style: "bold" | "monospace";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2
|
+
import { type DeliveryResult, isObject, type NotificationProvider } from "../provider.js";
|
|
3
|
+
import { clipText } from "../text.js";
|
|
4
|
+
import { postJson } from "./http.js";
|
|
5
|
+
|
|
6
|
+
// Verified 2026-10-18: https://developers.line.biz/en/reference/messaging-api/#send-push-message
|
|
7
|
+
// https://developers.line.biz/en/docs/messaging-api/text-character-count/: 5,000 UTF-16 units.
|
|
8
|
+
// https://developers.line.biz/en/docs/basics/channel-access-token/: tokens are opaque.
|
|
9
|
+
// RFC 6750 section 2.1 defines Bearer syntax; 8,192 is a local cap, not a LINE token limit.
|
|
10
|
+
const MAX_TOKEN_LENGTH = 8192;
|
|
11
|
+
|
|
12
|
+
function plainText(text: string): string {
|
|
13
|
+
return text.split("\n").map(sanitizeTerminalText).join("\n");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function acceptedBody(body: unknown): boolean {
|
|
17
|
+
if (!isObject(body)) return false;
|
|
18
|
+
// Legacy {}: https://github.com/line/line-bot-sdk-nodejs/blob/master/test/line-bot-client.spec.ts
|
|
19
|
+
// Current schema: https://github.com/line/line-openapi/blob/main/messaging-api.yml
|
|
20
|
+
if (Object.keys(body).length === 0) return true;
|
|
21
|
+
// Current reference uses Number for id; official line-openapi and its example use String.
|
|
22
|
+
return (
|
|
23
|
+
Array.isArray(body.sentMessages) &&
|
|
24
|
+
body.sentMessages.length >= 1 &&
|
|
25
|
+
body.sentMessages.length <= 5 &&
|
|
26
|
+
body.sentMessages.every(
|
|
27
|
+
(message) =>
|
|
28
|
+
isObject(message) &&
|
|
29
|
+
((typeof message.id === "string" && message.id.length > 0) ||
|
|
30
|
+
(typeof message.id === "number" && Number.isInteger(message.id) && message.id >= 0)) &&
|
|
31
|
+
(message.quoteToken === undefined || typeof message.quoteToken === "string"),
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One normal text push; HTTP acceptance does not prove recipient delivery. */
|
|
37
|
+
export function createLineProvider(fetcher: typeof fetch = fetch): NotificationProvider {
|
|
38
|
+
return {
|
|
39
|
+
id: "line",
|
|
40
|
+
label: "LINE",
|
|
41
|
+
validate(value) {
|
|
42
|
+
if (!isObject(value) || value.provider !== "line") return undefined;
|
|
43
|
+
if (typeof value.label !== "string" || !value.label.trim() || value.label.length > 128) return undefined;
|
|
44
|
+
if (
|
|
45
|
+
typeof value.channelAccessToken !== "string" ||
|
|
46
|
+
value.channelAccessToken.length > MAX_TOKEN_LENGTH ||
|
|
47
|
+
/\s/u.test(value.channelAccessToken) ||
|
|
48
|
+
!/^[A-Za-z0-9._~+/-]+=*$/u.test(value.channelAccessToken)
|
|
49
|
+
)
|
|
50
|
+
return undefined;
|
|
51
|
+
// https://developers.line.biz/en/docs/messaging-api/getting-user-ids/: U + 32 lowercase hex.
|
|
52
|
+
// The push reference's webhook source examples use C/R prefixes for group/room IDs.
|
|
53
|
+
// Group/room syntax is not specified: printable ASCII and 128 suffix characters
|
|
54
|
+
// are local safety bounds, not a claimed service grammar.
|
|
55
|
+
if (
|
|
56
|
+
typeof value.recipientId !== "string" ||
|
|
57
|
+
value.recipientId.length > 129 ||
|
|
58
|
+
/\s/u.test(value.recipientId) ||
|
|
59
|
+
!/^(?:U[0-9a-f]{32}|[CR][!-~]{1,128})$/u.test(value.recipientId)
|
|
60
|
+
)
|
|
61
|
+
return undefined;
|
|
62
|
+
return {
|
|
63
|
+
provider: "line",
|
|
64
|
+
label: value.label,
|
|
65
|
+
channelAccessToken: value.channelAccessToken,
|
|
66
|
+
recipientId: value.recipientId,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
async send(destination, notification, signal): Promise<DeliveryResult> {
|
|
70
|
+
if (signal.aborted) return { state: "cancelled", code: "cancelled" };
|
|
71
|
+
const valid = this.validate(destination);
|
|
72
|
+
if (valid?.provider !== "line") return { state: "failed", code: "invalid-destination" };
|
|
73
|
+
const result = await postJson(
|
|
74
|
+
"https://api.line.me/v2/bot/message/push",
|
|
75
|
+
{
|
|
76
|
+
to: valid.recipientId,
|
|
77
|
+
// No mention/emoji objects, substitutions, formatting, or silent-delivery option.
|
|
78
|
+
// LINE clients can still auto-link literal URLs; this does not promise link suppression.
|
|
79
|
+
messages: [{ type: "text", text: clipText(plainText(`${notification.title}\n${notification.body}`), 5000) }],
|
|
80
|
+
},
|
|
81
|
+
signal,
|
|
82
|
+
fetcher,
|
|
83
|
+
{ Authorization: `Bearer ${valid.channelAccessToken}` },
|
|
84
|
+
);
|
|
85
|
+
if (result.state !== "response") return result;
|
|
86
|
+
return result.status === 200 && acceptedBody(result.body)
|
|
87
|
+
? { state: "accepted" }
|
|
88
|
+
: { state: "failed", code: "response" };
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2
|
+
import { type DeliveryResult, isObject, type NotificationProvider } from "../provider.js";
|
|
3
|
+
import { postJson } from "./http.js";
|
|
4
|
+
|
|
5
|
+
// Local support policy, not a complete Microsoft URL grammar. Reviewed 2026-10-18:
|
|
6
|
+
// https://learn.microsoft.com/en-us/power-automate/triggers-troubleshoot
|
|
7
|
+
// documents migration from logic.azure.com and the optional /direct/cu/20 route.
|
|
8
|
+
// https://learn.microsoft.com/en-us/connectors/teams/#microsoft-teams-webhook
|
|
9
|
+
// documents Anyone authentication (no Authorization header) and the card envelope.
|
|
10
|
+
// https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-http-endpoint
|
|
11
|
+
// documents signed Request URLs; this is corroboration, not a Teams URL/response contract.
|
|
12
|
+
// Public current-format example (corroboration only):
|
|
13
|
+
// https://dev.classmethod.jp/en/articles/aws-step-functions-teams-workflows-new-webhook-url/
|
|
14
|
+
// Support only literal lowercase commercial DNS hosts with one or more valid prefix
|
|
15
|
+
// labels before .environment.api.powerplatform.com; labels <=63, entire host <=253.
|
|
16
|
+
// Require HTTPS, no userinfo, and no port except an explicit generated :443.
|
|
17
|
+
// Paths are exactly /powerautomate/automations/direct/[cu/<route>/]workflows/<id>
|
|
18
|
+
// /triggers/manual/paths/invoke. Route/id are opaque ASCII letters, digits, _ or -,
|
|
19
|
+
// 1..256 characters each: a local bound, NOT an inferred fixed-length service ID.
|
|
20
|
+
// Reject all encoded hosts/paths, dot segments, fragments, whitespace, controls and
|
|
21
|
+
// backslashes before a URL parser could normalize them. Total URL cap: 8,192 chars.
|
|
22
|
+
// Query keys must be literal api-version, sp, sv, sig, exactly once, in any order.
|
|
23
|
+
// api-version=1 and sv=1.0 are literal; decoded sp is /triggers/manual/run.
|
|
24
|
+
// Decoded sig is nonempty opaque base64/base64url syntax (up to two trailing =).
|
|
25
|
+
// Percent escapes must be valid UTF-8. In particular, + is NOT form-decoded to space.
|
|
26
|
+
// Preserve the COMPLETE raw signed URL, including port, escape case and query order.
|
|
27
|
+
const MAX_URL_LENGTH = 8192;
|
|
28
|
+
const HOST_SUFFIX = ".environment.api.powerplatform.com";
|
|
29
|
+
const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
|
|
30
|
+
const WORKFLOW_PATH =
|
|
31
|
+
/^\/powerautomate\/automations\/direct\/(?:cu\/[A-Za-z0-9_-]{1,256}\/)?workflows\/[A-Za-z0-9_-]{1,256}\/triggers\/manual\/paths\/invoke$/u;
|
|
32
|
+
|
|
33
|
+
function workflowUrl(value: unknown): string | undefined {
|
|
34
|
+
if (typeof value !== "string" || value.length > MAX_URL_LENGTH || /[\s\\\p{Cc}]/u.test(value)) return undefined;
|
|
35
|
+
const parts = /^https:\/\/([^/?#]+)(\/[^?#]+)\?([^#]+)$/u.exec(value);
|
|
36
|
+
if (!parts) return undefined;
|
|
37
|
+
const [, authority = "", path = "", query = ""] = parts;
|
|
38
|
+
const hostname = authority.endsWith(":443") ? authority.slice(0, -4) : authority;
|
|
39
|
+
if (
|
|
40
|
+
hostname.length > 253 ||
|
|
41
|
+
!hostname.endsWith(HOST_SUFFIX) ||
|
|
42
|
+
hostname.length <= HOST_SUFFIX.length ||
|
|
43
|
+
!hostname.split(".").every((label) => DNS_LABEL.test(label)) ||
|
|
44
|
+
!WORKFLOW_PATH.test(path)
|
|
45
|
+
)
|
|
46
|
+
return undefined;
|
|
47
|
+
const values = new Map<string, string>();
|
|
48
|
+
try {
|
|
49
|
+
for (const pair of query.split("&")) {
|
|
50
|
+
const separator = pair.indexOf("=");
|
|
51
|
+
if (separator < 0) return undefined;
|
|
52
|
+
const key = pair.slice(0, separator);
|
|
53
|
+
const raw = pair.slice(separator + 1);
|
|
54
|
+
if (!["api-version", "sp", "sv", "sig"].includes(key) || values.has(key)) return undefined;
|
|
55
|
+
const decoded = decodeURIComponent(raw);
|
|
56
|
+
// Also reject encoded terminal whitespace: JavaScript's $ can precede a final newline.
|
|
57
|
+
if (/[\s\\\p{Cc}]/u.test(decoded)) return undefined;
|
|
58
|
+
if ((key === "api-version" && raw !== "1") || (key === "sv" && raw !== "1.0")) return undefined;
|
|
59
|
+
values.set(key, decoded);
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
if (
|
|
65
|
+
values.size !== 4 ||
|
|
66
|
+
values.get("sp") !== "/triggers/manual/run" ||
|
|
67
|
+
!/^[A-Za-z0-9_+/-]+={0,2}$/u.test(values.get("sig") ?? "")
|
|
68
|
+
)
|
|
69
|
+
return undefined;
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function card(text: string) {
|
|
74
|
+
return {
|
|
75
|
+
type: "message",
|
|
76
|
+
attachments: [
|
|
77
|
+
{
|
|
78
|
+
contentType: "application/vnd.microsoft.card.adaptive",
|
|
79
|
+
contentUrl: null,
|
|
80
|
+
content: {
|
|
81
|
+
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
|
|
82
|
+
type: "AdaptiveCard",
|
|
83
|
+
version: "1.2",
|
|
84
|
+
// TextRun has no Markdown support. No actions, images or mention entities.
|
|
85
|
+
// https://learn.microsoft.com/en-us/adaptive-cards/schema-explorer/text-run
|
|
86
|
+
// Clients can still auto-link text; this does not promise link suppression.
|
|
87
|
+
body: [{ type: "RichTextBlock", inlines: [{ type: "TextRun", text }] }],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// A local encoded-JSON budget, NOT proof of Teams' downstream rendered-card size.
|
|
95
|
+
// https://learn.microsoft.com/en-us/connectors/teams/#known-issues-and-limitations
|
|
96
|
+
// The connector's approximate 28 KB limit includes rendered elements.
|
|
97
|
+
const MAX_PAYLOAD_BYTES = 24_000;
|
|
98
|
+
const TEXT_BUDGET = MAX_PAYLOAD_BYTES - Buffer.byteLength(JSON.stringify(card("")), "utf8");
|
|
99
|
+
|
|
100
|
+
function boundedText(title: string, body: string): string {
|
|
101
|
+
const text = `${title}\n${body}`.split("\n").map(sanitizeTerminalText).join("\n");
|
|
102
|
+
const points: string[] = [];
|
|
103
|
+
const costs: number[] = [];
|
|
104
|
+
let bytes = 0;
|
|
105
|
+
for (const point of text) {
|
|
106
|
+
// Count JSON escapes as well as UTF-8, using only constant-sized serializations.
|
|
107
|
+
const cost = Buffer.byteLength(JSON.stringify(point), "utf8") - 2;
|
|
108
|
+
if (bytes + cost > TEXT_BUDGET) {
|
|
109
|
+
while (bytes + 3 > TEXT_BUDGET) {
|
|
110
|
+
bytes -= costs.pop() ?? 0;
|
|
111
|
+
points.pop();
|
|
112
|
+
}
|
|
113
|
+
return `${points.join("")}…`;
|
|
114
|
+
}
|
|
115
|
+
bytes += cost;
|
|
116
|
+
points.push(point);
|
|
117
|
+
costs.push(cost);
|
|
118
|
+
}
|
|
119
|
+
return points.join("");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** One workflow request. Local acceptance is HTTP 202, never downstream-post proof. */
|
|
123
|
+
export function createTeamsProvider(fetcher: typeof fetch = fetch): NotificationProvider {
|
|
124
|
+
return {
|
|
125
|
+
id: "teams",
|
|
126
|
+
label: "Microsoft Teams",
|
|
127
|
+
validate(value) {
|
|
128
|
+
if (!isObject(value) || value.provider !== "teams") return undefined;
|
|
129
|
+
if (typeof value.label !== "string" || !value.label.trim() || value.label.length > 128) return undefined;
|
|
130
|
+
const webhookUrl = workflowUrl(value.webhookUrl);
|
|
131
|
+
return webhookUrl ? { provider: "teams", label: value.label, webhookUrl } : undefined;
|
|
132
|
+
},
|
|
133
|
+
async send(destination, notification, signal): Promise<DeliveryResult> {
|
|
134
|
+
if (signal.aborted) return { state: "cancelled", code: "cancelled" };
|
|
135
|
+
const valid = this.validate(destination);
|
|
136
|
+
if (valid?.provider !== "teams") return { state: "failed", code: "invalid-destination" };
|
|
137
|
+
const result = await postJson(
|
|
138
|
+
valid.webhookUrl,
|
|
139
|
+
card(boundedText(notification.title, notification.body)),
|
|
140
|
+
signal,
|
|
141
|
+
fetcher,
|
|
142
|
+
);
|
|
143
|
+
if (result.state !== "response") return result;
|
|
144
|
+
// Explicit local status-only policy after the FULL bounded response read:
|
|
145
|
+
// https://www.rfc-editor.org/rfc/rfc9110.html#section-15.3.3
|
|
146
|
+
// 202 means accepted for processing, not completed. The Request documentation
|
|
147
|
+
// above corroborates default 202 without a Response action, but does not define
|
|
148
|
+
// Teams responses. A public workflow example also reports 202 despite a later
|
|
149
|
+
// workflow failure (corroboration only, NOT a normative Teams response shape):
|
|
150
|
+
// https://simonscholz.dev/tutorials/microsoft-teams-messages-webhook-workflow/
|
|
151
|
+
// Ignore bounded empty/text/JSON bodies and undocumented fields.
|
|
152
|
+
// Live Teams interoperability and downstream receipt remain unverified.
|
|
153
|
+
return result.status === 202 ? { state: "accepted" } : { state: "failed", code: "response" };
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
package/src/providers.ts
CHANGED
|
@@ -2,9 +2,11 @@ import type { Providers } from "./provider.js";
|
|
|
2
2
|
import { createBarkProvider } from "./providers/bark.js";
|
|
3
3
|
import { createDiscordProvider } from "./providers/discord.js";
|
|
4
4
|
import { createGotifyProvider } from "./providers/gotify.js";
|
|
5
|
+
import { createLineProvider } from "./providers/line.js";
|
|
5
6
|
import { createNtfyProvider } from "./providers/ntfy.js";
|
|
6
7
|
import { createPushoverProvider } from "./providers/pushover.js";
|
|
7
8
|
import { createSlackProvider } from "./providers/slack.js";
|
|
9
|
+
import { createTeamsProvider } from "./providers/teams.js";
|
|
8
10
|
import { createTelegramProvider } from "./providers/telegram.js";
|
|
9
11
|
import { createWebhookProvider } from "./providers/webhook.js";
|
|
10
12
|
|
|
@@ -17,4 +19,6 @@ export const providers: Providers = new Map([
|
|
|
17
19
|
["discord", createDiscordProvider()],
|
|
18
20
|
["bark", createBarkProvider()],
|
|
19
21
|
["webhook", createWebhookProvider()],
|
|
22
|
+
["line", createLineProvider()],
|
|
23
|
+
["teams", createTeamsProvider()],
|
|
20
24
|
]);
|