在 MS 团队中 @mention Ms bot 中的用户

@mention a user in Ms bot with in MS teams

我有一个使用 ms bot v3 nodejs sdk 构建的机器人。我通过使用深度 link 进行 1:1 对话将此机器人添加到我的 MS 团队中,如下所示

https://teams.microsoft.com/l/chat/0/0?users=28:{BotID}

我想为这个机器人添加@mentioning 用户功能,我想看看我是否能得到一些关于如何做到这一点的例子?

不确定作为应用程序侧面加载机器人是否允许。

单用户对话中的机器人不需要 @ 提及 - 用户只需键入命令即可。 Bots in channel conversations 要求用户@提及机器人以在频道中调用它。

为了将您的机器人访问频道,您需要在 App Manifest. Please use Teams App Studio to create your app manifest. You need to Upload an app package to Microsoft Teams 中将团队范围添加到您的机器人以查看您的应用程序。

您可以将您的机器人作为应用上传,为此您需要创建一个 JSON 格式的应用清单,如下所示。

{
"$schema": "https://statics.teams.microsoft.com/sdk/v1.3.0-beta.2/manifest/MicrosoftTeams.schema.json",
"manifestVersion": "1.3",
"version": "1.3",
"id": "c9edb618-c5de-4be2-**f4-74c1*******1",
"packageName": "com.example.tcafebot",
"developer": {
    "name": "Harsh Raj",
    "websiteUrl": "https://www.sdharshraj.github.io",
    "privacyUrl": "https://privacy.microsoft.com/en-us/privacystatement",
    "termsOfUseUrl": "https://www.botframework.com/Content/Microsoft-Bot-Framework-Preview-Online-Services-Agreement.htm"
},
"name": {
    "short": "TCafeBot",
    "full": "Tea and Coffee bot"
},
"description": {
    "short": "TCafeBot - a bot helping you with twiter.",
    "full": "It will help you find a user or tweets from twiter. Also it can read text from image or even it can tell what is there in a photo."
},
"icons": {
    "outline": "bot_blue.png",
    "color": "bot_blue.png"
},
"accentColor": "#0079bf",
"configurableTabs": [{
    "configurationUrl": "https://contoso.com/teamstab/configure",
    "canUpdateConfiguration": true,
    "scopes": [
        "team",
        "groupchat"
    ]
}],
"staticTabs": [{
        "contentUrl": "https://harshcognitivebot.azurewebsites.net/loading",
        "entityId": "1on1test123",
        "name": "Bot Info",
        "scopes": [
            "team",
            "personal"
        ]
    },
    {
        "contentUrl": "https://harshcognitivebot.azurewebsites.net/tab-auth/simple",
        "entityId": "simpleAuth",
        "name": "Simple Auth",
        "scopes": [
            "personal"
        ]
    },
    {
        "contentUrl": "https://harshcognitivebot.azurewebsites.net/tab-auth/silent",
        "entityId": "silentAuth",
        "name": "Silent Auth",
        "scopes": [
            "personal"
        ]
    }
],
"bots": [{
    "botId": "c9edb618-c5de-4be2-**f4-74c1*******1",
    "scopes": [
        "team",
        "personal",
        "groupchat"
    ],
    "commandLists": [{
            "scopes": [
                "team"
            ],
            "commands": [{
                    "title": "hello",
                    "description": "Runs the simplest hello dialog"
                }
            ]
        },
        {
            "scopes": [
                "personal"
            ],
            "commands": [{
                    "title": "hello",
                    "description": "Runs the simplest hello dialog"
                }
            ]
        }
    ]
}],
"composeExtensions": [{
    "botId": "c9edb618-c5de-4be2-**f4-74c1*******1",
    "canUpdateConfiguration": true,
    "commands": [{
        "id": "search123",
        "description": "Find a card",
        "title": "Search",
        "initialRun": true,
        "parameters": [{
            "title": "query123",
            "name": "query",
            "description": "Search string"
        }]
    }]
}],
"permissions": [
    "identity",
    "messageTeamMembers"
],
"validDomains": [
    "787c30bb.ngrok.io"
]

}

并保留一个图标,其名称在清单文件中给出。

然后您需要将这两个文件(Manifest 和 Icon)压缩成一个 zip 文件。请注意,这两个文件不应在任何文件夹中,您应该直接将这两个文件压缩。

然后转到 Team App 并select上传自定义应用程序,您可以在那里浏览您的 zip 文件。

也可以参考这个Link

获取团队详细信息

要使用@mention,请将您的机器人添加到 Teams 频道:

使用 Teams App Studio 创建 App Manifest zip 文件。详情 here.

将 App Manifest zip 文件上传到 Teams 频道。转到团队频道 -> 管理团队 -> 应用程序 -> 上传自定义应用程序 link(在底部)

您的机器人现在可以在频道中使用,用户可以使用@mention 与其交谈。

有关 Teams 中机器人的重要提示 - 在机器人收到文本后(在 MessageController.cs 中),在将其发送到 LUIS 等之前删除@mention

            if (activity.ChannelId == ChannelIds.Msteams)
            {
                //remove bot @mention
                if (activity.Text.Contains("<at>"))
                {
                    activity.Text = Regex.Replace(activity.Text, "<at>.*</at>", "", RegexOptions.IgnoreCase).Trim();
                }
            }

机器人和用户只能提及同一对话的成员。

  • 在频道中,您可以提及团队中的任何用户
  • 在 1:1 聊天中,您可以提及其他用户
  • 在群聊中,您可以提及聊天中的任何用户

现在机器人和用户都不能提及非对话成员的任意用户。

上面的示例 "Hello @PersonB and @PersonC please take care of this ticket" 如果 PersonB 和 PersonC 是团队的一部分(如果在频道中)或群聊,则可以工作,但不能与 1:1 聊天机器人。

您问题中的深层链接创建了一个 1:1 聊天机器人,因此不会提及其他用户:(