@microsoft/agents-hosting-extensions-msteams 1.7.0-beta.10.g0c6864b626

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.
Files changed (143) hide show
  1. package/README.md +147 -0
  2. package/dist/package.json +46 -0
  3. package/dist/src/activity-extensions/index.d.ts +1 -0
  4. package/dist/src/activity-extensions/index.js +8 -0
  5. package/dist/src/activity-extensions/index.js.map +1 -0
  6. package/dist/src/activity-extensions/teamsChannelData.d.ts +12 -0
  7. package/dist/src/activity-extensions/teamsChannelData.js +29 -0
  8. package/dist/src/activity-extensions/teamsChannelData.js.map +1 -0
  9. package/dist/src/app/index.d.ts +1 -0
  10. package/dist/src/app/index.js +20 -0
  11. package/dist/src/app/index.js.map +1 -0
  12. package/dist/src/app/teamsAppExtensions.d.ts +145 -0
  13. package/dist/src/app/teamsAppExtensions.js +201 -0
  14. package/dist/src/app/teamsAppExtensions.js.map +1 -0
  15. package/dist/src/channels/index.d.ts +1 -0
  16. package/dist/src/channels/index.js +20 -0
  17. package/dist/src/channels/index.js.map +1 -0
  18. package/dist/src/channels/teamsChannel.d.ts +100 -0
  19. package/dist/src/channels/teamsChannel.js +210 -0
  20. package/dist/src/channels/teamsChannel.js.map +1 -0
  21. package/dist/src/config/config.d.ts +37 -0
  22. package/dist/src/config/config.js +71 -0
  23. package/dist/src/config/config.js.map +1 -0
  24. package/dist/src/config/index.d.ts +1 -0
  25. package/dist/src/config/index.js +20 -0
  26. package/dist/src/config/index.js.map +1 -0
  27. package/dist/src/errorHelper.d.ts +19 -0
  28. package/dist/src/errorHelper.js +96 -0
  29. package/dist/src/errorHelper.js.map +1 -0
  30. package/dist/src/fileConsents/fileConsent.d.ts +37 -0
  31. package/dist/src/fileConsents/fileConsent.js +79 -0
  32. package/dist/src/fileConsents/fileConsent.js.map +1 -0
  33. package/dist/src/fileConsents/index.d.ts +1 -0
  34. package/dist/src/fileConsents/index.js +20 -0
  35. package/dist/src/fileConsents/index.js.map +1 -0
  36. package/dist/src/graphClientFactory.d.ts +10 -0
  37. package/dist/src/graphClientFactory.js +98 -0
  38. package/dist/src/graphClientFactory.js.map +1 -0
  39. package/dist/src/index.d.ts +20 -0
  40. package/dist/src/index.js +39 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/src/meetings/index.d.ts +1 -0
  43. package/dist/src/meetings/index.js +20 -0
  44. package/dist/src/meetings/index.js.map +1 -0
  45. package/dist/src/meetings/meeting.d.ts +84 -0
  46. package/dist/src/meetings/meeting.js +107 -0
  47. package/dist/src/meetings/meeting.js.map +1 -0
  48. package/dist/src/messageExtensions/index.d.ts +2 -0
  49. package/dist/src/messageExtensions/index.js +24 -0
  50. package/dist/src/messageExtensions/index.js.map +1 -0
  51. package/dist/src/messageExtensions/messageExtension.d.ts +133 -0
  52. package/dist/src/messageExtensions/messageExtension.js +326 -0
  53. package/dist/src/messageExtensions/messageExtension.js.map +1 -0
  54. package/dist/src/messageExtensions/messagingExtensionQuery.d.ts +87 -0
  55. package/dist/src/messageExtensions/messagingExtensionQuery.js +35 -0
  56. package/dist/src/messageExtensions/messagingExtensionQuery.js.map +1 -0
  57. package/dist/src/messages/index.d.ts +1 -0
  58. package/dist/src/messages/index.js +20 -0
  59. package/dist/src/messages/index.js.map +1 -0
  60. package/dist/src/messages/message.d.ts +67 -0
  61. package/dist/src/messages/message.js +129 -0
  62. package/dist/src/messages/message.js.map +1 -0
  63. package/dist/src/models/index.d.ts +1 -0
  64. package/dist/src/models/index.js +20 -0
  65. package/dist/src/models/index.js.map +1 -0
  66. package/dist/src/models/readReceiptInfo.d.ts +27 -0
  67. package/dist/src/models/readReceiptInfo.js +44 -0
  68. package/dist/src/models/readReceiptInfo.js.map +1 -0
  69. package/dist/src/taskModules/index.d.ts +1 -0
  70. package/dist/src/taskModules/index.js +20 -0
  71. package/dist/src/taskModules/index.js.map +1 -0
  72. package/dist/src/taskModules/taskModule.d.ts +42 -0
  73. package/dist/src/taskModules/taskModule.js +102 -0
  74. package/dist/src/taskModules/taskModule.js.map +1 -0
  75. package/dist/src/teams/index.d.ts +1 -0
  76. package/dist/src/teams/index.js +20 -0
  77. package/dist/src/teams/index.js.map +1 -0
  78. package/dist/src/teams/teamsTeam.d.ts +82 -0
  79. package/dist/src/teams/teamsTeam.js +172 -0
  80. package/dist/src/teams/teamsTeam.js.map +1 -0
  81. package/dist/src/teamsActivity.d.ts +15 -0
  82. package/dist/src/teamsActivity.js +5 -0
  83. package/dist/src/teamsActivity.js.map +1 -0
  84. package/dist/src/teamsActivityExtensions.d.ts +53 -0
  85. package/dist/src/teamsActivityExtensions.js +101 -0
  86. package/dist/src/teamsActivityExtensions.js.map +1 -0
  87. package/dist/src/teamsAgentExtension.d.ts +105 -0
  88. package/dist/src/teamsAgentExtension.js +178 -0
  89. package/dist/src/teamsAgentExtension.js.map +1 -0
  90. package/dist/src/teamsApiClientExtensions.d.ts +13 -0
  91. package/dist/src/teamsApiClientExtensions.js +41 -0
  92. package/dist/src/teamsApiClientExtensions.js.map +1 -0
  93. package/dist/src/teamsHeaderPropagation.d.ts +14 -0
  94. package/dist/src/teamsHeaderPropagation.js +35 -0
  95. package/dist/src/teamsHeaderPropagation.js.map +1 -0
  96. package/dist/src/teamsModelExtensions.d.ts +19 -0
  97. package/dist/src/teamsModelExtensions.js +38 -0
  98. package/dist/src/teamsModelExtensions.js.map +1 -0
  99. package/dist/src/teamsProactiveServiceEndpoints.d.ts +15 -0
  100. package/dist/src/teamsProactiveServiceEndpoints.js +21 -0
  101. package/dist/src/teamsProactiveServiceEndpoints.js.map +1 -0
  102. package/dist/src/teamsRouteHandler.d.ts +13 -0
  103. package/dist/src/teamsRouteHandler.js +18 -0
  104. package/dist/src/teamsRouteHandler.js.map +1 -0
  105. package/dist/src/teamsTurnContext.d.ts +64 -0
  106. package/dist/src/teamsTurnContext.js +113 -0
  107. package/dist/src/teamsTurnContext.js.map +1 -0
  108. package/package.json +46 -0
  109. package/src/activity-extensions/index.ts +4 -0
  110. package/src/activity-extensions/teamsChannelData.ts +30 -0
  111. package/src/app/index.ts +4 -0
  112. package/src/app/teamsAppExtensions.ts +369 -0
  113. package/src/channels/index.ts +4 -0
  114. package/src/channels/teamsChannel.ts +229 -0
  115. package/src/config/config.ts +79 -0
  116. package/src/config/index.ts +4 -0
  117. package/src/errorHelper.ts +104 -0
  118. package/src/fileConsents/fileConsent.ts +85 -0
  119. package/src/fileConsents/index.ts +4 -0
  120. package/src/graphClientFactory.ts +127 -0
  121. package/src/index.ts +23 -0
  122. package/src/meetings/index.ts +4 -0
  123. package/src/meetings/meeting.ts +146 -0
  124. package/src/messageExtensions/index.ts +5 -0
  125. package/src/messageExtensions/messageExtension.ts +370 -0
  126. package/src/messageExtensions/messagingExtensionQuery.ts +34 -0
  127. package/src/messages/index.ts +4 -0
  128. package/src/messages/message.ts +148 -0
  129. package/src/models/index.ts +4 -0
  130. package/src/models/readReceiptInfo.ts +50 -0
  131. package/src/taskModules/index.ts +4 -0
  132. package/src/taskModules/taskModule.ts +113 -0
  133. package/src/teams/index.ts +4 -0
  134. package/src/teams/teamsTeam.ts +189 -0
  135. package/src/teamsActivity.ts +19 -0
  136. package/src/teamsActivityExtensions.ts +99 -0
  137. package/src/teamsAgentExtension.ts +205 -0
  138. package/src/teamsApiClientExtensions.ts +47 -0
  139. package/src/teamsHeaderPropagation.ts +32 -0
  140. package/src/teamsModelExtensions.ts +42 -0
  141. package/src/teamsProactiveServiceEndpoints.ts +18 -0
  142. package/src/teamsRouteHandler.ts +22 -0
  143. package/src/teamsTurnContext.ts +125 -0
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import type { HeaderPropagationCollection } from '@microsoft/agents-hosting'
5
+ import { version } from '../package.json'
6
+
7
+ const USER_AGENT_HEADER = 'User-Agent'
8
+ /**
9
+ * Product token appended to outbound User-Agent headers by the Teams extension.
10
+ */
11
+ export const TEAMS_USER_AGENT_PRODUCT = `agents-sdk-js-teams/${version}`
12
+
13
+ /**
14
+ * Applies Teams-specific header propagation to an outbound header collection.
15
+ *
16
+ * The current implementation appends the Teams SDK product token to `User-Agent`, preserving
17
+ * any existing incoming or outgoing User-Agent value.
18
+ *
19
+ * @param headers - Header propagation collection for the current request.
20
+ */
21
+ export function applyTeamsHeaderPropagation (headers: HeaderPropagationCollection): void {
22
+ const userAgentKey = headers.key?.(USER_AGENT_HEADER) ?? USER_AGENT_HEADER
23
+ const userAgent = headers.outgoing[userAgentKey] ?? headers.incoming[userAgentKey]
24
+
25
+ if (!userAgent) {
26
+ headers.add({ [userAgentKey]: TEAMS_USER_AGENT_PRODUCT })
27
+ } else if (!userAgent.includes(TEAMS_USER_AGENT_PRODUCT)) {
28
+ headers.concat({ [userAgentKey]: TEAMS_USER_AGENT_PRODUCT })
29
+ } else if (!headers.outgoing[userAgentKey]) {
30
+ headers.propagate([userAgentKey])
31
+ }
32
+ }
@@ -0,0 +1,42 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import type { MessagingExtensionAction, TaskModuleRequest } from '@microsoft/teams.api'
5
+
6
+ type TeamsDataContainer = Pick<TaskModuleRequest, 'data'> | Pick<MessagingExtensionAction, 'data'> | null | undefined
7
+
8
+ function hasDataProperty (value: unknown): value is { data?: unknown } {
9
+ return typeof value === 'object' && value !== null && Object.prototype.hasOwnProperty.call(value, 'data')
10
+ }
11
+
12
+ function getSourceData (source: TeamsDataContainer | unknown): unknown {
13
+ return hasDataProperty(source) ? source.data : source
14
+ }
15
+
16
+ /**
17
+ * Gets the data payload from a Teams task module request or message extension action as the specified type.
18
+ *
19
+ * @param request - Teams request or action that contains a `data` payload.
20
+ * @returns The data payload cast to the requested type, or undefined when no data is present.
21
+ */
22
+ export function teamsGetDataAs<T = unknown> (request: TeamsDataContainer): T | undefined {
23
+ return request?.data == null ? undefined : request.data as T
24
+ }
25
+
26
+ /**
27
+ * Gets a string property from a Teams task module request, message extension action, or raw data object.
28
+ *
29
+ * @param source - Teams request, Teams action, or raw data object to inspect.
30
+ * @param key - Property name to read from the data object.
31
+ * @param defaultValue - Value returned when the property is missing or is not a string.
32
+ * @returns The string property value, the default value, or an empty string.
33
+ */
34
+ export function teamsGetDataString (source: TeamsDataContainer | unknown, key: string, defaultValue?: string): string {
35
+ const data = getSourceData(source)
36
+ if (typeof data !== 'object' || data === null || Array.isArray(data)) {
37
+ return defaultValue ?? ''
38
+ }
39
+
40
+ const value = (data as Record<string, unknown>)[key]
41
+ return typeof value === 'string' ? value : defaultValue ?? ''
42
+ }
@@ -0,0 +1,18 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ /**
5
+ * Well-known service endpoint URLs for sending proactive messages to Microsoft Teams.
6
+ * Use these only if the incoming request serviceUrl is unavailable; once a serviceUrl
7
+ * has been returned from a prior conversation, cache and use that value instead.
8
+ */
9
+ export const TeamsProactiveServiceEndpoints = {
10
+ /** Service endpoint for the public global Teams environment. */
11
+ publicGlobal: 'https://smba.trafficmanager.net/teams/',
12
+ /** Service endpoint for the GCC (Government Community Cloud) Teams environment. */
13
+ gcc: 'https://smba.infra.gcc.teams.microsoft.com/teams',
14
+ /** Service endpoint for the GCC High Teams environment. */
15
+ gccHigh: 'https://smba.infra.gov.teams.microsoft.us/teams',
16
+ /** Service endpoint for the DoD (Department of Defense) Teams environment. */
17
+ dod: 'https://smba.infra.dod.teams.microsoft.us/teams'
18
+ } as const
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { RouteHandler, TurnContext, TurnState } from '@microsoft/agents-hosting'
5
+ import { TeamsTurnContext } from './teamsTurnContext'
6
+
7
+ /**
8
+ * Route handler that receives a Teams-specific turn context.
9
+ */
10
+ export type TeamsRouteHandler<TState extends TurnState> = (context: TeamsTurnContext, state: TState) => Promise<void>
11
+
12
+ /**
13
+ * Wraps a Teams route handler so it can be registered with an agent application route.
14
+ *
15
+ * @param handler - Handler that expects a Teams turn context.
16
+ * @returns A route handler that creates a Teams turn context for the current turn.
17
+ */
18
+ export function createTeamsRouteHandler<TState extends TurnState> (handler: TeamsRouteHandler<TState>): RouteHandler<TState> {
19
+ return async (context: TurnContext, state: TState) => {
20
+ await handler(new TeamsTurnContext(context), state)
21
+ }
22
+ }
@@ -0,0 +1,125 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { Activity, ExceptionHelper } from '@microsoft/agents-activity'
5
+ import { Client as GraphClient } from '@microsoft/microsoft-graph-client'
6
+ import { AgentApplication, type Authorization, type Connections, ResourceResponse, TurnContext } from '@microsoft/agents-hosting'
7
+ import { Client as TeamsClient } from '@microsoft/teams.api'
8
+ import { Errors } from './errorHelper'
9
+ import type { TeamsActivity } from './teamsActivity'
10
+ import { TeamsClientKey } from './teamsApiClientExtensions'
11
+ import { createAppGraphClient, createUserGraphClient } from './graphClientFactory'
12
+
13
+ const DEFAULT_GRAPH_BASE_URL = 'https://graph.microsoft.com/v1.0'
14
+
15
+ /**
16
+ * Turn context wrapper that exposes Teams-specific helpers for a Teams activity turn.
17
+ */
18
+ export class TeamsTurnContext extends TurnContext {
19
+ /**
20
+ * Gets the incoming activity with strongly typed Teams channel data.
21
+ *
22
+ * @remarks
23
+ * The returned object is the original turn activity. This getter only narrows
24
+ * its TypeScript type and does not convert or clone the activity.
25
+ */
26
+ override get activity (): TeamsActivity {
27
+ return super.activity as TeamsActivity
28
+ }
29
+
30
+ /**
31
+ * Gets the Teams API client for the current turn.
32
+ *
33
+ * @returns The Teams API client configured for the activity's service URL.
34
+ * @throws If the Teams API client is not available in turn state.
35
+ */
36
+ get client (): TeamsClient {
37
+ const teamsClient = this.turnState.get<TeamsClient>(TeamsClientKey)
38
+ if (!teamsClient) {
39
+ throw ExceptionHelper.generateException(Error, Errors.TeamsApiClientNotAvailable)
40
+ }
41
+ return teamsClient
42
+ }
43
+
44
+ /**
45
+ * Sends a cloned copy of an activity as a Teams targeted activity.
46
+ *
47
+ * @param activity - The activity to send to the targeted recipient.
48
+ * @returns The resource response for the sent activity, if provided by the adapter.
49
+ */
50
+ async sendTargetedActivity (activity: Activity): Promise<ResourceResponse | undefined> {
51
+ const targetedActivity = Activity.fromObject(activity)
52
+ targetedActivity.makeTargetedActivity()
53
+ return await this.sendActivity(targetedActivity)
54
+ }
55
+
56
+ /**
57
+ * Sends cloned copies of activities as Teams targeted activities.
58
+ *
59
+ * @param activities - The activities to send to targeted recipients.
60
+ * @returns Resource responses for the sent activities.
61
+ */
62
+ async sendTargetedActivities (activities: Activity[]): Promise<ResourceResponse[]> {
63
+ const targetedActivities = activities.map((activity) => {
64
+ const targetedActivity = Activity.fromObject(activity)
65
+ targetedActivity.makeTargetedActivity()
66
+ return targetedActivity
67
+ })
68
+ return await this.sendActivities(targetedActivities)
69
+ }
70
+
71
+ /**
72
+ * Creates a Microsoft Graph client authenticated with a delegated token for the current user.
73
+ *
74
+ * @param handlerName - Optional authorization handler name. Required when multiple handlers are configured.
75
+ * @param graphBaseUrl - Optional Graph base URL. Defaults to Microsoft Graph v1.0.
76
+ * @returns A Microsoft Graph client configured with delegated permissions.
77
+ */
78
+ getGraphClient (handlerName?: string, graphBaseUrl: string = DEFAULT_GRAPH_BASE_URL): GraphClient {
79
+ return createUserGraphClient(this.getUserAuthorization(), this, handlerName, graphBaseUrl)
80
+ }
81
+
82
+ /**
83
+ * Creates a Microsoft Graph client authenticated with an app-only token from the current turn's connection.
84
+ *
85
+ * @param graphBaseUrl - Optional Graph base URL. Defaults to Microsoft Graph v1.0.
86
+ * @returns A Microsoft Graph client configured with application permissions.
87
+ */
88
+ getAppGraphClient (graphBaseUrl: string = DEFAULT_GRAPH_BASE_URL): GraphClient {
89
+ const tokenProvider = this.getConnections().getTokenProviderFromActivity(this.identity, this.activity)
90
+ return createAppGraphClient(tokenProvider, graphBaseUrl)
91
+ }
92
+
93
+ /**
94
+ * Creates a Microsoft Graph client authenticated with an app-only token from a named connection.
95
+ *
96
+ * @param connectionName - The configured token connection name.
97
+ * @param graphBaseUrl - Optional Graph base URL. Defaults to Microsoft Graph v1.0.
98
+ * @returns A Microsoft Graph client configured with application permissions.
99
+ */
100
+ getAppGraphClientForConnection (connectionName: string, graphBaseUrl: string = DEFAULT_GRAPH_BASE_URL): GraphClient {
101
+ if (!connectionName) {
102
+ throw ExceptionHelper.generateException(Error, Errors.TeamsGraphParameterRequired, undefined, { parameterName: 'connectionName' })
103
+ }
104
+
105
+ return createAppGraphClient(this.getConnections().getConnection(connectionName), graphBaseUrl)
106
+ }
107
+
108
+ private getUserAuthorization (): Authorization {
109
+ const authorization = this.turnState.get<Authorization>(AgentApplication.UserAuthorizationKey)
110
+ if (!authorization) {
111
+ throw ExceptionHelper.generateException(Error, Errors.TeamsGraphUserAuthorizationNotConfigured)
112
+ }
113
+
114
+ return authorization
115
+ }
116
+
117
+ private getConnections (): Connections {
118
+ const connections = this.turnState.get<Connections>(AgentApplication.ConnectionsKey)
119
+ if (!connections) {
120
+ throw ExceptionHelper.generateException(Error, Errors.TeamsGraphConnectionsNotConfigured)
121
+ }
122
+
123
+ return connections
124
+ }
125
+ }