Skip to content

Commit ed7c5bf

Browse files
Michael Mieleemgrol
authored andcommitted
mm/fixing issues (MicrosoftDocs#1697)
1 parent c2f82be commit ed7c5bf

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

articles/includes/snippet-channeldata.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,49 @@ This snippet shows an example of a `channelData` property that specifies a chann
456456
}
457457
```
458458

459+
## Adding a bot to Teams
460+
461+
Bots added to a team become another team member, who can be `@mentioned` as part of the conversation. In fact, bots only receive messages when they are `@mentioned`, so other conversations on the channel are not sent to the bot.
462+
For more information, see [Channel and Group chat conversations with a Microsoft Teams bot](https://aka.ms/bots-con-channel).
463+
464+
Because bots in a group or channel respond only when they are mentioned (`@botname`) in a message, every message received by a bot in a group channel contains its own name, and you must ensure your message parsing handles that. In addition, bots can parse out other users mentioned and mention users as part of their messages.
465+
466+
### Check for and strip @bot mention
467+
468+
```csharp
469+
470+
Mention[] m = sourceMessage.GetMentions();
471+
var messageText = sourceMessage.Text;
472+
473+
for (int i = 0;i < m.Length;i++)
474+
{
475+
if (m[i].Mentioned.Id == sourceMessage.Recipient.Id)
476+
{
477+
//Bot is in the @mention list.
478+
//The below example will strip the bot name out of the message, so you can parse it as if it wasn't included. Note that the Text object will contain the full bot name, if applicable.
479+
if (m[i].Text != null)
480+
messageText = messageText.Replace(m[i].Text, "");
481+
}
482+
}
483+
```
484+
485+
```javascript
486+
var text = message.text;
487+
if (message.entities) {
488+
message.entities
489+
.filter(entity => ((entity.type === "mention") && (entity.mentioned.id.toLowerCase() === botId)))
490+
.forEach(entity => {
491+
text = text.replace(entity.text, "");
492+
});
493+
text = text.trim();
494+
}
495+
496+
```
497+
498+
> [!IMPORTANT]
499+
> Adding a bot by GUID, for anything other than testing purposes, is not recommended. Doing so severely limits the functionality of a bot. Bots in production should be added to Teams as part of an app. See [Create a bot](https://docs.microsoft.com/microsoftteams/platform/concepts/bots/bots-create) and [Test and debug your Microsoft Teams bot](https://docs.microsoft.com/microsoftteams/platform/concepts/bots/bots-test).
500+
501+
459502
## Additional resources
460503

461504
- [Entities and activity types](../bot-service-activities-entities.md)

0 commit comments

Comments
 (0)