Skip to content

Commit 7513c98

Browse files
Merging pull request #14711
* Updating Chat prop to include support for external users. * Bump * Committed CodeRabbit suggestions for error handling and caching for performance. * Adding docs link and original description.
1 parent 4eb94ef commit 7513c98

File tree

13 files changed

+78
-14
lines changed

13 files changed

+78
-14
lines changed

components/microsoft_teams/actions/create-channel/create-channel.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Create Channel",
66
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)",
77
type: "action",
8-
version: "0.0.6",
8+
version: "0.0.7",
99
props: {
1010
microsoftTeams,
1111
teamId: {

components/microsoft_teams/actions/list-channels/list-channels.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "List Channels",
66
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)",
77
type: "action",
8-
version: "0.0.6",
8+
version: "0.0.7",
99
props: {
1010
microsoftTeams,
1111
teamId: {

components/microsoft_teams/actions/list-shifts/list-shifts.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "List Shifts",
66
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)",
77
type: "action",
8-
version: "0.0.3",
8+
version: "0.0.4",
99
props: {
1010
microsoftTeams,
1111
teamId: {

components/microsoft_teams/actions/send-channel-message/send-channel-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Send Channel Message",
66
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)",
77
type: "action",
8-
version: "0.0.6",
8+
version: "0.0.7",
99
props: {
1010
microsoftTeams,
1111
teamId: {

components/microsoft_teams/actions/send-chat-message/send-chat-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Send Chat Message",
66
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)",
77
type: "action",
8-
version: "0.0.6",
8+
version: "0.0.7",
99
props: {
1010
microsoftTeams,
1111
chatId: {

components/microsoft_teams/microsoft_teams.app.mjs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,64 @@ export default {
5858
chat: {
5959
type: "string",
6060
label: "Chat",
61-
description: "Team Chat within the organization (No external Contacts)",
61+
description: "Team Chat (internal and external contacts)",
6262
async options({ prevContext }) {
6363
const response = prevContext.nextLink
6464
? await this.makeRequest({
6565
path: prevContext.nextLink,
6666
})
6767
: await this.listChats();
68+
69+
const myTenantId = await this.getAuthenticatedUserTenant();
6870
const options = [];
71+
72+
this._userCache = this._userCache || new Map();
73+
6974
for (const chat of response.value) {
70-
const members = chat.members.map((member) => member.displayName);
75+
const messages = await this.makeRequest({
76+
path: `/chats/${chat.id}/messages?$top=50`,
77+
});
78+
79+
const members = await Promise.all(chat.members.map(async (member) => {
80+
const cacheKey = `user_${member.userId}`;
81+
let displayName = member.displayName || this._userCache.get(cacheKey);
82+
83+
if (!displayName) {
84+
try {
85+
if (messages?.value?.length > 0) {
86+
const userMessage = messages.value.find((msg) =>
87+
msg.from?.user?.id === member.userId);
88+
if (userMessage?.from?.user?.displayName) {
89+
displayName = userMessage.from.user.displayName;
90+
}
91+
}
92+
93+
if (!displayName) {
94+
const userDetails = await this.makeRequest({
95+
path: `/users/${member.userId}`,
96+
});
97+
displayName = userDetails.displayName;
98+
}
99+
100+
this._userCache.set(cacheKey, displayName);
101+
} catch (err) {
102+
if (err.statusCode === 404) {
103+
displayName = "User Not Found";
104+
} else if (err.statusCode === 403) {
105+
displayName = "Access Denied";
106+
} else {
107+
displayName = "Unknown User";
108+
}
109+
console.error(`Failed to fetch user details for ${member.userId}:`, err);
110+
}
111+
}
112+
113+
const isExternal = member.tenantId !== myTenantId || !member.tenantId;
114+
return isExternal
115+
? `${displayName} (External)`
116+
: displayName;
117+
}));
118+
71119
options.push({
72120
label: members.join(", "),
73121
value: chat.id,
@@ -144,6 +192,22 @@ export default {
144192
: reduction;
145193
}, api);
146194
},
195+
async getAuthenticatedUserTenant() {
196+
try {
197+
const { value } = await this.client()
198+
.api("/organization")
199+
.get();
200+
201+
if (!value || value.length === 0) {
202+
throw new Error("No organization found");
203+
}
204+
205+
return value[0].id;
206+
} catch (error) {
207+
console.error("Failed to fetch tenant ID:", error);
208+
throw new Error("Unable to determine tenant ID");
209+
}
210+
},
147211
async authenticatedUserId() {
148212
const { id } = await this.client()
149213
.api("/me")

components/microsoft_teams/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/microsoft_teams",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Pipedream Microsoft Teams Components",
55
"main": "microsoft_teams.app.mjs",
66
"keywords": [

components/microsoft_teams/sources/new-channel-message/new-channel-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "microsoft_teams-new-channel-message",
66
name: "New Channel Message",
77
description: "Emit new event when a new message is posted in a channel",
8-
version: "0.0.7",
8+
version: "0.0.8",
99
type: "source",
1010
dedupe: "unique",
1111
props: {

components/microsoft_teams/sources/new-channel/new-channel.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "microsoft_teams-new-channel",
66
name: "New Channel",
77
description: "Emit new event when a new channel is created within a team",
8-
version: "0.0.7",
8+
version: "0.0.8",
99
type: "source",
1010
dedupe: "unique",
1111
props: {

components/microsoft_teams/sources/new-chat-message/new-chat-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "microsoft_teams-new-chat-message",
66
name: "New Chat Message",
77
description: "Emit new event when a new message is received in a chat",
8-
version: "0.0.7",
8+
version: "0.0.8",
99
type: "source",
1010
dedupe: "unique",
1111
props: {

0 commit comments

Comments
 (0)