@gakr-gakr/msteams 0.1.0
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/api.ts +3 -0
- package/autobot.plugin.json +15 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +2 -0
- package/config-api.ts +4 -0
- package/contract-api.ts +4 -0
- package/index.ts +20 -0
- package/package.json +72 -0
- package/runtime-api.ts +66 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +13 -0
- package/setup-plugin-api.ts +3 -0
- package/src/ai-entity.ts +7 -0
- package/src/approval-auth.ts +44 -0
- package/src/attachments/bot-framework.ts +348 -0
- package/src/attachments/download.ts +328 -0
- package/src/attachments/graph.ts +489 -0
- package/src/attachments/html.ts +122 -0
- package/src/attachments/payload.ts +14 -0
- package/src/attachments/remote-media.ts +86 -0
- package/src/attachments/shared.ts +655 -0
- package/src/attachments/types.ts +47 -0
- package/src/attachments.ts +18 -0
- package/src/channel-api.ts +1 -0
- package/src/channel.runtime.ts +56 -0
- package/src/channel.setup.ts +77 -0
- package/src/channel.ts +1176 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +40 -0
- package/src/conversation-store-fs.ts +149 -0
- package/src/conversation-store-helpers.ts +105 -0
- package/src/conversation-store-memory.ts +51 -0
- package/src/conversation-store.ts +71 -0
- package/src/directory-live.ts +111 -0
- package/src/doctor.ts +27 -0
- package/src/errors.ts +270 -0
- package/src/feedback-reflection-prompt.ts +117 -0
- package/src/feedback-reflection-store.ts +113 -0
- package/src/feedback-reflection.ts +271 -0
- package/src/file-consent-helpers.ts +115 -0
- package/src/file-consent-invoke.ts +150 -0
- package/src/file-consent.ts +223 -0
- package/src/graph-chat.ts +36 -0
- package/src/graph-group-management.ts +168 -0
- package/src/graph-members.ts +48 -0
- package/src/graph-messages.ts +534 -0
- package/src/graph-teams.ts +114 -0
- package/src/graph-thread.ts +146 -0
- package/src/graph-upload.ts +531 -0
- package/src/graph-users.ts +29 -0
- package/src/graph.ts +308 -0
- package/src/inbound.ts +148 -0
- package/src/index.ts +4 -0
- package/src/media-helpers.ts +105 -0
- package/src/mentions.ts +114 -0
- package/src/messenger.ts +608 -0
- package/src/monitor-handler/access.ts +136 -0
- package/src/monitor-handler/inbound-media.ts +180 -0
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +28 -0
- package/src/monitor-handler/message-handler.test-support.ts +102 -0
- package/src/monitor-handler/message-handler.ts +1015 -0
- package/src/monitor-handler/reaction-handler.ts +124 -0
- package/src/monitor-handler/thread-session.ts +30 -0
- package/src/monitor-handler.ts +538 -0
- package/src/monitor-handler.types.ts +27 -0
- package/src/monitor-types.ts +6 -0
- package/src/monitor.ts +476 -0
- package/src/oauth.flow.ts +77 -0
- package/src/oauth.shared.ts +37 -0
- package/src/oauth.token.ts +162 -0
- package/src/oauth.ts +130 -0
- package/src/outbound.ts +198 -0
- package/src/pending-uploads-fs.ts +235 -0
- package/src/pending-uploads.ts +121 -0
- package/src/policy.ts +245 -0
- package/src/polls-store-memory.ts +32 -0
- package/src/polls.ts +312 -0
- package/src/presentation.ts +93 -0
- package/src/probe.ts +132 -0
- package/src/reply-dispatcher.ts +523 -0
- package/src/reply-stream-controller.ts +334 -0
- package/src/resolve-allowlist.ts +309 -0
- package/src/revoked-context.ts +17 -0
- package/src/runtime.ts +12 -0
- package/src/sdk-types.ts +59 -0
- package/src/sdk.ts +916 -0
- package/src/secret-contract.ts +49 -0
- package/src/secret-input.ts +7 -0
- package/src/send-context.ts +269 -0
- package/src/send.ts +697 -0
- package/src/sent-message-cache.ts +174 -0
- package/src/session-route.ts +40 -0
- package/src/setup-core.ts +162 -0
- package/src/setup-surface.ts +319 -0
- package/src/sso-token-store.ts +166 -0
- package/src/sso.ts +300 -0
- package/src/storage.ts +25 -0
- package/src/store-fs.ts +42 -0
- package/src/streaming-message.ts +327 -0
- package/src/thread-parent-context.ts +159 -0
- package/src/token-response.ts +11 -0
- package/src/token.ts +194 -0
- package/src/user-agent.ts +53 -0
- package/src/webhook-timeouts.ts +27 -0
- package/src/welcome-card.ts +57 -0
- package/test-api.ts +1 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { getMSTeamsRuntime } from "./runtime.js";
|
|
3
|
+
|
|
4
|
+
let cachedUserAgent: string | undefined;
|
|
5
|
+
|
|
6
|
+
function resolveTeamsSdkVersion(): string {
|
|
7
|
+
try {
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const pkg = require("@microsoft/teams.apps/package.json") as { version?: string };
|
|
10
|
+
return pkg.version ?? "unknown";
|
|
11
|
+
} catch {
|
|
12
|
+
return "unknown";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function resolveAutoBotVersion(): string {
|
|
17
|
+
try {
|
|
18
|
+
return getMSTeamsRuntime().version;
|
|
19
|
+
} catch {
|
|
20
|
+
return "unknown";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build a combined User-Agent string that preserves the Teams SDK identity
|
|
26
|
+
* and appends the AutoBot version.
|
|
27
|
+
*
|
|
28
|
+
* Format: "teams.ts[apps]/<sdk-version> AutoBot/<autobot-version>"
|
|
29
|
+
* Example: "teams.ts[apps]/2.0.5 AutoBot/2026.3.22"
|
|
30
|
+
*
|
|
31
|
+
* This lets the Teams backend track SDK usage while also identifying the
|
|
32
|
+
* host application.
|
|
33
|
+
*/
|
|
34
|
+
/** Reset the cached User-Agent (for testing). */
|
|
35
|
+
export function resetUserAgentCache(): void {
|
|
36
|
+
cachedUserAgent = undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function buildUserAgent(): string {
|
|
40
|
+
if (cachedUserAgent) {
|
|
41
|
+
return cachedUserAgent;
|
|
42
|
+
}
|
|
43
|
+
cachedUserAgent = `teams.ts[apps]/${resolveTeamsSdkVersion()} AutoBot/${resolveAutoBotVersion()}`;
|
|
44
|
+
return cachedUserAgent;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function ensureUserAgentHeader(headers?: HeadersInit): Headers {
|
|
48
|
+
const nextHeaders = new Headers(headers);
|
|
49
|
+
if (!nextHeaders.has("User-Agent")) {
|
|
50
|
+
nextHeaders.set("User-Agent", buildUserAgent());
|
|
51
|
+
}
|
|
52
|
+
return nextHeaders;
|
|
53
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Server } from "node:http";
|
|
2
|
+
|
|
3
|
+
const MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS = 30_000;
|
|
4
|
+
const MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS = 30_000;
|
|
5
|
+
const MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS = 15_000;
|
|
6
|
+
|
|
7
|
+
type ApplyMSTeamsWebhookTimeoutsOpts = {
|
|
8
|
+
inactivityTimeoutMs?: number;
|
|
9
|
+
requestTimeoutMs?: number;
|
|
10
|
+
headersTimeoutMs?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function applyMSTeamsWebhookTimeouts(
|
|
14
|
+
httpServer: Server,
|
|
15
|
+
opts?: ApplyMSTeamsWebhookTimeoutsOpts,
|
|
16
|
+
): void {
|
|
17
|
+
const inactivityTimeoutMs = opts?.inactivityTimeoutMs ?? MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS;
|
|
18
|
+
const requestTimeoutMs = opts?.requestTimeoutMs ?? MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS;
|
|
19
|
+
const headersTimeoutMs = Math.min(
|
|
20
|
+
opts?.headersTimeoutMs ?? MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS,
|
|
21
|
+
requestTimeoutMs,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
httpServer.setTimeout(inactivityTimeoutMs);
|
|
25
|
+
httpServer.requestTimeout = requestTimeoutMs;
|
|
26
|
+
httpServer.headersTimeout = headersTimeoutMs;
|
|
27
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an Adaptive Card for welcoming users when the bot is added to a conversation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const DEFAULT_PROMPT_STARTERS = [
|
|
6
|
+
"What can you do?",
|
|
7
|
+
"Summarize my last meeting",
|
|
8
|
+
"Help me draft an email",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
type WelcomeCardOptions = {
|
|
12
|
+
/** Bot display name. Falls back to "AutoBot". */
|
|
13
|
+
botName?: string;
|
|
14
|
+
/** Custom prompt starters. Falls back to defaults. */
|
|
15
|
+
promptStarters?: string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Build a welcome Adaptive Card for 1:1 personal chats.
|
|
20
|
+
*/
|
|
21
|
+
export function buildWelcomeCard(options?: WelcomeCardOptions): Record<string, unknown> {
|
|
22
|
+
const botName = options?.botName || "AutoBot";
|
|
23
|
+
const starters = options?.promptStarters?.length
|
|
24
|
+
? options.promptStarters
|
|
25
|
+
: DEFAULT_PROMPT_STARTERS;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
type: "AdaptiveCard",
|
|
29
|
+
version: "1.5",
|
|
30
|
+
body: [
|
|
31
|
+
{
|
|
32
|
+
type: "TextBlock",
|
|
33
|
+
text: `Hi! I'm ${botName}.`,
|
|
34
|
+
weight: "bolder",
|
|
35
|
+
size: "medium",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "TextBlock",
|
|
39
|
+
text: "I can help you with questions, tasks, and more. Here are some things to try:",
|
|
40
|
+
wrap: true,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
actions: starters.map((label) => ({
|
|
44
|
+
type: "Action.Submit",
|
|
45
|
+
title: label,
|
|
46
|
+
data: { msteams: { type: "imBack", value: label } },
|
|
47
|
+
})),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Build a brief welcome message for group chats (when the bot is @mentioned).
|
|
53
|
+
*/
|
|
54
|
+
export function buildGroupWelcomeText(botName?: string): string {
|
|
55
|
+
const name = botName || "AutoBot";
|
|
56
|
+
return `Hi! I'm ${name}. Mention me with @${name} to get started.`;
|
|
57
|
+
}
|
package/test-api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { msteamsPlugin } from "./src/channel.js";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.package-boundary.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "."
|
|
5
|
+
},
|
|
6
|
+
"include": ["./*.ts", "./src/**/*.ts"],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"./**/*.test.ts",
|
|
9
|
+
"./dist/**",
|
|
10
|
+
"./node_modules/**",
|
|
11
|
+
"./src/test-support/**",
|
|
12
|
+
"./src/**/*test-helpers.ts",
|
|
13
|
+
"./src/**/*test-harness.ts",
|
|
14
|
+
"./src/**/*test-support.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|