建议的操作在 Microsoft Teams 中不可见

Suggested Actions not visible in Microsoft Teams

我将从机器人向 Microsoft Teams 发送一条主动消息,其中包含用户可以执行的 2 个建议操作。但在 Microsoft Teams 中,消息显示如下:

请注意,该消息未显示任何建议消息!在 Bot Framework Emulator 中,相同的消息如下所示:

Teams 或我的代码有什么问题?

下面是我用于验证、生成和发送消息的代码:

private async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken)
{
    string serviceUrl = turnContext.Activity.RelatesTo.ServiceUrl;

    ConnectorClient Connector = new ConnectorClient(
        new Uri(serviceUrl),
        microsoftAppId: "[MicrosoftAppId]",
        microsoftAppPassword: "[MicrosoftAppPassword]"
    );

    AppCredentials.TrustServiceUrl(serviceUrl);
    ChannelAccount from = turnContext.Activity.From;
    IMessageActivity activity = MessageFactory.SuggestedActions(
        new string[] { "First action", "Second action" },
        $"Hi {userName},\r\nYou've missed some lorem ipsum dolor sit amet:\r\n- **consectetur:** Ut porttitor\r\nChoose an action from below to add them."
    );

    await Connector.Conversations.SendToConversationAsync(
        turnContext.Activity.Conversation.Id, 
        activity as Activity, 
        cancellationToken
    );
}

团队不支持建议的操作。如果要显示按钮,可以在 Teams 中使用 Cards

与其他回复相呼应,但可能更详细一些。如前所述,在 Teams(和其他客户端)中执行此操作的方法是使用“Cards" - kind of like mini windows inside the chat. Teams supports a few different kinds of cards to suit different interactions, but the most prominent are called Adaptive Cards. You can play more with these at the designer here,App Studio 中甚至内置了 "designer" 体验(您甚至可以在其中使用 App Studio 的机器人 "send" 你看卡片在 "real" 对话中的样子。