-
Notifications
You must be signed in to change notification settings - Fork 262
[Docs] Add in-depth guide for message reactions #2718
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
rido-min
wants to merge
1
commit into
main
Choose a base branch
from
feat/msg-reactions
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.
+272
−0
Open
Changes from all commits
Commits
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
80 changes: 80 additions & 0 deletions
80
teams.md/src/components/include/in-depth-guides/message-reactions/csharp.incl.md
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,80 @@ | ||
| <!-- adding-reaction --> | ||
|
|
||
| ```csharp | ||
| app.OnMessage(async context => | ||
| { | ||
| await context.Send("Hello! I'll react to this message."); | ||
|
|
||
| // Add a reaction to the incoming message | ||
| await context.Api.Conversations.Reactions.AddAsync( | ||
| context.Activity.Conversation.Id, | ||
| context.Activity.Id, | ||
| ReactionType.Like | ||
| ); | ||
| }); | ||
| ``` | ||
|
|
||
| <!-- removing-reaction --> | ||
|
|
||
| ```csharp | ||
| app.OnMessage(async context => | ||
| { | ||
| // First, add a reaction | ||
| await context.Api.Conversations.Reactions.AddAsync( | ||
| context.Activity.Conversation.Id, | ||
| context.Activity.Id, | ||
| ReactionType.Heart | ||
| ); | ||
|
|
||
| // Wait a bit, then remove it | ||
| await Task.Delay(2000); | ||
| await context.Api.Conversations.Reactions.DeleteAsync( | ||
| context.Activity.Conversation.Id, | ||
| context.Activity.Id, | ||
| ReactionType.Heart | ||
| ); | ||
| }); | ||
| ``` | ||
|
|
||
| <!-- reaction-types --> | ||
|
|
||
| The following reaction types are available: | ||
|
|
||
| - `ReactionType.Like` — 👍 | ||
| - `ReactionType.Heart` — ❤️ | ||
| - `ReactionType.Checkmark` — ✅ | ||
| - `ReactionType.Hourglass` — ⏳ | ||
| - `ReactionType.Pushpin` — 📌 | ||
| - `ReactionType.Exclamation` — ❗ | ||
| - `ReactionType.Laugh` — 😆 | ||
| - `ReactionType.Surprise` — 😮 | ||
| - `ReactionType.Sad` — 🙁 | ||
| - `ReactionType.Angry` — 😠 | ||
|
|
||
| You can also use custom reaction types by creating a new `ReactionType` instance: | ||
|
|
||
| ```csharp | ||
| // Use a custom emoji reaction | ||
| var customReaction = new ReactionType("1f44b_wavinghand-tone4"); | ||
|
|
||
| await context.Api.Conversations.Reactions.AddAsync( | ||
| context.Activity.Conversation.Id, | ||
| context.Activity.Id, | ||
| customReaction | ||
| ); | ||
| ``` | ||
|
|
||
| <!-- advanced-usage --> | ||
|
|
||
| For advanced scenarios where you need to use a custom service URL or access the HTTP client directly, you can use the `ApiClient.Client` property: | ||
|
|
||
| ```csharp | ||
| // Access the underlying HTTP client for custom requests | ||
| var api = new ApiClient(context.Activity.ServiceUrl, context.Api.Client); | ||
|
|
||
| await api.Conversations.Reactions.AddAsync( | ||
| context.Activity.Conversation.Id, | ||
| context.Activity.Id, | ||
| ReactionType.Like | ||
| ); | ||
| ``` |
79 changes: 79 additions & 0 deletions
79
teams.md/src/components/include/in-depth-guides/message-reactions/python.incl.md
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,79 @@ | ||
| <!-- adding-reaction --> | ||
|
|
||
| ```python | ||
| @app.on_message | ||
| async def handle_message(ctx: ActivityContext[MessageActivity]): | ||
| await ctx.send("Hello! I'll react to this message.") | ||
|
|
||
| # Add a reaction to the incoming message | ||
| await ctx.api.conversations.reactions.add( | ||
| ctx.activity.conversation.id, | ||
| ctx.activity.id, | ||
| 'like' | ||
| ) | ||
| ``` | ||
|
|
||
| <!-- removing-reaction --> | ||
|
|
||
| ```python | ||
| import asyncio | ||
|
|
||
| @app.on_message | ||
| async def handle_message(ctx: ActivityContext[MessageActivity]): | ||
| # First, add a reaction | ||
| await ctx.api.conversations.reactions.add( | ||
| ctx.activity.conversation.id, | ||
| ctx.activity.id, | ||
| 'heart' | ||
| ) | ||
|
|
||
| # Wait a bit, then remove it | ||
| await asyncio.sleep(2) | ||
| await ctx.api.conversations.reactions.delete( | ||
| ctx.activity.conversation.id, | ||
| ctx.activity.id, | ||
| 'heart' | ||
| ) | ||
| ``` | ||
|
|
||
| <!-- reaction-types --> | ||
|
|
||
| The following reaction types are available: | ||
|
|
||
| - `'like'` — 👍 | ||
| - `'heart'` — ❤️ | ||
| - `'checkmark'` — ✅ | ||
| - `'hourglass'` — ⏳ | ||
| - `'pushpin'` — 📌 | ||
| - `'exclamation'` — ❗ | ||
| - `'laugh'` — 😆 | ||
| - `'surprise'` — 😮 | ||
| - `'sad'` — 🙁 | ||
| - `'angry'` — 😠 | ||
|
|
||
| You can also use custom emoji reactions by providing the emoji code: | ||
|
|
||
| ```python | ||
| # Use a custom emoji reaction | ||
| await ctx.api.conversations.reactions.add( | ||
| ctx.activity.conversation.id, | ||
| ctx.activity.id, | ||
| '1f44b_wavinghand-tone4' | ||
| ) | ||
| ``` | ||
|
|
||
| <!-- advanced-usage --> | ||
|
|
||
| For advanced scenarios, you can access the API client from the context: | ||
|
|
||
| ```python | ||
| # The API client is available through the context | ||
| api = ctx.api | ||
|
|
||
| # Use reactions API | ||
| await api.conversations.reactions.add( | ||
| conversation_id, | ||
| activity_id, | ||
| 'like' | ||
| ) | ||
| ``` | ||
61 changes: 61 additions & 0 deletions
61
....md/src/components/include/in-depth-guides/message-reactions/typescript.incl.md
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,61 @@ | ||
| <!-- adding-reaction --> | ||
|
|
||
| ```typescript | ||
| app.on('message', async ({ activity, api, send }) => { | ||
| await send("Hello! I'll react to this message."); | ||
|
|
||
| // Add a reaction to the incoming message | ||
| await api.conversations.reactions.add(activity.conversation.id, activity.id, 'like'); | ||
| }); | ||
| ``` | ||
|
|
||
| <!-- removing-reaction --> | ||
|
|
||
| ```typescript | ||
| app.on('message', async ({ activity, api }) => { | ||
| // First, add a reaction | ||
| await api.conversations.reactions.add(activity.conversation.id, activity.id, 'heart'); | ||
|
|
||
| // Wait a bit, then remove it | ||
| await new Promise((resolve) => setTimeout(resolve, 2000)); | ||
| await api.conversations.reactions.delete(activity.conversation.id, activity.id, 'heart'); | ||
| }); | ||
| ``` | ||
|
|
||
| <!-- reaction-types --> | ||
|
|
||
| The following reaction types are available: | ||
|
|
||
| - `'like'` — 👍 | ||
| - `'heart'` — ❤️ | ||
| - `'checkmark'` — ✅ | ||
| - `'hourglass'` — ⏳ | ||
| - `'pushpin'` — 📌 | ||
| - `'exclamation'` — ❗ | ||
| - `'laugh'` — 😆 | ||
| - `'surprise'` — 😮 | ||
| - `'sad'` — 🙁 | ||
| - `'angry'` — 😠 | ||
|
|
||
| You can also use custom emoji reactions by providing the emoji code: | ||
|
|
||
| ```typescript | ||
| // Use a custom emoji reaction | ||
| await api.conversations.reactions.add( | ||
| activity.conversation.id, | ||
| activity.id, | ||
| '1f44b_wavinghand-tone4' | ||
| ); | ||
| ``` | ||
|
|
||
| <!-- advanced-usage --> | ||
|
|
||
| For advanced scenarios, you can access the underlying HTTP client or create a custom API client instance: | ||
|
|
||
| ```typescript | ||
| // The API client is available through the context | ||
| const { api } = context; | ||
|
|
||
| // Use reactions API | ||
| await api.conversations.reactions.add(conversationId, activityId, 'like'); | ||
| ``` |
52 changes: 52 additions & 0 deletions
52
teams.md/src/pages/templates/in-depth-guides/message-reactions.mdx
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,52 @@ | ||
| --- | ||
| sidebar_position: 8 | ||
| title: Message Reactions | ||
| sidebar_label: Message Reactions | ||
| summary: Guide to adding and removing message reactions in Teams applications, including available reaction types and best practices for implementing reaction functionality. | ||
| --- | ||
|
|
||
| # Message Reactions | ||
|
|
||
| Message reactions allow your bot to add emoji reactions to messages in Teams conversations. This feature enables your bot to provide quick, non-verbal feedback to user messages, enhancing the interactive experience. | ||
|
|
||
| ## Adding a Reaction | ||
|
|
||
| To add a reaction to a message, use the `Reactions` API available through the conversations client: | ||
|
|
||
| <LanguageInclude section="adding-reaction" /> | ||
|
|
||
| ## Removing a Reaction | ||
|
|
||
| You can also remove reactions that your bot has added: | ||
|
|
||
| <LanguageInclude section="removing-reaction" /> | ||
|
|
||
| ## Available Reaction Types | ||
|
|
||
| <LanguageInclude section="reaction-types" /> | ||
|
|
||
| :::info Custom Reactions | ||
| In addition to the standard reaction types listed above, you can use any valid Teams emoji reaction code. Teams supports a wide variety of emoji reactions beyond the standard set. | ||
| ::: | ||
|
|
||
| ## Advanced Usage | ||
|
|
||
| <LanguageInclude section="advanced-usage" /> | ||
|
|
||
| ## Best Practices | ||
|
|
||
| When working with message reactions, consider the following: | ||
|
|
||
| - **Use reactions sparingly**: Reactions work best when used to provide meaningful feedback rather than reacting to every message. | ||
| - **Consider the context**: Different reaction types convey different meanings. Choose reactions that align with your bot's purpose and the conversation context. | ||
| - **Handle errors gracefully**: Reaction operations may fail (e.g., if the message no longer exists). Always handle potential errors appropriately. | ||
| - **Be aware of rate limits**: Like other bot operations, reaction operations are subject to Teams API rate limits. | ||
|
|
||
| ## Differences from Feedback | ||
|
|
||
| Message reactions are different from the [feedback](./feedback) feature: | ||
|
|
||
| - **Reactions** are quick emoji responses that your bot adds to messages programmatically | ||
| - **Feedback** are interactive UI components (like/dislike buttons) that users can click to provide structured feedback on bot responses | ||
|
|
||
| Use reactions when your bot wants to acknowledge or respond to messages with emoji. Use feedback when you want to collect user opinions about your bot's responses. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these well known codes?