-
Notifications
You must be signed in to change notification settings - Fork 5
[Outlook] Use selected email text as input instead of full body #1448
Open
Description
Summary
When a user highlights text inside an email and starts a chat, they expect the add-in to act on just the selection, not the entire email body. Today the full body is always shoved into the prompt, which is noisy and breaks token budgets on long threads.
Current behavior
client/src/features/office/utilities/outlookMailContext.js:
getBodyTextAsync()(lines 16–31) reads the full email viaitem.body.getAsync(Office.CoercionType.Text, ...).fetchCurrentMailContext()(lines 84–138) returns{ bodyText, subject, itemId, attachments }. There is no notion of a selection.
client/src/features/office/utilities/buildChatApiMessages.js:
combineUserTextWithEmailBody()(lines 71–77) unconditionally appends the full body under--- Current email ---.
The Office.js API for selection in read mode is Office.context.mailbox.item.getSelectedDataAsync(Office.CoercionType.Text, callback) — currently unused.
Proposed change
- In
outlookMailContext.js, addgetSelectedTextAsync()usingitem.getSelectedDataAsync(Office.CoercionType.Text, ...). Resolve tonullon missing/empty selection (don't reject — selection-not-supported should be a soft fallback). - Extend
fetchCurrentMailContext()to returnselectedTextalongsidebodyText. - In
buildChatApiMessages.combineUserTextWithEmailBody()(or a new helper), preferselectedTextwhen non-empty; otherwise fall back tobodyText. - Surface the choice in the UI: if a selection exists, show a chip / banner reading "Using selected text (N chars) — switch to full email" (ties into issue: Review attachments / show like uploaded files).
- Persist the user's last choice (use-selection vs use-full-body) per session.
Acceptance criteria
- Highlighting text in the email and opening the add-in produces a prompt that uses only the selection.
- With no selection, behaviour is identical to today (full body used).
- The user can override the default per message (one-click toggle).
- Selection text is refreshed when the user re-runs (not cached stale).
- Works in both read mode and compose mode where the API supports it.
Files
client/src/features/office/utilities/outlookMailContext.jsclient/src/features/office/utilities/buildChatApiMessages.jsclient/src/features/office/hooks/useOfficeChatAdapter.jsclient/src/features/office/hooks/useOutlookMailContext.jsclient/src/features/office/components/OfficeChatPanel.jsx
Source
User feedback, 2026年05月13日.