Botframework 在Bot框架Web聊天中,如何连接到我的Bot服务器?

Botframework 在Bot框架Web聊天中,如何连接到我的Bot服务器?,botframework,Botframework,所有教程都连接到direct line,那么使用我自己的bot服务器怎么样?如何在javascript中连接 我已经安装了服务器端: // Setup BotFramework var connector = new Builder.ChatConnector({ appId: "a8...", appPassword: "ko...", openIdMetadata: process.env.BotOpenIdMetadata }); // Setup Bot v

所有教程都连接到direct line,那么使用我自己的bot服务器怎么样?如何在javascript中连接

我已经安装了服务器端:

// Setup BotFramework
var connector = new Builder.ChatConnector({

    appId: "a8...",
    appPassword: "ko...",
    openIdMetadata: process.env.BotOpenIdMetadata

});

// Setup Bot
var bot = new Builder.UniversalBot(connector);
bot.set('storage', new Builder.MemoryBotStorage());
// Setup Server
var server = Restify.createServer();

server.listen(process.env.port || process.env.PORT || 4000, function () {
    console.log("Listening on port "+(process.env.port || process.env.PORT || 4000));
});
server.post('/api/messages', connector.listen());
在客户端,以下是我目前使用direct line获得的信息:

<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>

<script src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>

<script>
    const params = BotChat.queryParams(location.search);

    const speechOptions = {
        speechRecognizer: new BotChat.Speech.BrowserSpeechRecognizer(),
        speechSynthesizer: new BotChat.Speech.BrowserSpeechSynthesizer()
    };


    BotChat.App({
        showUploadButton: false,
        directLine: { secret: '_bm...' },
        bot: { id: 'a8...' },
        locale: params['locale'],
        resize: 'detect',
        speechOptions: speechOptions,
        user: {
            id: 'WebChatDemoUser',
            name: 'You'
        },
    }, document.getElementById('ChatBot'));
    var header = document.getElementsByClassName("wc-header");
    header[0].innerHTML = "<span>Chat</span>"
</script>
或者在生产过程中是这样的:

http://localhost:4000/api/messages
http://myserver.com:4000/api/messages
基本上,与Bot Emulator的连接方式类似:


默认情况下,DirectLineJs将调用直连连接器服务。然后,连接器服务调用您的bot,bot将通过响应(或主动消息)回调连接器服务DirectLineJs确实提供了一个域参数,您可以提供该参数来覆盖默认值:

const dl = new DirectLine({
    secret: /* put your Direct Line secret here */,
    token: /* or put your Direct Line token here (supply secret OR token, not both) */,
    domain: /* optional: if you are not using the default Direct Line endpoint, e.g. if you are using a region-specific endpoint, put its full URL here */
    webSocket: /* optional: false if you want to use polling GET to receive messages. Defaults to true (use WebSocket). */,
    pollingInterval: /* optional: set polling interval in milliseconds. Default to 1000 */,
});
但是,托管您自己的直连连接器服务涉及的内容要多得多。SDK代码将使用活动的serviceUrl属性将消息发送回连接器服务。bot需要端点,如此控制器中的端点:

更多详细信息将在这篇负载测试博客文章中解释:

还有一个有限的节点示例: