-
Notifications
You must be signed in to change notification settings - Fork 20
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
21
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
21 commits
Select commit
Hold shift + click to select a range
edc6de4
Remove with_reply_to_id
9902d1b
Quoted reply features and unit tests
3129d41
Fix up
bf90f87
Quoted replies sample
1443ccf
Mark as experimental and remove replyToId change
e82c2fb
Update examples
a19adfb
Fix pyright errors in quote_reply() type narrowing
93a2e09
Fix tests
ad76e3b
PR Feedback
520a7aa
Update sample README.md
f564d03
Add docstring for time field format (IC3 epoch)
0770e7c
Fix test string
21f1b5e
Have reply defer quote_reply
b50c06a
Move stamping to model layer
e72a39a
Update to quote and verbiage improvements
corinagum d6203ea
Add TENANT_ID to sample env vars
corinagum 4f9d471
Separate copyright from description in example docstring
corinagum 6d4bc73
Rename example
corinagum d71fb16
Change preview wording to coming soon
corinagum 7618710
Update preview wording to Coming soon
corinagum 282f981
Fix missing return in add_feedback method
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.
|
||
| ``` | ||
|
|
||
| ## 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.
|
||
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
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" |
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.