-
Notifications
You must be signed in to change notification settings - Fork 19
Updated quoted replies & new quotes features #321
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
Open
corinagum
wants to merge
20
commits into
main
Choose a base branch
from
cg/quoted-replies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a3e168c
Remove with_reply_to_id
1e9b596
Quoted reply features and unit tests
babffd2
Fix up
bd0ea4b
Quoted replies sample
89a5c34
Mark as experimental and remove replyToId change
8e5eb72
Update examples
e796969
Fix pyright errors in quote_reply() type narrowing
f238d35
Fix tests
a7a0366
PR Feedback
9182616
Update sample README.md
27f5d89
Add docstring for time field format (IC3 epoch)
cde6dfe
Fix test string
8cb1b40
Have reply defer quote_reply
b284672
Move stamping to model layer
2c4df11
Update to quote and verbiage improvements
corinagum 5efa251
Add TENANT_ID to sample env vars
corinagum 1779d75
Separate copyright from description in example docstring
corinagum 2994996
Rename example
corinagum ff32d1a
Change preview wording to coming soon
corinagum 4236a21
Update preview wording to Coming soon
corinagum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Example: Quoting | ||
|
|
||
| A bot that demonstrates various ways to quote previous messages in Microsoft Teams. | ||
|
|
||
| ## Commands | ||
|
|
||
| | Command | Behavior | | ||
| |---------|----------| | ||
| | `test reply` | `reply()` — auto-quotes the inbound message | | ||
| | `test quote` | `quote()` — sends a message, then quotes it by ID | | ||
| | `test add` | `add_quote()` — sends a message, then quotes it with builder + response | | ||
| | `test multi` | Sends two messages, then quotes both with interleaved responses | | ||
| | `test manual` | `add_quote()` + `add_text()` — manual control | | ||
| | `help` | Shows available commands | | ||
| | *(quote a message)* | Bot reads and displays the quoted reply metadata | | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| cd examples/quoting | ||
| pip install -e . | ||
| python src/main.py | ||
|
|
||
| # Or with uv: | ||
| uv run python src/main.py | ||
corinagum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| Create a `.env` file: | ||
|
|
||
| ```env | ||
| CLIENT_ID=<your-azure-bot-app-id> | ||
| CLIENT_SECRET=<your-azure-bot-app-secret> | ||
| TENANT_ID=<your-tenant-id> | ||
| ``` | ||
corinagum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [project] | ||
| name = "quoting" | ||
| version = "0.1.0" | ||
| description = "Quoting example - demonstrates various ways to quote previous messages in conversations" | ||
| readme = "README.md" | ||
| requires-python = ">=3.12,<3.15" | ||
| dependencies = [ | ||
| "dotenv>=0.9.9", | ||
| "microsoft-teams-apps", | ||
| "microsoft-teams-api", | ||
| ] | ||
|
|
||
| [tool.uv.sources] | ||
| microsoft-teams-apps = { workspace = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| import asyncio | ||
|
|
||
| from microsoft_teams.api import MessageActivity, MessageActivityInput | ||
| from microsoft_teams.api.activities.typing import TypingActivityInput | ||
| from microsoft_teams.apps import ActivityContext, App | ||
|
|
||
| app = App() | ||
|
|
||
|
|
||
| @app.on_message | ||
| async def handle_message(ctx: ActivityContext[MessageActivity]): | ||
| """Handle message activities.""" | ||
| await ctx.reply(TypingActivityInput()) | ||
|
|
||
| text = (ctx.activity.text or "").lower() | ||
|
|
||
| # ============================================ | ||
| # Read inbound quoted replies | ||
| # ============================================ | ||
| quotes = ctx.activity.get_quoted_messages() | ||
| if quotes: | ||
| quote = quotes[0].quoted_reply | ||
| info_parts = [f"Quoted message ID: {quote.message_id}"] | ||
| if quote.sender_name: | ||
| info_parts.append(f"From: {quote.sender_name}") | ||
| if quote.preview: | ||
| info_parts.append(f'Preview: "{quote.preview}"') | ||
| if quote.is_reply_deleted: | ||
| info_parts.append("(deleted)") | ||
| if quote.validated_message_reference: | ||
| info_parts.append("(validated)") | ||
|
|
||
| await ctx.send("You sent a message with a quoted reply:\n\n" + "\n".join(info_parts)) | ||
|
|
||
| # ============================================ | ||
| # reply() — auto-quotes the inbound message | ||
| # ============================================ | ||
| if "test reply" in text: | ||
| await ctx.reply("Thanks for your message! This reply auto-quotes it using reply().") | ||
| return | ||
|
|
||
| # ============================================ | ||
| # quote() — quote a previously sent message by ID | ||
| # ============================================ | ||
| if "test quote" in text: | ||
| sent = await ctx.send("The meeting has been moved to 3 PM tomorrow.") | ||
| await ctx.quote(sent.id, "Just to confirm — does the new time work for everyone?") | ||
| return | ||
|
|
||
| # ============================================ | ||
| # add_quote() — builder with response | ||
| # ============================================ | ||
| if "test add" in text: | ||
| sent = await ctx.send("Please review the latest PR before end of day.") | ||
| msg = MessageActivityInput().add_quote(sent.id, "Done! Left my comments on the PR.") | ||
| await ctx.send(msg) | ||
| return | ||
|
|
||
| # ============================================ | ||
| # Multi-quote with mixed responses | ||
| # ============================================ | ||
| if "test multi" in text: | ||
| sent_a = await ctx.send("We need to update the API docs before launch.") | ||
| sent_b = await ctx.send("The design mockups are ready for review.") | ||
| sent_c = await ctx.send("CI pipeline is green on main.") | ||
| msg = ( | ||
| MessageActivityInput() | ||
| .add_quote(sent_a.id, "I can take the docs — will have a draft by Thursday.") | ||
| .add_quote(sent_b.id, "Looks great, approved!") | ||
| .add_quote(sent_c.id) | ||
| ) | ||
| await ctx.send(msg) | ||
| return | ||
|
|
||
| # ============================================ | ||
| # add_quote() + add_text() — manual control | ||
| # ============================================ | ||
| if "test manual" in text: | ||
| sent = await ctx.send("Deployment to staging is complete.") | ||
| msg = MessageActivityInput().add_quote(sent.id).add_text(" Verified — all smoke tests passing.") | ||
| await ctx.send(msg) | ||
| return | ||
|
|
||
| # ============================================ | ||
| # Help / Default | ||
| # ============================================ | ||
| if "help" in text: | ||
| await ctx.reply( | ||
| "**Quoting Test Bot**\n\n" | ||
| "**Commands:**\n" | ||
| "- `test reply` - reply() auto-quotes your message\n" | ||
| "- `test quote` - quote() quotes a previously sent message\n" | ||
| "- `test add` - add_quote() builder with response\n" | ||
| "- `test multi` - Multi-quote with mixed responses (one bare quote with no response)\n" | ||
| "- `test manual` - add_quote() + add_text() manual control\n\n" | ||
| "Quote any message to me to see the parsed metadata!" | ||
| ) | ||
| return | ||
|
|
||
| await ctx.reply('Say "help" for available commands.') | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(app.start()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| from typing import Any, List, Literal, Optional, Self | ||
|
|
||
| from microsoft_teams.cards import AdaptiveCard | ||
| from microsoft_teams.common.experimental import experimental | ||
|
|
||
| from ...models import ( | ||
| Account, | ||
|
|
@@ -21,6 +22,8 @@ | |
| Importance, | ||
| InputHint, | ||
| MentionEntity, | ||
| QuotedReplyData, | ||
| QuotedReplyEntity, | ||
| StreamInfoEntity, | ||
| SuggestedActions, | ||
| TextFormat, | ||
|
|
@@ -82,6 +85,20 @@ class MessageActivity(_MessageBase, ActivityBase): | |
| text: str = "" # pyright: ignore [reportGeneralTypeIssues, reportIncompatibleVariableOverride] | ||
| """The text content of the message.""" | ||
|
|
||
| @experimental("ExperimentalTeamsQuotedReplies") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want quote/quoting for this too? |
||
| def get_quoted_messages(self) -> list[QuotedReplyEntity]: | ||
| """ | ||
| Get all quoted reply entities from this message. | ||
|
|
||
| Returns: | ||
| List of quoted reply entities, empty if none | ||
|
|
||
| .. warning:: Coming Soon | ||
| This API is coming soon and may change in the future. | ||
| Diagnostic: ExperimentalTeamsQuotedReplies | ||
| """ | ||
| return [e for e in (self.entities or []) if isinstance(e, QuotedReplyEntity)] | ||
corinagum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def is_recipient_mentioned(self) -> bool: | ||
| """ | ||
| Check if the recipient account is mentioned in the message. | ||
|
|
@@ -397,6 +414,56 @@ def add_stream_final(self) -> Self: | |
|
|
||
| return self.add_entity(stream_entity) | ||
|
|
||
| @experimental("ExperimentalTeamsQuotedReplies") | ||
| def prepend_quote(self, message_id: str) -> Self: | ||
| """ | ||
| Prepend a quotedReply entity and placeholder before existing text. | ||
| Used by reply()/quote() for quote-above-response. | ||
|
|
||
| Args: | ||
| message_id: The IC3 message ID of the message to quote | ||
|
|
||
| Returns: | ||
| Self for method chaining | ||
|
|
||
| .. warning:: Coming Soon | ||
| This API is coming soon and may change in the future. | ||
| Diagnostic: ExperimentalTeamsQuotedReplies | ||
| """ | ||
| if not self.entities: | ||
| self.entities = [] | ||
| self.entities.append(QuotedReplyEntity(quoted_reply=QuotedReplyData(message_id=message_id))) | ||
| placeholder = f'<quoted messageId="{message_id}"/>' | ||
| has_text = bool((self.text or "").strip()) | ||
| self.text = f"{placeholder} {self.text}" if has_text else placeholder | ||
| return self | ||
|
|
||
| @experimental("ExperimentalTeamsQuotedReplies") | ||
| def add_quote(self, message_id: str, text: str | None = None) -> Self: | ||
| """ | ||
| Add a quoted message reference and append a placeholder to text. | ||
| Teams renders the quoted message as a preview bubble above the response text. | ||
| If text is provided, it is appended to the quoted message placeholder. | ||
|
|
||
| Args: | ||
| message_id: The ID of the message to quote | ||
| text: Optional text, appended to the quoted message placeholder | ||
|
|
||
| Returns: | ||
| Self for method chaining | ||
|
|
||
| .. warning:: Coming Soon | ||
| This API is coming soon and may change in the future. | ||
| Diagnostic: ExperimentalTeamsQuotedReplies | ||
| """ | ||
| if not self.entities: | ||
| self.entities = [] | ||
| self.entities.append(QuotedReplyEntity(quoted_reply=QuotedReplyData(message_id=message_id))) | ||
| self.add_text(f'<quoted messageId="{message_id}"/>') | ||
| if text: | ||
| self.add_text(f" {text}") | ||
| return self | ||
|
|
||
| def with_recipient(self, value: Account, is_targeted: Optional[bool] = None) -> Self: | ||
| """ | ||
| Set the recipient. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/api/src/microsoft_teams/api/models/entity/quoted_reply_entity.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from typing import Literal, Optional | ||
|
|
||
| from microsoft_teams.common.experimental import experimental | ||
|
|
||
| from ..custom_base_model import CustomBaseModel | ||
|
|
||
|
|
||
| @experimental("ExperimentalTeamsQuotedReplies") | ||
| class QuotedReplyData(CustomBaseModel): | ||
| """Data for a quoted reply entity | ||
|
|
||
| .. warning:: Coming Soon | ||
| This API is coming soon and may change in the future. | ||
| Diagnostic: ExperimentalTeamsQuotedReplies | ||
| """ | ||
|
|
||
| message_id: str | ||
| "ID of the message being quoted" | ||
|
|
||
| sender_id: Optional[str] = None | ||
| "ID of the sender of the quoted message" | ||
|
|
||
| sender_name: Optional[str] = None | ||
| "Name of the sender of the quoted message" | ||
|
|
||
| preview: Optional[str] = None | ||
| "Preview text of the quoted message" | ||
|
|
||
| time: Optional[str] = None | ||
| "Timestamp of the quoted message (IC3 epoch value, e.g. '1772050244572'). Inbound only." | ||
|
|
||
| is_reply_deleted: Optional[bool] = None | ||
| "Whether the quoted reply has been deleted" | ||
|
|
||
| validated_message_reference: Optional[bool] = None | ||
| "Whether the message reference has been validated" | ||
|
|
||
|
|
||
| @experimental("ExperimentalTeamsQuotedReplies") | ||
| class QuotedReplyEntity(CustomBaseModel): | ||
| """Entity containing quoted reply information | ||
|
|
||
| .. warning:: Coming Soon | ||
| This API is coming soon and may change in the future. | ||
| Diagnostic: ExperimentalTeamsQuotedReplies | ||
| """ | ||
|
|
||
| type: Literal["quotedReply"] = "quotedReply" | ||
| "Type identifier for quoted reply" | ||
|
|
||
| quoted_reply: QuotedReplyData | ||
| "The quoted reply data" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.