UNPKG

@microsoft/agents-hosting-extensions-teams

Version:

Microsoft 365 Agents SDK for JavaScript. Teams extensions

313 lines 11.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TeamsConnectorClient = void 0; /** * A client for interacting with Microsoft Teams APIs. * Extends the ConnectorClient class to provide Teams-specific functionalities. */ class TeamsConnectorClient { constructor(client) { this.client = client; this.axiosInstance = client.axiosInstance; } /** * Retrieves a member from a conversation or team. * @param activity - The activity containing the context. * @param userId - The ID of the user to retrieve. * @returns A TeamsChannelAccount representing the member. */ static async getMember(activity, userId) { var _a; const teamsChannelData = activity.channelData; const teamId = (_a = teamsChannelData.team) === null || _a === void 0 ? void 0 : _a.id; if (teamId) { return await this.getTeamMember(activity, teamId, userId); } else { const conversationId = (activity.conversation != null) && activity.conversation.id ? activity.conversation.id : undefined; return await this.getMemberInternal(activity, conversationId, userId); } } /** * Retrieves the team ID from an activity. * @param activity - The activity containing the context. * @returns The team ID as a string. * @throws Error if the activity is missing or invalid. */ static getTeamId(activity) { if (!activity) { throw new Error('Missing activity parameter'); } const channelData = activity.channelData; const team = channelData && (channelData.team != null) ? channelData.team : undefined; const teamId = (team != null) && typeof team.id === 'string' ? team.id : undefined; return teamId; } /** * Retrieves a member from a team. * @param activity - The activity containing the context. * @param teamId - The ID of the team. * @param userId - The ID of the user to retrieve. * @returns A TeamsChannelAccount representing the team member. * @throws Error if the teamId or userId is missing. */ static async getTeamMember(activity, teamId, userId) { const t = teamId || this.getTeamId(activity); if (!t) { throw new Error('This method is only valid within the scope of a MS Teams Team.'); } if (!userId) { throw new Error('userId is required'); } return await this.getMemberInternal(activity, t, userId); } /** * Retrieves a member from a conversation. * @param conversationId - The ID of the conversation. * @param userId - The ID of the user to retrieve. * @returns A ChannelAccount representing the conversation member. */ async getConversationMember(conversationId, userId) { const config = { method: 'get', url: `/v3/conversations/${conversationId}/members/${userId}`, headers: { 'Content-Type': 'application/json' } }; const response = await this.axiosInstance(config); return response.data; } /** * Retrieves a member from a conversation or team internally. * @param activity - The activity containing the context. * @param conversationId - The ID of the conversation. * @param userId - The ID of the user to retrieve. * @returns A ChannelAccount representing the member. * @throws Error if the conversationId is missing or the client is unavailable. */ static async getMemberInternal(activity, conversationId, userId) { var _a; if (!conversationId) { throw new Error('conversationId is required'); } const client = (_a = activity.turnState) === null || _a === void 0 ? void 0 : _a.get(activity.adapter.ConnectorClientKey); if (!client) { throw new Error('Client is not available in the context.'); } const teamMember = await client.getConversationMember(conversationId, userId); return teamMember; } /** * Retrieves paged members of a conversation. * @param conversationId - The ID of the conversation. * @param pageSize - The number of members per page. * @param continuationToken - The token for pagination. * @returns A TeamsPagedMembersResult containing the paged members. */ async getConversationPagedMember(conversationId, pageSize, continuationToken) { const config = { method: 'get', url: `v3/conversations/${conversationId}/pagedMembers`, params: { pageSize, continuationToken } }; const response = await this.axiosInstance(config); return response.data; } /** * Fetches the list of channels in a team. * @param teamId - The ID of the team. * @returns An array of ChannelInfo objects representing the channels. */ async fetchChannelList(teamId) { const config = { method: 'get', url: `v3/teams/${teamId}/conversations` }; const response = await this.axiosInstance(config); return response.data; } /** * Fetches the details of a team. * @param teamId - The ID of the team. * @returns A TeamDetails object containing the team details. */ async fetchTeamDetails(teamId) { const config = { method: 'get', url: `v3/teams/${teamId}` }; const response = await this.axiosInstance(config); return response.data; } /** * Fetches information about a meeting participant. * @param meetingId - The ID of the meeting. * @param participantId - The ID of the participant. * @param tenantId - The tenant ID. * @returns A string containing participant information. */ async fetchMeetingParticipant(meetingId, participantId, tenantId) { const config = { method: 'get', url: `v1/meetings/${meetingId}/participants/${participantId}`, params: { tenantId } }; const response = await this.axiosInstance(config); return response.data; } /** * Fetches information about a meeting. * @param meetingId - The ID of the meeting. * @returns A MeetingInfo object containing the meeting information. */ async fetchMeetingInfo(meetingId) { const config = { method: 'get', url: `v1/meetings/${meetingId}` }; const response = await this.axiosInstance(config); return response.data; } /** * Sends a notification to a meeting. * @param meetingId - The ID of the meeting. * @param notification - The notification to send. * @returns A MeetingNotificationResponse object containing the response. */ async sendMeetingNotification(meetingId, notification) { const config = { method: 'post', url: `v1/meetings/${meetingId}/notification`, data: notification }; const response = await this.axiosInstance(config); return response.data; } /** * Sends a message to a list of users. * @param activity - The activity to send. * @param tenantId - The tenant ID. * @param members - The list of members to send the message to. * @returns A TeamsBatchOperationResponse object containing the response. */ async sendMessageToListOfUsers(activity, tenantId, members) { const content = { activity, members, tenantId }; const config = { method: 'post', url: 'v3/batch/conversation/users', data: content }; const response = await this.axiosInstance(config); return response.data; } /** * Sends a message to all users in a tenant. * @param activity - The activity to send. * @param tenandId - The tenant ID. * @returns A TeamsBatchOperationResponse object containing the response. */ async sendMessageToAllUsersInTenant(activity, tenandId) { const content = { activity, tenandId }; const config = { method: 'post', url: 'v3/batch/conversation/tenant', data: content }; const response = await this.axiosInstance(config); return response.data; } /** * Sends a message to all users in a team. * @param activity - The activity to send. * @param tenantId - The tenant ID. * @param teamId - The team ID. * @returns A TeamsBatchOperationResponse object containing the response. */ async sendMessageToAllUsersInTeam(activity, tenantId, teamId) { const content = { activity, tenantId, teamId }; const config = { method: 'post', url: 'v3/batch/conversation/team', data: content }; const response = await this.axiosInstance(config); return response.data; } /** * Sends a message to a list of channels. * @param activity - The activity to send. * @param tenantId - The tenant ID. * @param members - The list of members to send the message to. * @returns A TeamsBatchOperationResponse object containing the response. */ async sendMessageToListOfChannels(activity, tenantId, members) { const content = { activity, tenantId, members }; const config = { method: 'post', url: 'v3/batch/conversation/channels', data: content }; const response = await this.axiosInstance(config); return response.data; } /** * Retrieves the state of a batch operation. * @param operationId - The ID of the operation. * @returns A BatchOperationStateResponse object containing the operation state. */ async getOperationState(operationId) { const config = { method: 'get', url: `v3/batch/conversation/${operationId}` }; const response = await this.axiosInstance(config); return response.data; } /** * Retrieves the failed entries of a batch operation. * @param operationId - The ID of the operation. * @returns A BatchFailedEntriesResponse object containing the failed entries. */ async getFailedEntries(operationId) { const config = { method: 'get', url: `v3/batch/conversation/failedentries/${operationId}` }; const response = await this.axiosInstance(config); return response.data; } /** * Cancels a batch operation. * @param operationId - The ID of the operation. * @returns A CancelOperationResponse object containing the response. */ async cancelOperation(operationId) { const config = { method: 'delete', url: `v3/batch/conversation/${operationId}` }; const response = await this.axiosInstance(config); return response.data; } } exports.TeamsConnectorClient = TeamsConnectorClient; //# sourceMappingURL=teamsConnectorClient.js.map