Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
141 changes: 67 additions & 74 deletions components/microsoft_teams/microsoft_teams.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
label: "Channel",
description: "Team Channel",
async options({
teamId, prevContext,
teamId,
prevContext,
}) {
const response = prevContext.nextLink
? await this.makeRequest({
Expand All @@ -58,76 +59,76 @@
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, searchTerm }) {

Check failure on line 63 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break after this opening brace

Check failure on line 63 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break before this closing brace
let path = "/chats?$expand=members";
path += "&$top=20";

Check failure on line 66 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
if (searchTerm) {
path += `&$search="${searchTerm}"`;
}

Check failure on line 70 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
const response = prevContext?.nextLink
? await this.makeRequest({
path: prevContext.nextLink,
})
: await this.listChats();

const myTenantId = await this.getAuthenticatedUserTenant();
const options = [];

: await this.makeRequest({
path,
});

Check failure on line 78 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
this._userCache = this._userCache || new Map();

const options = [];

Check failure on line 81 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
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);

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 (!displayName) {
const userDetails = await this.makeRequest({
path: `/users/${member.userId}`,
});
displayName = userDetails.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";
let members = chat.members.map((member) => ({
displayName: member.displayName,
wasNull: !member.displayName,
userId: member.userId,
email: member.email,
}));

Check failure on line 89 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
if (members.some((member) => !member.displayName)) {
try {
const messages = await this.makeRequest({
path: `/chats/${chat.id}/messages?$top=10&$orderby=createdDateTime desc`,
});

Check failure on line 95 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
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);
}
console.error(`Failed to fetch user details for ${member.userId}:`, err);
}
});

Check failure on line 102 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
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;
}));

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance error resilience in message fetching

The current error handling for message fetching only logs the error. Consider:

  1. Implementing retry logic for transient failures
  2. Gracefully falling back to email/userId when message fetching fails
 if (members.some((member) => !member.displayName)) {
+  const maxRetries = 3;
+  let retryCount = 0;
   try {
-    const messages = await this.makeRequest({
-      path: `/chats/${chat.id}/messages?$top=10&$orderby=createdDateTime desc`,
-    });
+    const messages = await this._retryWithBackoff(async () => {
+      return await this.makeRequest({
+        path: `/chats/${chat.id}/messages?$top=10&$orderby=createdDateTime desc`,
+      });
+    }, maxRetries);

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 eslint

[error] 95-95: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 102-102: Trailing spaces not allowed.

(no-trailing-spaces)

🪛 GitHub Check: Lint Code Base

[failure] 95-95:
Trailing spaces not allowed


[failure] 102-102:
Trailing spaces not allowed


Check failure on line 111 in components/microsoft_teams/microsoft_teams.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Trailing spaces not allowed
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: {
nextLink: response["@odata.nextLink"],
},
};
},
useQuery: true,
},
channelDisplayName: {
type: "string",
Expand Down Expand Up @@ -168,7 +169,10 @@
});
},
async makeRequest({
method, path, params = {}, content,
method,
path,
params = {},
content,
}) {
const api = this.client().api(path);

Expand All @@ -192,22 +196,6 @@
: 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")
Expand All @@ -231,7 +219,8 @@
});
},
async createChannel({
teamId, content,
teamId,
content,
}) {
return this.makeRequest({
method: "post",
Expand All @@ -240,7 +229,9 @@
});
},
async sendChannelMessage({
teamId, channelId, content,
teamId,
channelId,
content,
}) {
return this.makeRequest({
method: "post",
Expand All @@ -249,7 +240,8 @@
});
},
async sendChatMessage({
chatId, content,
chatId,
content,
}) {
return this.makeRequest({
method: "post",
Expand Down Expand Up @@ -279,7 +271,8 @@
.get();
},
async listChannelMessages({
teamId, channelId,
teamId,
channelId,
}) {
return this.makeRequest({
path: `/teams/${teamId}/channels/${channelId}/messages/delta`,
Expand Down
2 changes: 1 addition & 1 deletion components/microsoft_teams/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion components/microsoft_teams/sources/new-chat/new-chat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion components/microsoft_teams/sources/new-team/new-team.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading