You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Bot Framework SDK V4(C#)Web Chat中显示长文本选项为按钮?

Fix: Keep Spaced Long Text Options as Buttons in Web Chat

I've run into this exact issue before! The problem is that Web Chat automatically switches between button and list rendering based on option text length and spacing. But we can force it to always use buttons—here's how to do it step by step, depending on how you're embedding Web Chat:

Option 1: Custom Web Chat Embedding (Your Own Website)

If you've added Web Chat to your custom HTML/JS page:

  1. Locate your Web Chat initialization code. It'll look something like this:

    <div id="webchat" role="main"></div>
    <script>
        window.WebChat.renderWebChat({
            directLine: window.WebChat.createDirectLine({ token: 'YOUR_DIRECT_LINE_TOKEN' })
        }, document.getElementById('webchat'));
    </script>
    
  2. Add the styleOptions parameter to force button rendering:
    Modify the code to include this configuration:

    window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({ token: 'YOUR_DIRECT_LINE_TOKEN' }),
        styleOptions: {
            // This forces all choice prompts to render as buttons, no matter the text length
            choiceRendering: 'button'
        }
    }, document.getElementById('webchat'));
    
  3. Save and refresh your page—your long, spaced options will now show as buttons instead of lists.

Option 2: Azure Portal Web Chat Iframe

If you're using the default iframe embed code from Azure Portal:

  1. Take your existing iframe code (it looks like this):

    <iframe src="https://webchat.botframework.com/embed/YOUR_BOT_ID?s=YOUR_SECRET_KEY" />
    
  2. Append the URL-encoded style option to the src attribute:
    Add &styleOptions=%7B%22choiceRendering%22%3A%22button%22%7D to the end of the URL. Your updated code will be:

    <iframe src="https://webchat.botframework.com/embed/YOUR_BOT_ID?s=YOUR_SECRET_KEY&styleOptions=%7B%22choiceRendering%22%3A%22button%22%7D" />
    
  3. Replace YOUR_BOT_ID and YOUR_SECRET_KEY with your actual values, then embed this updated iframe—your options will now render as buttons.

Bonus: Bot Code Adjustment (Optional)

While the front-end fix is the most reliable, you can also set the prompt style in your C# code to hint that you want buttons. This works best combined with the front-end setting:

return await stepContext.PromptAsync(
    "choicePrompt",
    new PromptOptions
    {
        Prompt = stepContext.Context.Activity.CreateReply("Based on the access privileges assigned to you by your admin, below are the options you can avail. Please click/choose any one from the following: "),
        Choices = new[] {
            new Choice { Value = "Show My VMs" },
            new Choice { Value = "Show VMs Status" },
            new Choice { Value = "Start VM" },
            new Choice { Value = "Stop VM" },
            new Choice { Value = "Request Model/License" },
            new Choice { Value = "Request For New VM" },
            new Choice { Value = "Extend My Existing VM" },
            new Choice { Value = "Logout" },
            new Choice { Value = "Help" }
        }.ToList(),
        RetryPrompt = stepContext.Context.Activity.CreateReply("Sorry, I did not understand that. Please choose any one from the options displayed below: "),
        // Explicitly request button style for the prompt
        Style = ListStyle.Button
    });

This tells the Bot Framework you prefer buttons, but Web Chat's front-end configuration will override any automatic switching behavior, so combining both ensures consistency.

内容的提问来源于stack exchange,提问作者Chaitanya N G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 17:29:11