microsoft / microsoft/teams.ts
Provide a built-in option to strip only the bot’s own mention from inbound activity text
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 107
- Forks
- 39
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 74
Description
The current `activity.mentions.stripText: true` option removes all structured mentions from inbound activity text. Bot command handlers commonly need different behavior: remove the bot’s leading mention while preserving mentions of other users.
For example:
```text
Input: GitHub help Alice
Output: help Alice
```
Today this requires application code to identify the mention whose account ID matches `activity.recipient.id` and remove it manually:
```ts
for (const entity of activity.entities ?? []) {
if (
entity.type === 'mention' &&
entity.mentioned?.id === activity.recipient.id &&
entity.text
) {
activity.text = activity.text.replace(entity.text, '').trim();
break;
}
}
```
The lower-level `stripMentionsText` utility supports filtering by `accountId`, but applications must know to call it and pass the recipient ID for every activity. The app-level mention middleware could provide this common behavior directly because it already has access to the activity and its recipient.
Would you consider an option such as:
```ts
const app = new App({
activity: {
mentions: {
stripText: {
recipient: true,
leadingOnly: true,
},
},
},
});
```
or a dedicated utility:
```ts
stripRecipientMentionText(activity, { leadingOnly: true });
```
Expected behavior:
- Remove the bot/recipient mention from the beginning of the message.
- Preserve mentions of other users.
- Preserve a bot mention appearing later in the message when `leadingOnly` is enabled.
- Handle mention entities that provide either `text` or only the mentioned account’s name.
- Trim whitespace left by removing the leading mention.
This would cover the common Teams bot command-parsing scenario without requiring each application to implement its own mention matching and text mutation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the app-level mention middleware and the lower-level stripMentionsText utility described in the issue, then trace how activity.entities, activity.text, and activity.recipient.id are available. Define and implement the selected option or utility so it removes only a leading recipient mention, preserves other and later mentions, handles text or account-name entities, and trims the remaining whitespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100