Messages in bot conversations - Teams (2024)

  • Article
  • 9 minutes to read

Each message in a conversation is an Activity object of type messageType: message. When a user sends a message, Teams posts the message to your bot. Teams sends a JSON object to your bot's messaging endpoint. Your bot examines the message to determine its type and responds accordingly.

Basic conversations are handled through the Bot Framework connector, a single REST API. This API enables your bot to communicate with Teams and other channels. The Bot Builder SDK provides the following features:

  • Easy access to the Bot Framework connector.
  • Additional functionality to manage conversation flow and state.
  • Simple ways to incorporate cognitive services, such as natural language processing (NLP).

Your bot receives messages from Teams using the Text property and it sends single or multiple message responses to the users.

For more information, see User attribution for bot messages

Receive a message

To receive a text message, use the Text property of the Activity object. In the bot's activity handler, use the turn context object's Activity to read a single message request.

The following code shows an example of receiving a message:

  • C#
  • TypeScript
  • Python
  • JSON
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken){ await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: {turnContext.Activity.Text}"), cancellationToken);}

Send a message

To send a text message, specify the string you want to send as the activity. In the bot's activity handler, use the turn context object's SendActivityAsync method to send a single message response. Use the object's SendActivitiesAsync method to send multiple responses at once.

The following code shows an example of sending a message when a user is added to a conversation:

  • C#
  • TypeScript
  • Python
  • JSON
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken){ await turnContext.SendActivityAsync(MessageFactory.Text($"Hello and welcome!"), cancellationToken);}

Note

Message splitting occurs when a text message and an attachment are sent in the same activity payload. This activity is split into separate activities by Microsoft Teams, one with just a text message and the other with an attachment. As the activity is split, you do not receive the message ID in response, which is used to update or delete the message proactively. It is recommended to send separate activities instead of depending on message splitting.

Messages sent between users and bots include internal channel data within the message. This data allows the bot to communicate properly on that channel. The Bot Builder SDK allows you to modify the message structure.

Send suggested actions

Suggested actions enable your bot to present buttons that the user can select to provide input. Suggested actions enhance user experience by enabling the user to answer a question or make a choice with selection of a button, rather than typing a response with a keyboard.The buttons remain visible and accessible to the user in the rich cards even after user makes a selection whereas for suggested actions, buttons aren't available. This prevents the user from selection of stale buttons within a conversation.

To add suggested actions to a message, set the suggestedActions property of the Activity object to specify the list of CardAction objects that represent the buttons to be presented to the user. For more information, see SugestedActions

The following is an example for implementation and experience of suggested actions:

"suggestedActions": { "actions": [ { "type": "imBack", "title": "Action 1", "value": "Action 1" }, { "type": "imBack", "title": "Action 2", "value": "Action 2" } ], "to": [<list of recepientIds>] }

Messages in bot conversations - Teams (1)

Note

  • SuggestedActions are only supported for one-on-one chat bots and text based messages and not for Adaptive Cards or attachments.
  • Currently imBack is the only supported action type and Teams display up to three suggested actions.

Teams channel data

The channelData object contains Teams-specific information and is a definitive source for team and channel IDs. Optionally, you can cache and use these IDs as keys for local storage. The TeamsActivityHandler in the SDK pulls out important information from the channelData object to make it easily accessible. However, you can always access the original data from the turnContext object.

The channelData object isn't included in messages in personal conversations, as these take place outside of a channel.

A typical channelData object in an activity sent to your bot contains the following information:

  • eventType: Teams event type passed only in cases of channel modification events.
  • tenant.id: Microsoft Azure Active Directory (Azure AD) tenant ID passed in all contexts.
  • team: Passed only in channel contexts, not in personal chat.
    • id: GUID for the channel.
    • name: Name of the team passed only in cases of team rename events.
  • channel: Passed only in channel contexts, when the bot is mentioned or for events in channels in teams, where the bot has been added.
    • id: GUID for the channel.
    • name: Channel name passed only in cases of channel modification events.
  • channelData.teamsTeamId: Deprecated. This property is only included for backward compatibility.
  • channelData.teamsChannelId: Deprecated. This property is only included for backward compatibility.

Example channelData object (channelCreated event)

The following code shows an example of channelData object:

"channelData": { "eventType": "channelCreated", "tenant": { "id": "72f988bf-86f1-41af-91ab-2d7cd011db47" }, "channel": { "id": "19:693ecdb923ac4458a5c23661b505fc84@thread.skype", "name": "My New Channel" }, "team": { "id": "19:693ecdb923ac4458a5c23661b505fc84@thread.skype" }}

Message content

Messages received from or sent to your bot can include different types of message content.

FormatFrom user to botFrom bot to userNotes
Rich text✔️✔️Your bot can send rich text, pictures, and cards. Users can send rich text and pictures to your bot.
Pictures✔️✔️Maximum 1024 × 1024 pixels and 1 MB in PNG, JPEG, or GIF format. Animated GIF isn't supported.
Cards✔️See the Teams card reference for supported cards.
Emojis✔️✔️Teams currently supports emojis through UTF-16, such as U+1F600 for grinning face.

Notifications to your message

You can also add notifications to your message using the Notification.Alert property. Notifications alert users about new tasks, mentions, and comments. These alerts are related to what users are working on or what they must look at by inserting a notice into their activity feed. For notifications to trigger from your bot message, set the TeamsChannelData objects Notification.Alert property to true. Whether or not a notification is raised depends on the individual user's Teams settings and you can't override these settings. The notification type is either a banner, or both a banner and an email.

Note

The Summary field displays any text from the user as a notification message in the feed.

The following code shows an example of adding notifications to your message:

  • C#
  • TypeScript
  • Python
  • JSON
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken){ var message = MessageFactory.Text("You'll get a notification, if you've turned them on."); message.TeamsNotifyUser(); await turnContext.SendActivityAsync(message);}

To enhance your message, you can include pictures as attachments to that message.

Picture messages

Pictures are sent by adding attachments to a message. For more information on attachments, see add media attachments to messages.

Pictures can be at most 1024×1024 MB and 1 MB in PNG, JPEG, or GIF format. Animated GIF isn't supported.

Specify the height and width of each image by using XML. In markdown, the image size defaults to 256×256. For example:

  • Use: <img src="http://aka.ms/Fo983c" alt="Duck on a rock" height="150" width="223"></img>.
  • Don't use: ![Duck on a rock](http://aka.ms/Fo983c).

A conversational bot can include Adaptive Cards that simplify business workflows. Adaptive Cards offer rich customizable text, speech, images, buttons, and input fields.

Adaptive Cards

Adaptive Cards can be authored in a bot and shown in multiple apps such as Teams, your website, and so on. For more information, see Adaptive Cards.

The following code shows an example of sending a simple Adaptive Card:

{ "type": "AdaptiveCard", "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.5", "body": [ { "items": [ { "size": "large", "text": " Simple Adaptivecard Example with a Textbox", "type": "TextBlock", "weight": "bolder", "wrap": true }, ], "spacing": "extraLarge", "type": "Container", "verticalContentAlignment": "center" } ]}

Form completion feedback

Form completion message appears in Adaptive Cards while sending a response to the bot. The message can be of two types, error or success:

  • Error: When a response sent to the bot is unsuccessful, Something went wrong, Try again message appears.

    Messages in bot conversations - Teams (2)

  • Success: When a response sent to the bot is successful, Your response was sent to the app message appears.

    Messages in bot conversations - Teams (3)

    You can select Close or switch chat to dismiss the message.

    If you don't want to display the success message, set the attribute hide to true in the msTeams feedback property. Following is an example:

     "content": { "type": "AdaptiveCard", "title": "Card with hidden footer messages", "version": "1.0", "actions": [ { "type": "Action.Submit", "title": "Submit", "msTeams": { "feedback": { "hide": true } } } ] } 

For more information on cards and cards in bots, see cards documentation.

Status code responses

Following are the status codes and their error code and message values:

Status codeError code and message valuesDescription
403Code: ConversationBlockedByUser
Message: User blocked the conversation with the bot.
User blocked the bot in 1:1 chat or a channel through moderation settings.
403Code: BotNotInConversationRoster
Message: The bot isn't part of the conversation roster.
The bot isn't part of the conversation.
403Code: BotDisabledByAdmin
Message: The tenant admin disabled this bot.
Tenant blocked the bot.
401Code: BotNotRegistered
Message: No registration found for this bot.
The registration for this bot wasn't found.
412Code: PreconditionFailed
Message: Precondition failed, please try again.
A precondition failed on one of our dependencies due to multiple concurrent operations on the same conversation.
404Code: ConversationNotFound
Message: Conversation not found.
The conversation wasn't found.
413Code: MessageSizeTooBig
Message: Message size too large.
The size on the incoming request was too large.
429Code: Throttled
Message: Too many requests. Also returns when to retry after.
Too many requests were sent by the bot. For more information, see rate limit.

Code sample

Sample nameDescription.NETCoreNode.jsPython
Teams conversation botMessaging and conversation event handling.ViewViewView

Next step

Bot command menus

See also

  • Send proactive messages
  • Subscribe to conversation events
  • Send and receive files through the bot
  • Send tenant ID and conversation ID to the request headers of the bot
Messages in bot conversations - Teams (2024)

FAQs

What is bot conversation in Teams? ›

Bots are apps that have a conversational interface. You can interact with a bot using text, interactive cards, and speech. A bot behaves differently in a channel or group chat conversation and in a one-to-one conversation. Conversations are handled through the Bot Framework connector. See conversation basics.

How do you use team chat bots? ›

Allow users to add bot to a team
  1. On the side pane, go to Manage > Channels.
  2. Select Microsoft Teams.
  3. Select Edit details.
  4. Select Allow your users to add this bot to a team.
  5. Select Save.
Jul 26, 2022

How many bots are available in MS Teams to help increase productivity? ›

21 Bots For Microsoft Teams To Reinvent Your Organization's Productivity.

How do you clean up the conversations team? ›

Delete a chat in Teams for personal and small business use
  1. From the Chat tab, find the chat you want to delete. Note: You can delete one-on-one, group, and meeting chats.
  2. Tap and hold the chat.
  3. Tap Delete. and then confirm that you want to delete it by tapping OK. You'll then leave the meeting or chat.

Can bots send text messages? ›

With text bots, you aren't limited to just SMS, but can also send multimedia messages to include videos, GIFs, and audio. Multimedia messaging service (MMS) can improve customers' texting experience and is often easier than sending texts because MMS requires a single media file.

Does Microsoft Teams keep a conversation history? ›

In Teams for Business, unless you change the retention policy, chat history is already enabled and chat messages are saved indefinitely.

How do you automate Teams messages? ›

Flow setup
  1. Sign in to Power Automate.
  2. Select My flows > New > Automated cloud flow.
  3. Enter a name for your flow.
  4. Select the When a file is created (properties only) trigger.
  5. Select Create.
  6. Set up your trigger by choosing a SharePoint site and Folder ID that you want to monitor.
Aug 1, 2022

How do Teams test bots? ›

Open Microsoft Teams, on the Chat pane, select the Add chat icon. In To:, paste your bot's Microsoft App ID. The app ID must resolve to your bot name. Select your bot and send a message to initiate a conversation.

What can bots do? ›

Bots are normally used to automate certain tasks, meaning they can run without specific instructions from humans. An organization or individual can use a bot to replace a repetitive task that a human would otherwise have to perform. Bots are also much faster at these tasks than humans.

Can my employer see deleted Teams messages? ›

However, is it possible for an employer of that company to look at deleted Microsoft Teams messages, and if possible, what would they potentially use to see those messages? The simple answer is yes: a company can and does have the right to monitor information even if it has been deleted from Microsoft Teams.

Does deleting a message in Teams Delete for everyone? ›

Does deleting a message in Teams delete it for everyone? If you're worried that when you delete chats in Microsoft Teams, other people will still see them, worry not. Deleting your own message in Microsoft Teams will remove it from the chat. However, your colleagues will be able to see that you deleted something.

How long are Teams chats saved? ›

Content paths for retain-only retention policy

When a user deletes a Teams message, although the message disappears from the Teams app, the message doesn't go into the SubstrateHolds folder for 21 days. The message is stored in the SubstrateHolds folder for at least 1 day.

How do you use daily bot? ›

DailyBot for Slack — daily check-ins, agile stand-ups, polls, mood ...

How do you make a bot call someone? ›

To setup your PhoneBot to receive calls first select one of your numbers. A new panel will appear to setup the script you will use to answer your phone and the Log of the calls made to your phone. Select the script, press "Save" and you are ready to go. The Phonebot will load that script when someone calls your number.

How do I create a chat bot for my team? ›

Create a new bot in a team
  1. Select Start now on the Home page.
  2. Pick which team you want the bot to be managed by. Let's create the bot in the Contoso HR Team since you are part of Contoso HR. ...
  3. Fill in the bot name and language in the bot creation window. Let's use HR Support Bot for the name. ...
  4. Select Create.
Feb 15, 2022

What are chat bot messages? ›

A SMS chatbot is an automated conversation partner via text messaging. It facilitates a conversation between a person and a computer. Usually, you will have a conversation with another person via text messaging. But with chatbots, you are not talking to a human, but to a computer.

How do you tell if you're chatting with a bot? ›

The most common way to tell if an account is fake is to check out the profile. The most rudimentary bots lack a photo, a link, or any bio. More sophisticated ones might use a photo stolen from the web, or an automatically generated account name. Using human language is still incredibly hard for machines.

Can admin read Teams messages? ›

The quick answer is yes -- IT administrators can monitor employees' messages in Microsoft Teams.

Are Teams conversations private? ›

Team channels are places where everyone on the team can have open conversations. Private chats are only visible to those people in the chat.

Where are Teams chat messages stored? ›

Microsoft Teams stores chat data in primary and secondary storage locations for compliance. The chat service stores its messages in Azure Cosmos DB. Compliance records for messages are stored in group and personal Exchange Online mailboxes under a hidden folder in the mailbox.

How do you trigger team flow? ›

Create the flow
  1. Sign in to Power Automate, and then select My flows > New > Instant-from blank.
  2. Enter a name for your flow.
  3. Select the For a selected message trigger.
  4. Select Create.
Feb 15, 2022

Can I send a recurring message in Teams? ›

To do this, you will want to click on the down arrow next to the “Send” button and click “Send Later.” Now, you can choose the date and time that you want your message to be posted in Teams. Once the date and time are chosen, just click send later!

Is Power Automate free with Teams? ›

Free plan. If you sign in with work or school email address, you get all Power Automate capabilities included in Office 365.

What is chatbot example? ›

Make it accessible across platforms: Chatbots that span cross-platform perform better than one channel. For example, you can order through the Domino's Pizza Bot by Slack, Messenger, Apple Watch, Mobile App, Twitter (by Pizza Emoji), Smart Home Assistants, and more.

What can bots do? ›

Bots are normally used to automate certain tasks, meaning they can run without specific instructions from humans. An organization or individual can use a bot to replace a repetitive task that a human would otherwise have to perform. Bots are also much faster at these tasks than humans.

How do you create a chat bot in Microsoft Teams? ›

Create a new bot in a team
  1. Select Start now on the Home page.
  2. Pick which team you want the bot to be managed by. Let's create the bot in the Contoso HR Team since you are part of Contoso HR. ...
  3. Fill in the bot name and language in the bot creation window. Let's use HR Support Bot for the name. ...
  4. Select Create.
Aug 3, 2022

How do you make a bot call someone? ›

To setup your PhoneBot to receive calls first select one of your numbers. A new panel will appear to setup the script you will use to answer your phone and the Log of the calls made to your phone. Select the script, press "Save" and you are ready to go. The Phonebot will load that script when someone calls your number.

Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 6435

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.