Skip to content

Provide a built-in option to strip only the bot’s own mention from inbound activity text #833

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:

Input:  <at>GitHub</at> help <at>Alice</at>
Output: help <at>Alice</at>

Today this requires application code to identify the mention whose account ID matches activity.recipient.id and remove it manually:

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:

const app = new App({
  activity: {
    mentions: {
      stripText: {
        recipient: true,
        leadingOnly: true,
      },
    },
  },
});

or a dedicated utility:

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions