diff --git a/components/microsoft_teams/actions/create-channel/create-channel.mjs b/components/microsoft_teams/actions/create-channel/create-channel.mjs index 76708df037b2f..844c59d96d475 100644 --- a/components/microsoft_teams/actions/create-channel/create-channel.mjs +++ b/components/microsoft_teams/actions/create-channel/create-channel.mjs @@ -5,7 +5,7 @@ export default { name: "Create Channel", description: "Create a new channel in Microsoft Teams. [See the docs here](https://docs.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-1.0&tabs=http)", type: "action", - version: "0.0.7", + version: "0.0.8", props: { microsoftTeams, teamId: { diff --git a/components/microsoft_teams/actions/list-channels/list-channels.mjs b/components/microsoft_teams/actions/list-channels/list-channels.mjs index 1752d87e0f694..3451cb7b2a14b 100644 --- a/components/microsoft_teams/actions/list-channels/list-channels.mjs +++ b/components/microsoft_teams/actions/list-channels/list-channels.mjs @@ -5,7 +5,7 @@ export default { name: "List Channels", description: "Lists all channels in a Microsoft Team. [See the docs here](https://docs.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-1.0&tabs=http)", type: "action", - version: "0.0.7", + version: "0.0.8", props: { microsoftTeams, teamId: { diff --git a/components/microsoft_teams/actions/list-shifts/list-shifts.mjs b/components/microsoft_teams/actions/list-shifts/list-shifts.mjs index cd679b51661d9..2af018585a8ac 100644 --- a/components/microsoft_teams/actions/list-shifts/list-shifts.mjs +++ b/components/microsoft_teams/actions/list-shifts/list-shifts.mjs @@ -5,7 +5,7 @@ export default { name: "List Shifts", description: "Get the list of shift instances for a team. [See the documentation](https://learn.microsoft.com/en-us/graph/api/schedule-list-shifts?view=graph-rest-1.0&tabs=http)", type: "action", - version: "0.0.4", + version: "0.0.5", props: { microsoftTeams, teamId: { diff --git a/components/microsoft_teams/actions/send-channel-message/send-channel-message.mjs b/components/microsoft_teams/actions/send-channel-message/send-channel-message.mjs index a5b4adc642d09..9ed69e54b1190 100644 --- a/components/microsoft_teams/actions/send-channel-message/send-channel-message.mjs +++ b/components/microsoft_teams/actions/send-channel-message/send-channel-message.mjs @@ -5,7 +5,7 @@ export default { name: "Send Channel Message", description: "Send a message to a team's channel. [See the docs here](https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http)", type: "action", - version: "0.0.7", + version: "0.0.8", props: { microsoftTeams, teamId: { diff --git a/components/microsoft_teams/actions/send-chat-message/send-chat-message.mjs b/components/microsoft_teams/actions/send-chat-message/send-chat-message.mjs index f02834e2b3b23..265adb34126a2 100644 --- a/components/microsoft_teams/actions/send-chat-message/send-chat-message.mjs +++ b/components/microsoft_teams/actions/send-chat-message/send-chat-message.mjs @@ -5,7 +5,7 @@ export default { name: "Send Chat Message", description: "Send a message to a team's chat. [See the docs here](https://docs.microsoft.com/en-us/graph/api/chat-post-messages?view=graph-rest-1.0&tabs=http)", type: "action", - version: "0.0.7", + version: "0.0.8", props: { microsoftTeams, chatId: { diff --git a/components/microsoft_teams/microsoft_teams.app.mjs b/components/microsoft_teams/microsoft_teams.app.mjs index d343128d39e5c..12edcb2f43997 100644 --- a/components/microsoft_teams/microsoft_teams.app.mjs +++ b/components/microsoft_teams/microsoft_teams.app.mjs @@ -34,7 +34,8 @@ export default { label: "Channel", description: "Team Channel", async options({ - teamId, prevContext, + teamId, + prevContext, }) { const response = prevContext.nextLink ? await this.makeRequest({ @@ -58,69 +59,69 @@ export default { chat: { type: "string", label: "Chat", - description: "Team Chat (internal and external contacts)", - async options({ prevContext }) { - const response = prevContext.nextLink + description: "Select a chat (type to search by participant names)", + async options({ + prevContext, query, + }) { + let path = "/chats?$expand=members"; + path += "&$top=20"; + + if (query) { + path += `&$search="${query}"`; + } + + const response = prevContext?.nextLink ? await this.makeRequest({ path: prevContext.nextLink, }) - : await this.listChats(); - - const myTenantId = await this.getAuthenticatedUserTenant(); - const options = []; + : await this.makeRequest({ + path, + }); this._userCache = this._userCache || new Map(); + const options = []; for (const chat of response.value) { - const messages = await this.makeRequest({ - path: `/chats/${chat.id}/messages?$top=50`, - }); - - const members = await Promise.all(chat.members.map(async (member) => { - const cacheKey = `user_${member.userId}`; - let displayName = member.displayName || this._userCache.get(cacheKey); + let members = chat.members.map((member) => ({ + displayName: member.displayName, + wasNull: !member.displayName, + userId: member.userId, + email: member.email, + })); - if (!displayName) { - try { - if (messages?.value?.length > 0) { - const userMessage = messages.value.find((msg) => - msg.from?.user?.id === member.userId); - if (userMessage?.from?.user?.displayName) { - displayName = userMessage.from.user.displayName; - } - } + if (members.some((member) => !member.displayName)) { + try { + const messages = await this.makeRequest({ + path: `/chats/${chat.id}/messages?$top=10&$orderby=createdDateTime desc`, + }); - if (!displayName) { - const userDetails = await this.makeRequest({ - path: `/users/${member.userId}`, - }); - displayName = userDetails.displayName; + const nameMap = new Map(); + messages.value.forEach((msg) => { + if (msg.from?.user?.id && msg.from?.user?.displayName) { + nameMap.set(msg.from.user.id, msg.from.user.displayName); } + }); - this._userCache.set(cacheKey, displayName); - } catch (err) { - if (err.statusCode === 404) { - displayName = "User Not Found"; - } else if (err.statusCode === 403) { - displayName = "Access Denied"; - } else { - displayName = "Unknown User"; - } - console.error(`Failed to fetch user details for ${member.userId}:`, err); - } + members = members.map((member) => ({ + ...member, + displayName: member.displayName || nameMap.get(member.userId) || member.email || "Unknown User", + })); + } catch (err) { + console.error(`Failed to fetch messages for chat ${chat.id}:`, err); } + } - const isExternal = member.tenantId !== myTenantId || !member.tenantId; - return isExternal - ? `${displayName} (External)` - : displayName; - })); + const memberNames = members.map((member) => + member.wasNull + ? `${member.displayName} (External)` + : member.displayName); options.push({ - label: members.join(", "), + label: memberNames.join(", "), value: chat.id, }); } + return { options, context: { @@ -128,6 +129,7 @@ export default { }, }; }, + useQuery: true, }, channelDisplayName: { type: "string", @@ -168,7 +170,10 @@ export default { }); }, async makeRequest({ - method, path, params = {}, content, + method, + path, + params = {}, + content, }) { const api = this.client().api(path); @@ -192,22 +197,6 @@ export default { : reduction; }, api); }, - async getAuthenticatedUserTenant() { - try { - const { value } = await this.client() - .api("/organization") - .get(); - - if (!value || value.length === 0) { - throw new Error("No organization found"); - } - - return value[0].id; - } catch (error) { - console.error("Failed to fetch tenant ID:", error); - throw new Error("Unable to determine tenant ID"); - } - }, async authenticatedUserId() { const { id } = await this.client() .api("/me") @@ -231,7 +220,8 @@ export default { }); }, async createChannel({ - teamId, content, + teamId, + content, }) { return this.makeRequest({ method: "post", @@ -240,7 +230,9 @@ export default { }); }, async sendChannelMessage({ - teamId, channelId, content, + teamId, + channelId, + content, }) { return this.makeRequest({ method: "post", @@ -249,7 +241,8 @@ export default { }); }, async sendChatMessage({ - chatId, content, + chatId, + content, }) { return this.makeRequest({ method: "post", @@ -279,7 +272,8 @@ export default { .get(); }, async listChannelMessages({ - teamId, channelId, + teamId, + channelId, }) { return this.makeRequest({ path: `/teams/${teamId}/channels/${channelId}/messages/delta`, diff --git a/components/microsoft_teams/package.json b/components/microsoft_teams/package.json index 0c13f4b2a7c0d..c6550f058d7b2 100644 --- a/components/microsoft_teams/package.json +++ b/components/microsoft_teams/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/microsoft_teams", - "version": "0.1.3", + "version": "0.1.4", "description": "Pipedream Microsoft Teams Components", "main": "microsoft_teams.app.mjs", "keywords": [ diff --git a/components/microsoft_teams/sources/new-channel-message/new-channel-message.mjs b/components/microsoft_teams/sources/new-channel-message/new-channel-message.mjs index 7d029a50f7f44..37898dae07a8b 100644 --- a/components/microsoft_teams/sources/new-channel-message/new-channel-message.mjs +++ b/components/microsoft_teams/sources/new-channel-message/new-channel-message.mjs @@ -5,7 +5,7 @@ export default { key: "microsoft_teams-new-channel-message", name: "New Channel Message", description: "Emit new event when a new message is posted in a channel", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", props: { diff --git a/components/microsoft_teams/sources/new-channel/new-channel.mjs b/components/microsoft_teams/sources/new-channel/new-channel.mjs index b3824a0246cc3..89cf6fd8a23f2 100644 --- a/components/microsoft_teams/sources/new-channel/new-channel.mjs +++ b/components/microsoft_teams/sources/new-channel/new-channel.mjs @@ -5,7 +5,7 @@ export default { key: "microsoft_teams-new-channel", name: "New Channel", description: "Emit new event when a new channel is created within a team", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", props: { diff --git a/components/microsoft_teams/sources/new-chat-message/new-chat-message.mjs b/components/microsoft_teams/sources/new-chat-message/new-chat-message.mjs index 2beb9bb0bc6b2..1f0e8925cc3b9 100644 --- a/components/microsoft_teams/sources/new-chat-message/new-chat-message.mjs +++ b/components/microsoft_teams/sources/new-chat-message/new-chat-message.mjs @@ -5,7 +5,7 @@ export default { key: "microsoft_teams-new-chat-message", name: "New Chat Message", description: "Emit new event when a new message is received in a chat", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", props: { diff --git a/components/microsoft_teams/sources/new-chat/new-chat.mjs b/components/microsoft_teams/sources/new-chat/new-chat.mjs index 4ca96716efe61..e105b9374ab18 100644 --- a/components/microsoft_teams/sources/new-chat/new-chat.mjs +++ b/components/microsoft_teams/sources/new-chat/new-chat.mjs @@ -5,7 +5,7 @@ export default { key: "microsoft_teams-new-chat", name: "New Chat", description: "Emit new event when a new chat is created", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", methods: { diff --git a/components/microsoft_teams/sources/new-team-member/new-team-member.mjs b/components/microsoft_teams/sources/new-team-member/new-team-member.mjs index bb673fbf496db..2011638c4ed11 100644 --- a/components/microsoft_teams/sources/new-team-member/new-team-member.mjs +++ b/components/microsoft_teams/sources/new-team-member/new-team-member.mjs @@ -5,7 +5,7 @@ export default { key: "microsoft_teams-new-team-member", name: "New Team Member", description: "Emit new event when a new member is added to a team", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", props: { diff --git a/components/microsoft_teams/sources/new-team/new-team.mjs b/components/microsoft_teams/sources/new-team/new-team.mjs index 92b48dcceda90..3c9799c1e54f8 100644 --- a/components/microsoft_teams/sources/new-team/new-team.mjs +++ b/components/microsoft_teams/sources/new-team/new-team.mjs @@ -5,7 +5,7 @@ export default { key: "microsoft_teams-new-team", name: "New Team", description: "Emit new event when a new team is joined by the authenticated user", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", methods: {