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

如何使用Visual Studio的Enterprise Bot Template创建机器人?求教程

Hey there, I’ve put together a step-by-step guide to building a bot using Visual Studio’s Enterprise Bot Template while avoiding the Bot Framework cloud services your company restricts. Let’s dive in:

Prerequisites First
  • Make sure you have Visual Studio 2022 (2019 works too, but 2022 is more stable) installed with the .NET Desktop Development and AI Development workloads.
  • Install the Enterprise Bot Template: Open VS, go to Extensions > Manage Extensions, search for "Enterprise Bot Template" in the marketplace, download it, restart VS once installed.

1. Create Your Enterprise Bot Project

  • Fire up Visual Studio and click Create a new project.
  • Search for "Enterprise Bot" in the project template search bar, select the matching result.
  • Name your project, pick a save location, and hit Create. The template will generate a full solution with separate projects for bot logic, dialogs, models, etc.—this is the core enterprise bot structure.

2. Tweak the Bot Logic for Local Use

The template uses the Bot Framework SDK by default, but we can adjust it to run entirely locally without cloud dependencies:

  • Open the Bot project’s Bot.cs file—this is where your bot handles interactions.
  • Modify the OnMessageActivityAsync method to handle local input/output. For example, a simple response setup:
    protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        var userInput = turnContext.Activity.Text;
        var botResponse = $"Got it, you said: {userInput} | This is your local enterprise bot speaking!";
        await turnContext.SendActivityAsync(MessageFactory.Text(botResponse), cancellationToken);
    }
    
  • Use the template’s built-in dialog system under the Dialogs project to add custom flows (like greeting dialogs or help menus) by extending the ComponentDialog class.

3. Set Up a Local Testing Host

To test the bot without cloud channels, we’ll build a simple console host:

  • Add a new Console App project to your solution.
  • Reference your main Bot project in the console app, then install only the local-focused Bot Framework SDK NuGet packages (skip any Azure-specific ones like Microsoft.Bot.Builder.Azure).
  • Add this code to the console app’s Program.cs to simulate user interactions:
    static async Task Main(string[] args)
    {
        var yourBot = new YourBotNameBot(); // Replace with your bot class name
        var adapter = new ConsoleAdapter();
    
        Console.WriteLine("Local Enterprise Bot is running! Type a message to start:");
        await adapter.ProcessAsync(async (context, token) =>
        {
            await yourBot.OnTurnAsync(context, token);
        }, cancellationToken: CancellationToken.None);
    }
    
  • Run the console project, type messages directly into the console, and your bot will respond locally.

4. Add Enterprise-Grade Features (Locally)

  • Intent Recognition: Use Microsoft.Recognizers.Text (included in the template) to handle user intents locally instead of cloud-based LUIS.
  • State Management: Swap out Azure storage for local MemoryStorage in the Bot project’s Startup.cs:
    services.AddSingleton<IStorage, MemoryStorage>();
    services.AddSingleton<UserState>();
    services.AddSingleton<ConversationState>();
    
  • Multi-Step Dialogs: Use the template’s WaterfallDialog to build complex flows (like user onboarding forms) that run entirely on your local machine.

Quick Compliance Check

Double-check your project to remove any references to Bot Framework cloud services (like LUIS, QnA Maker, or Azure storage) to stay aligned with your company’s rules. All logic runs locally, so no external cloud deployments are needed.

内容的提问来源于stack exchange,提问作者Raudel CostaLaHoz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 07:26:58