-
Notifications
You must be signed in to change notification settings - Fork 3.1k
improvement(ms-teams): resolve mentions accurately #1762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds proper mention resolution for MS Teams chat and channel messages. When users include <at>name</at> tags in messages, the system now fetches member lists from the MS Graph API, matches names to user IDs, and properly formats mentions in the message payload.
Key changes:
- Added
parseMentions(),fetchChatMembers(),fetchChannelMembers(), andresolveMentionsForChat/Channel()utility functions - Updated tool configuration to detect mentions via regex and route to custom API when found
- Modified API routes to call mention resolution, build proper mention entities, and set contentType to 'html' when mentions are present
- Implemented graceful error handling that continues without mentions if resolution fails
- Improved TypeScript typing by replacing
anycasts with proper type definitions for message bodies
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The implementation follows best practices with proper error handling, TypeScript typing, and graceful degradation. The mention resolution is wrapped in try-catch blocks that log warnings but continue execution if it fails. The regex pattern for detecting mentions is straightforward and the member matching logic uses simple case-insensitive string comparison. No security vulnerabilities or logic errors were identified.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/tools/microsoft_teams/utils.ts | 5/5 | Added mention resolution utilities including parseMentions, fetchChatMembers, fetchChannelMembers, and resolveMentions functions |
| apps/sim/app/api/tools/microsoft_teams/write_channel/route.ts | 5/5 | Integrated mention resolution with proper error handling and contentType management |
| apps/sim/app/api/tools/microsoft_teams/write_chat/route.ts | 5/5 | Integrated mention resolution with proper error handling and contentType management |
Sequence Diagram
sequenceDiagram
participant Client
participant ToolConfig as write_chat/write_channel
participant API as Custom API Route
participant Utils as Utils (resolveMentions)
participant MSGraph as Microsoft Graph API
Client->>ToolConfig: Send message with <at>name</at>
ToolConfig->>ToolConfig: Detect mentions with regex
alt Has mentions or files
ToolConfig->>API: Route to custom API
API->>API: Parse and validate request
API->>Utils: Call resolveMentionsForChat/Channel
Utils->>Utils: parseMentions(content)
Utils->>MSGraph: Fetch chat/channel members
MSGraph-->>Utils: Return member list
Utils->>Utils: Match mention names to member IDs
Utils-->>API: Return mention entities
API->>API: Set contentType to 'html'
API->>API: Build messageBody with mentions
API->>MSGraph: POST message with mentions array
MSGraph-->>API: Message created
API-->>Client: Success response
else No mentions and no files
ToolConfig->>MSGraph: Direct API call
MSGraph-->>Client: Message created
end
5 files reviewed, no comments
This reverts commit 0ac702a.
* improvement(ms-teams): resolve mentions accurately * fix for bots * add utils file * add logs * fix perms issue * fix scopes * fetch works for bots * Revert "fetch works for bots" This reverts commit 0ac702a. * update docs
Summary
Resolve @ mentions correctly for MS-teams write chat and write channel tools for users.
Type of Change
Testing
Testing with @aadamgough
Checklist