-
Notifications
You must be signed in to change notification settings - Fork 16
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
16
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
16 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 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: Quoted Replies | ||
|
|
||
| A bot that demonstrates quoted reply features in Microsoft Teams — referencing previous messages when sending responses. | ||
|
|
||
| ## 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/quoted-replies | ||
| pip install -e . | ||
| python src/main.py | ||
|
|
||
| # Or with uv: | ||
| uv run python src/main.py | ||
| ``` | ||
|
|
||
| ## 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 = "quoted-replies" | ||
| version = "0.1.0" | ||
| description = "Quoted replies example - demonstrates quoting 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,114 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
|
|
||
| Example: Quoted Replies | ||
|
|
||
| A bot that demonstrates quoted reply features in Microsoft Teams. | ||
| Tests reply(), quote(), add_quote(), and get_quoted_messages(). | ||
| """ | ||
|
|
||
| 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( | ||
| "**Quoted Replies 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
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:: Preview | ||
| This API is in preview 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:: Preview | ||
| This API is in preview 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.