如何根据需要放置建议动作按钮

时间:2019-07-17 00:23:35

标签: c# botframework

你好,我是初学者。

我想在多行的两列中显示所建议的操作按钮。 (例如2列3行)我只知道如何在一行中显示它。如果可以的话,请教我。

谢谢

下面是代码示例。

welcomeActivity.SuggestedActions = new SuggestedActions()
{
    Actions = new List<CardAction>()
    {
        new CardAction(){ Title = Common.SomeResource1, Type=ActionTypes.ImBack, Value= Common.SomeResource1},
        new CardAction(){ Title = Common.SomeResource2, Type=ActionTypes.ImBack, Value= Common.SomeResource2},
        new CardAction(){ Title = Common.SomeResource3, Type=ActionTypes.ImBack, Value= Common.SomeResource3},
        new CardAction(){ Title = Common.SomeResource4, Type=ActionTypes.ImBack, Value= Common.SomeResource4},
        new CardAction(){ Title = Common.SomeResource5, Type=ActionTypes.ImBack, Value= Common.SomeResource5},
        new CardAction(){ Title = Common.SomeResource6, Type=ActionTypes.ImBack, Value= Common.SomeResource6},
    }
};

1 个答案:

答案 0 :(得分:0)

根据我的经验,“建议的操作”在Webchat频道中效果不佳,因为我无法将建议移动到聊天框(聊天框)中。明确地说,我使用的是Bot Framework v4。

我使用的替代方法是HeroCard,可以在多个渠道中正常工作。我已经实施了这样的建议:

var card = new HeroCard()
{
    Text = "Would you like me to help you?",
    Buttons = new List<CardAction>()
    {
       new CardAction(){ Title = "Yes", Type = ActionTypes.ImBack, Value = "Yes" },
       new CardAction(){ Title = "No", Type = ActionTypes.ImBack, Value = "No" },
    }
}; 

//To display the HeroCard, you need to send it as PromptOptions like this.
return await stepContext.PromptAsync("dialogName",
            new PromptOptions
            {
                Choices = ChoiceFactory.ToChoices(new List<string> { "Yes", "No" }),
                Prompt = (Activity)MessageFactory.Attachment(card.ToAttachment()),                             
            }, cancellationToken);