@chat-adapter/teams 4.16.1 → 4.17.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/dist/index.d.ts +30 -10
- package/dist/index.js +105 -40
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -76,17 +76,37 @@ declare class TeamsFormatConverter extends BaseFormatConverter {
|
|
|
76
76
|
private tableToGfm;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** Certificate-based authentication config */
|
|
80
|
+
interface TeamsAuthCertificate {
|
|
81
|
+
/** PEM-encoded certificate private key */
|
|
82
|
+
certificatePrivateKey: string;
|
|
83
|
+
/** Hex-encoded certificate thumbprint (optional when x5c is provided) */
|
|
84
|
+
certificateThumbprint?: string;
|
|
85
|
+
/** Public certificate for subject-name validation (optional) */
|
|
86
|
+
x5c?: string;
|
|
87
|
+
}
|
|
88
|
+
/** Federated (workload identity) authentication config */
|
|
89
|
+
interface TeamsAuthFederated {
|
|
90
|
+
/** Audience for the federated credential (defaults to api://AzureADTokenExchange) */
|
|
91
|
+
clientAudience?: string;
|
|
92
|
+
/** Client ID for the managed identity assigned to the bot */
|
|
93
|
+
clientId: string;
|
|
94
|
+
}
|
|
79
95
|
interface TeamsAdapterConfig {
|
|
80
|
-
/** Microsoft App ID */
|
|
81
|
-
appId
|
|
82
|
-
/** Microsoft App Password */
|
|
83
|
-
appPassword
|
|
84
|
-
/** Microsoft App Tenant ID */
|
|
96
|
+
/** Microsoft App ID. Defaults to TEAMS_APP_ID env var. */
|
|
97
|
+
appId?: string;
|
|
98
|
+
/** Microsoft App Password. Defaults to TEAMS_APP_PASSWORD env var. */
|
|
99
|
+
appPassword?: string;
|
|
100
|
+
/** Microsoft App Tenant ID. Defaults to TEAMS_APP_TENANT_ID env var. */
|
|
85
101
|
appTenantId?: string;
|
|
86
102
|
/** Microsoft App Type */
|
|
87
103
|
appType?: "MultiTenant" | "SingleTenant";
|
|
88
|
-
/**
|
|
89
|
-
|
|
104
|
+
/** Certificate-based authentication */
|
|
105
|
+
certificate?: TeamsAuthCertificate;
|
|
106
|
+
/** Federated (workload identity) authentication */
|
|
107
|
+
federated?: TeamsAuthFederated;
|
|
108
|
+
/** Logger instance for error reporting. Defaults to ConsoleLogger. */
|
|
109
|
+
logger?: Logger;
|
|
90
110
|
/** Override bot username (optional) */
|
|
91
111
|
userName?: string;
|
|
92
112
|
}
|
|
@@ -106,7 +126,7 @@ declare class TeamsAdapter implements Adapter<TeamsThreadId, unknown> {
|
|
|
106
126
|
private readonly logger;
|
|
107
127
|
private readonly formatConverter;
|
|
108
128
|
private readonly config;
|
|
109
|
-
constructor(config
|
|
129
|
+
constructor(config?: TeamsAdapterConfig);
|
|
110
130
|
initialize(chat: ChatInstance): Promise<void>;
|
|
111
131
|
handleWebhook(request: Request, options?: WebhookOptions): Promise<Response>;
|
|
112
132
|
private handleTurn;
|
|
@@ -225,6 +245,6 @@ declare class TeamsAdapter implements Adapter<TeamsThreadId, unknown> {
|
|
|
225
245
|
*/
|
|
226
246
|
private handleTeamsError;
|
|
227
247
|
}
|
|
228
|
-
declare function createTeamsAdapter(config?:
|
|
248
|
+
declare function createTeamsAdapter(config?: TeamsAdapterConfig): TeamsAdapter;
|
|
229
249
|
|
|
230
|
-
export { TeamsAdapter, type TeamsAdapterConfig, TeamsFormatConverter, type TeamsThreadId, cardToAdaptiveCard, cardToFallbackText, createTeamsAdapter };
|
|
250
|
+
export { TeamsAdapter, type TeamsAdapterConfig, type TeamsAuthCertificate, type TeamsAuthFederated, TeamsFormatConverter, type TeamsThreadId, cardToAdaptiveCard, cardToFallbackText, createTeamsAdapter };
|
package/dist/index.js
CHANGED
|
@@ -671,7 +671,11 @@ var require_azureTokenCredentials = __commonJS({
|
|
|
671
671
|
});
|
|
672
672
|
|
|
673
673
|
// src/index.ts
|
|
674
|
-
import {
|
|
674
|
+
import {
|
|
675
|
+
ClientCertificateCredential,
|
|
676
|
+
ClientSecretCredential,
|
|
677
|
+
DefaultAzureCredential
|
|
678
|
+
} from "@azure/identity";
|
|
675
679
|
|
|
676
680
|
// ../../node_modules/.pnpm/@microsoft+microsoft-graph-client@3.0.7_@azure+identity@4.13.0/node_modules/@microsoft/microsoft-graph-client/lib/es/src/content/BatchRequestContent.js
|
|
677
681
|
init_tslib_es6();
|
|
@@ -3563,6 +3567,10 @@ import {
|
|
|
3563
3567
|
ConfigurationBotFrameworkAuthentication,
|
|
3564
3568
|
TeamsInfo
|
|
3565
3569
|
} from "botbuilder";
|
|
3570
|
+
import {
|
|
3571
|
+
CertificateServiceClientCredentialsFactory,
|
|
3572
|
+
FederatedServiceClientCredentialsFactory
|
|
3573
|
+
} from "botframework-connector";
|
|
3566
3574
|
import {
|
|
3567
3575
|
AdapterRateLimitError,
|
|
3568
3576
|
AuthenticationError,
|
|
@@ -3981,31 +3989,110 @@ var TeamsAdapter = class {
|
|
|
3981
3989
|
logger;
|
|
3982
3990
|
formatConverter = new TeamsFormatConverter();
|
|
3983
3991
|
config;
|
|
3984
|
-
constructor(config) {
|
|
3985
|
-
|
|
3986
|
-
|
|
3992
|
+
constructor(config = {}) {
|
|
3993
|
+
const appId = config.appId ?? process.env.TEAMS_APP_ID;
|
|
3994
|
+
if (!appId) {
|
|
3995
|
+
throw new ValidationError(
|
|
3996
|
+
"teams",
|
|
3997
|
+
"appId is required. Set TEAMS_APP_ID or provide it in config."
|
|
3998
|
+
);
|
|
3999
|
+
}
|
|
4000
|
+
const hasExplicitAuth = config.appPassword || config.certificate || config.federated;
|
|
4001
|
+
const appPassword = hasExplicitAuth ? config.appPassword : config.appPassword ?? process.env.TEAMS_APP_PASSWORD;
|
|
4002
|
+
const appTenantId = config.appTenantId ?? process.env.TEAMS_APP_TENANT_ID;
|
|
4003
|
+
this.config = {
|
|
4004
|
+
...config,
|
|
4005
|
+
appId,
|
|
4006
|
+
appPassword,
|
|
4007
|
+
appTenantId
|
|
4008
|
+
};
|
|
4009
|
+
this.logger = config.logger ?? new ConsoleLogger("info").child("teams");
|
|
3987
4010
|
this.userName = config.userName || "bot";
|
|
3988
|
-
|
|
4011
|
+
const authMethodCount = [
|
|
4012
|
+
appPassword,
|
|
4013
|
+
config.certificate,
|
|
4014
|
+
config.federated
|
|
4015
|
+
].filter(Boolean).length;
|
|
4016
|
+
if (authMethodCount === 0) {
|
|
4017
|
+
throw new ValidationError(
|
|
4018
|
+
"teams",
|
|
4019
|
+
"One of appPassword, certificate, or federated must be provided"
|
|
4020
|
+
);
|
|
4021
|
+
}
|
|
4022
|
+
if (authMethodCount > 1) {
|
|
4023
|
+
throw new ValidationError(
|
|
4024
|
+
"teams",
|
|
4025
|
+
"Only one of appPassword, certificate, or federated can be provided"
|
|
4026
|
+
);
|
|
4027
|
+
}
|
|
4028
|
+
if (config.appType === "SingleTenant" && !appTenantId) {
|
|
3989
4029
|
throw new ValidationError(
|
|
3990
4030
|
"teams",
|
|
3991
4031
|
"appTenantId is required for SingleTenant app type"
|
|
3992
4032
|
);
|
|
3993
4033
|
}
|
|
3994
|
-
const
|
|
3995
|
-
MicrosoftAppId:
|
|
3996
|
-
MicrosoftAppPassword: config.appPassword,
|
|
4034
|
+
const botFrameworkConfig = {
|
|
4035
|
+
MicrosoftAppId: appId,
|
|
3997
4036
|
MicrosoftAppType: config.appType || "MultiTenant",
|
|
3998
|
-
MicrosoftAppTenantId: config.appType === "SingleTenant" ?
|
|
3999
|
-
}
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4037
|
+
MicrosoftAppTenantId: config.appType === "SingleTenant" ? appTenantId : void 0
|
|
4038
|
+
};
|
|
4039
|
+
let credentialsFactory;
|
|
4040
|
+
let graphCredential;
|
|
4041
|
+
if (config.certificate) {
|
|
4042
|
+
const { certificatePrivateKey, certificateThumbprint, x5c } = config.certificate;
|
|
4043
|
+
if (x5c) {
|
|
4044
|
+
credentialsFactory = new CertificateServiceClientCredentialsFactory(
|
|
4045
|
+
appId,
|
|
4046
|
+
x5c,
|
|
4047
|
+
certificatePrivateKey,
|
|
4048
|
+
appTenantId
|
|
4049
|
+
);
|
|
4050
|
+
} else if (certificateThumbprint) {
|
|
4051
|
+
credentialsFactory = new CertificateServiceClientCredentialsFactory(
|
|
4052
|
+
appId,
|
|
4053
|
+
certificateThumbprint,
|
|
4054
|
+
certificatePrivateKey,
|
|
4055
|
+
appTenantId
|
|
4056
|
+
);
|
|
4057
|
+
} else {
|
|
4058
|
+
throw new ValidationError(
|
|
4059
|
+
"teams",
|
|
4060
|
+
"Certificate auth requires either certificateThumbprint or x5c"
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
if (appTenantId) {
|
|
4064
|
+
graphCredential = new ClientCertificateCredential(appTenantId, appId, {
|
|
4065
|
+
certificate: certificatePrivateKey
|
|
4066
|
+
});
|
|
4067
|
+
}
|
|
4068
|
+
} else if (config.federated) {
|
|
4069
|
+
credentialsFactory = new FederatedServiceClientCredentialsFactory(
|
|
4070
|
+
appId,
|
|
4071
|
+
config.federated.clientId,
|
|
4072
|
+
appTenantId,
|
|
4073
|
+
config.federated.clientAudience
|
|
4074
|
+
);
|
|
4075
|
+
if (appTenantId) {
|
|
4076
|
+
graphCredential = new DefaultAzureCredential();
|
|
4077
|
+
}
|
|
4078
|
+
} else if (appPassword && appTenantId) {
|
|
4079
|
+
graphCredential = new ClientSecretCredential(
|
|
4080
|
+
appTenantId,
|
|
4081
|
+
appId,
|
|
4082
|
+
appPassword
|
|
4006
4083
|
);
|
|
4084
|
+
}
|
|
4085
|
+
const auth = new ConfigurationBotFrameworkAuthentication(
|
|
4086
|
+
{
|
|
4087
|
+
...botFrameworkConfig,
|
|
4088
|
+
...appPassword ? { MicrosoftAppPassword: appPassword } : {}
|
|
4089
|
+
},
|
|
4090
|
+
credentialsFactory
|
|
4091
|
+
);
|
|
4092
|
+
this.botAdapter = new ServerlessCloudAdapter(auth);
|
|
4093
|
+
if (graphCredential) {
|
|
4007
4094
|
const authProvider = new import_azureTokenCredentials.TokenCredentialAuthenticationProvider(
|
|
4008
|
-
|
|
4095
|
+
graphCredential,
|
|
4009
4096
|
{
|
|
4010
4097
|
scopes: ["https://graph.microsoft.com/.default"]
|
|
4011
4098
|
}
|
|
@@ -5589,29 +5676,7 @@ var TeamsAdapter = class {
|
|
|
5589
5676
|
}
|
|
5590
5677
|
};
|
|
5591
5678
|
function createTeamsAdapter(config) {
|
|
5592
|
-
|
|
5593
|
-
if (!appId) {
|
|
5594
|
-
throw new ValidationError(
|
|
5595
|
-
"teams",
|
|
5596
|
-
"appId is required. Set TEAMS_APP_ID or provide it in config."
|
|
5597
|
-
);
|
|
5598
|
-
}
|
|
5599
|
-
const appPassword = config?.appPassword ?? process.env.TEAMS_APP_PASSWORD;
|
|
5600
|
-
if (!appPassword) {
|
|
5601
|
-
throw new ValidationError(
|
|
5602
|
-
"teams",
|
|
5603
|
-
"appPassword is required. Set TEAMS_APP_PASSWORD or provide it in config."
|
|
5604
|
-
);
|
|
5605
|
-
}
|
|
5606
|
-
const resolved = {
|
|
5607
|
-
appId,
|
|
5608
|
-
appPassword,
|
|
5609
|
-
appTenantId: config?.appTenantId ?? process.env.TEAMS_APP_TENANT_ID,
|
|
5610
|
-
appType: config?.appType,
|
|
5611
|
-
logger: config?.logger ?? new ConsoleLogger("info").child("teams"),
|
|
5612
|
-
userName: config?.userName
|
|
5613
|
-
};
|
|
5614
|
-
return new TeamsAdapter(resolved);
|
|
5679
|
+
return new TeamsAdapter(config ?? {});
|
|
5615
5680
|
}
|
|
5616
5681
|
export {
|
|
5617
5682
|
TeamsAdapter,
|