【问题标题】:Issue with List of buttons in Microsoft Bot Builder for .NET - Channel: Facebook MessengerMicrosoft Bot Builder for .NET 中的按钮列表问题 - 频道:Facebook Messenger
【发布时间】:2017-06-23 08:15:56
【问题描述】:

我正在尝试在 herocard 中添加按钮列表。它在 Bot Emulator 中运行良好,但在 Messenger Channel 中不起作用。这是我的代码。

public static IList<Attachment> ToAttachmentList(this List<string> items)
{
        var attachments = new List<Attachment>();
        var actions = new List<CardAction>();

        foreach (var item in items)
        {
            actions.Add(new CardAction(ActionTypes.ImBack, title: item, value: item));
        }

        var heroCard = new HeroCard
        {
            Buttons = actions
        };

        attachments.Add(heroCard.ToAttachment());

        return attachments;
}

private async Task ShowOptions(IDialogContext context)
{
        var reply = context.MakeMessage();
        reply.Text = $"Here's what you can do.";
        reply.AttachmentLayout = AttachmentLayoutTypes.List;
        reply.Attachments = Messages.OrderingOptions.ToAttachmentList();

        await context.PostAsync(reply);
}

在 Messenger 中,最后一个按钮被添加为轮播,所有按钮文本都被截断。

请帮我解决这个问题。

【问题讨论】:

    标签: c# bots botframework facebook-messenger-bot


    【解决方案1】:

    根据documentation,按钮标题有 20 个字符的限制。

    此外,如果您有超过 3 个按钮,Facebook 会将它们拆分为 Button template 期望的 1-3 个按钮。

    您需要将字符限制为 20 个,因此您可能希望使用 “Order Pizza” 来代替 “我想订购披萨”。添加更多按钮;您可能想探索Quick Replies,因为限制是 11 个“按钮”(但标题仍然有 20 个字符的限制)。您可以查看其他post 以了解有关快速回复的更多信息。

    【讨论】:

    • 有没有什么办法可以添加4个动作,也可以添加和文本一样的句子???
    • 您需要将字符限制为 20 个,因此我不想订购披萨,只需使用“订购披萨”即可。添加更多按钮;您可能想探索快速回复 (developers.facebook.com/docs/messenger-platform/…)。限制为 11(但标题仍有 20 个字符的限制)。您可以查看stackoverflow.com/questions/40230436/…。请投票并设置为已回答
    • 赞成,因为@EzequielJadib 的这个有效答案没有理由得到负分
    猜你喜欢
    • 2016-08-28
    • 2017-02-05
    • 2017-06-07
    • 2018-08-31
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 2018-05-12
    相关资源
    最近更新 更多