简体   繁体   English

如何将我的机器人变成 MS Teams 应用程序

[英]How can I turn my bot into a MS Teams app

I made a normal bot by using Microsoft Bot Framework and has deployed it to the Azure portal.我使用 Microsoft Bot Framework 制作了一个普通机器人,并将其部署到 Azure 门户。

How can I possibly make it a Teams app other than channeling to Teams, for example, make it a Teams app package.除了引导到 Teams 之外,我如何才能使其成为 Teams 应用程序,例如,使其成为 Teams 应用程序 package。 I checked some sample code on Github and noticed that general bots are a bit different from Teams bots, for example, general bots extend ActivityHandler but Teams bots extend TeamsActivityHandler.我检查了 Github 上的一些示例代码,并注意到通用机器人与团队机器人有点不同,例如,通用机器人扩展了 ActivityHandler,但团队机器人扩展了 TeamsActivityHandler。 May I ask how can I turn my bot into a Teams app?请问如何将我的机器人变成 Teams 应用程序? Do I need to alter the code of the bot I made a lot?我需要更改我制作的机器人的代码吗?

Thanks谢谢

With a few exceptions, you don't really need to make changes to your bot code to deploy to Teams channel.除少数例外情况外,您实际上不需要更改机器人代码即可部署到 Teams 频道。 However, I do think there are a few things you should be aware of and consider in your development.但是,我确实认为在开发过程中应该注意和考虑一些事情。 First of all, I'm going to assume you have or know how to turn on the channel from the Bot Service.首先,我假设您已经或知道如何从机器人服务打开频道。 Once you have done that, you can test your bot in Teams without even creating a Teams app by pasting the Microsoft App ID into the chat To: field (obviously it's not recommended to share this ID for general testing).完成此操作后,您可以在 Teams 中测试您的机器人,甚至无需创建 Teams 应用,只需将 Microsoft 应用 ID 粘贴到聊天收件人:字段(显然不建议共享此 ID 进行一般测试)。

The main change you probably need is to remove mentions.您可能需要的主要更改是删除提及。 These will mess with QnA Maker and/or LUIS as they are included in the query string.这些将与 QnA Maker 和/或 LUIS 混淆,因为它们包含在查询字符串中。 I have been doing this as the first step in the onMessage handler.我一直在做这个作为 onMessage 处理程序的第一步。 My current bots use regex for this, eg我目前的机器人为此使用正则表达式,例如

if (context._activity.text) ( // Make sure there is activity text before trying to replace
    context._activity.text = context._activity.text.replace(/(@|<at>)((Bot Name)|(Teams App Manifest Name))(<\/at>)? ?/g, '');
}

However, I have also seen that the TurnContext object can do this via TurnContext.removeRecipientMention(context.activity);但是,我也看到 TurnContext object 可以通过TurnContext.removeRecipientMention(context.activity); I've not actually tried that myself, though.不过,我自己并没有真正尝试过。 If it works it would be very helpful in case you find yourself changing bot names as I have done in the past...如果它有效,如果您发现自己像我过去所做的那样更改机器人名称,那将非常有帮助......

The other main change I made to my bots was creating Teams-specific adaptive cards with menu buttons.我对我的机器人所做的另一个主要更改是创建带有菜单按钮的团队特定的自适应卡片。 By default, Action.Submit will work for web channels but NOT Teams channel.默认情况下, Action.Submit将适用于 web 频道,但不适用于 Teams 频道。 A typical action would look like一个典型的动作看起来像

{
    "type": "ActionSet",
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Get Order Status",
            "data": "Get Order Status"
        }
    ]
}

But Teams can't handle this and will error out on button click (at least when using standard Activity handler, not sure if it is the same if using TeamsActivityHandler .) Instead, you should check the channel before displaying cards with Action.Submit actions and display an alternative card instead.但是 Teams 无法处理此问题,并且会在单击按钮时出错(至少在使用标准 Activity 处理程序时,不确定使用TeamsActivityHandler是否相同。)相反,您应该在使用Action.Submit操作显示卡片之前检查通道并显示替代卡。 For example例如

if (context.activity.channelId == 'msteams') {
    var welcomeCard = CardHelper.GetMenuCardTeams(welcomeMessage,'Y','Y');
} else {
    var welcomeCard = CardHelper.GetMenuCard(welcomeMessage,'Y','Y');
}

And then your actions for Teams instead look like然后你对 Teams 的操作看起来像

{
    "type": "ActionSet",
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Get Order Status",
            "data": {
                "msteams": {
                    "type": "imBack",
                    "value": "Get Order Status"
                }
            }
        }
    ]
}

I've tried combining these and it doesn't work well.我已经尝试将这些结合起来,但效果不佳。 You can add something to your handler to make Teams cards work in web, but the text will not be inserted into the chat like a typical button and it will instead be essentially like a backchannel event.您可以向处理程序添加一些内容,以使 Teams 卡在 web 中工作,但文本不会像典型按钮那样插入到聊天中,而是本质上类似于反向通道事件。 I like this method much better.我更喜欢这种方法。

Other than that you should be able to run your bot as-is, except for attachments as noted in your separate question .除此之外,您应该能够按原样运行您的机器人,但您的单独问题中提到的附件除外 I have not gotten that to work and I believe it may be related to not using TeamsActivityHandler but I'm not sure.我还没有让它工作,我相信这可能与不使用 TeamsActivityHandler 有关,但我不确定。

Hopefully this helps.希望这会有所帮助。 Go ahead and give it a try and you can create a new issue with any specific problems you face once the bot is operating in Teams. Go 提前尝试一下,一旦机器人在 Teams 中运行,您就可以针对遇到的任何特定问题创建一个新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM