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

无需微软注册能否使用BotFramework WebChat与BotFramework模拟器?

Can I use Bot Framework Web Chat (HTML/JS) and the Bot Framework Emulator without registering on dev.botframework.com?

Absolutely! You don’t need to sign up for the Bot Framework portal to use Web Chat alongside the Emulator for local testing. Here’s a straightforward breakdown to make this work:

1. Run a local Bot instance

First, you’ll need a Bot running on your machine. You can use the Bot Framework SDK (for C#, JavaScript, Python, etc.) to build a simple Bot, or start with one of the official sample Bots. For example, with a JavaScript Bot:

  • Initialize a new project with npm init
  • Install core dependencies like botbuilder
  • Write a basic Echo Bot that sends back user messages
  • Start the Bot – it’ll typically run on http://localhost:3978/api/messages by default

2. Connect the Bot Framework Emulator

Open the Emulator and link it to your local Bot:

  • Enter the Bot’s endpoint URL: http://localhost:3978/api/messages
  • Leave the "Microsoft App ID" and "Microsoft App Password" fields blank (since we’re working entirely locally)
  • Click "Connect" – the Emulator should immediately start chatting with your Bot.

3. Set up Web Chat to talk to your local Bot

To get Web Chat working with your local Bot, you need two key steps:

a. Enable CORS on your Bot

Since Web Chat runs in a browser, your local Bot needs to allow cross-origin requests. For a JavaScript Bot, add CORS middleware using the cors package:

const cors = require('cors');
// Add this to your Bot's startup code before defining routes
server.use(cors({ origin: '*' }));

For a .NET Bot, configure CORS in Startup.cs:

using Microsoft.AspNetCore.Cors;

public void ConfigureServices(IServiceCollection services)
{
    services.AddCors(options =>
    {
        options.AddPolicy("AllowAll", policy =>
        {
            policy.AllowAnyOrigin()
                  .AllowAnyMethod()
                  .AllowAnyHeader();
        });
    });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseCors("AllowAll");
    // ... other middleware configurations
}

b. Minimal Web Chat HTML/JS example

Use the official Web Chat library to connect directly to your local Bot’s Direct Line endpoint. Here’s a working sample:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Local Bot Web Chat</title>
    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
        body { margin: 0; height: 100vh; }
        #webchat { height: 100%; width: 100%; }
    </style>
</head>
<body>
    <div id="webchat" role="main"></div>
    <script>
        // Create a Direct Line connection to your local Bot
        const directLine = window.WebChat.createDirectLine({
            domain: 'http://localhost:3978/v3/directline',
            // For local testing, you can use a temporary token (generate via Bot Framework CLI) or enable anonymous access
            token: 'YOUR_LOCAL_DIRECT_LINE_TOKEN'
        });

        // Render the Web Chat interface
        window.WebChat.renderWebChat(
            {
                directLine: directLine,
                userID: 'local-webchat-user',
                username: 'Web Chat User'
            },
            document.getElementById('webchat')
        );
    </script>
</body>
</html>

Note: If you haven’t set up a Direct Line secret for your local Bot, you can enable temporary anonymous access for testing, or generate a token using the Bot Framework CLI tool.

Quick reminders

  • This setup is ideal for local development and testing – you can iterate on your Bot and Web Chat UI without deploying to the cloud or registering on the portal.
  • When you’re ready to make your Bot public, you’ll need to register it on the Bot Framework portal to get official Direct Line credentials and enable external access.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:00:26