如何将基本 HTML 文件部署到 Azure Bot 函数应用程序的根目录?

How do you deploy a basic HTML file to the root directory of an Azure Bot function app?

我从 LUIS 模板在 Azure 中创建了一个 Bot App Service 并配置了持续集成。 Bot Service 是一个函数应用程序,在本地和 web-windows 在 Azure 和 dev.botframework.com 上工作。

我的目标是将基本 HTML 页面部署到我的应用程序服务的根目录 BOT_NAME.azurewebsites.net

当前尝试解决:

我已经配置了网络聊天并且有一个 I-Frame:

<iframe src='https://webchat.botframework.com/embed/<BOT_NAME>?s=<SECRET>'></iframe>

我试图用以下内容修改 run.csx 文件:

var response = req.CreateResponse(HttpStatusCode.OK);
var stream = new FileStream(@"index.html", FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
return req.CreateResponse(HttpStatusCode.Accepted);

这会在 localhost:3979/api/messages 处正确显示 index.html。部署到 Azure 时,我试图将 index.html 完全限定为 d:\home\site\wwwroot\index.html,但 <BOT_NAME>.azurewebsites.com/api/messages returns 以下内容:

The HTTP 'GET' method is not supported by the 'GenericJsonWebHookReceiver' WebHook receiver

我创建了一个新的功能应用程序(不是机器人应用程序)以启动基础 HTML 文件并利用 Azure 的网络代理功能映射URL \wwwroot\index.html\。这可行,但它将应用程序隔离到两个存储库中,因此感觉不合实际。

我也曾尝试修改 function.json 以包含 "authLevel": "anonymous" 但无济于事。

请帮忙!我真的很感激,因为我不知道实施这种解决方案的最佳做法。在 Azure 中,所有 现成的 Bot 模板现在都是函数应用程序,因此任何希望启动 HTML bot 页面的人都可能需要详细信息。谢谢!

示例解决方案包含以下内容:

你是对的,机器人服务 UI 没有公开 Azure Function Proxies 部分。但是,您仍然可以使用它,因为 Bot Service 仍然是一个功能应用程序。

您可以执行以下操作。

启用函数代理

要启用功能代理,请将以下内容添加到功能应用程序的应用程序设置中。

ROUTING_EXTENSION_VERSION ~0.2

您可以通过机器人服务 > 设置 > 应用程序设置 > 应用程序设置访问该选项卡

添加Index.html

在 wwwroot/index.html

添加带有机器人 iframe 的 index.html

添加新函数以公开 index.html

创建一个新的 HTTP 触发器函数,读取 index.html 和 returns 作为 http 响应。 Directory structure

Function.json

{
 "bindings": [
    {
      "authLevel": "anonymous",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}

run.csx

using System.Net;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.IO;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    var response = new HttpResponseMessage(HttpStatusCode.OK);
    var stream = new FileStream(@"d:\home\site\wwwroot\index.html", FileMode.Open);
    response.Content = new StreamContent(stream);
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
    return response;
}

添加proxies.json

最后添加一个代理,让函数 app 的根目录指向新函数。

{
    "proxies":{
        "home":{
            "matchCondition": {
                "route": "/"
            },
            "backendUri": "https://<<FUNCTION_APP_NAME>>.azurewebsites.net/api/home"
        }
    }
}

请注意,我使用应用服务编辑器添加了函数应用程序和代理文件。您可以在机器人服务 > 设置 > 高级设置 > 开发工具 > 应用服务编辑器中找到它。