Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Oct 29, 2025

Summary

Resolve @ mentions correctly for MS-teams write chat and write channel tools for users.

Type of Change

  • Other: Functionality Improvement

Testing

Testing with @aadamgough

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Oct 30, 2025 5:20am

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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(), and resolveMentionsForChat/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 any casts 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
Loading

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit fdefb14 into staging Oct 30, 2025
9 checks passed
@waleedlatif1 waleedlatif1 mentioned this pull request Oct 30, 2025
10 tasks
@waleedlatif1 waleedlatif1 deleted the improvement/ms-teams-mentions branch November 6, 2025 01:25
waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
* 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
@waleedlatif1 waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants