0

如何在 Azure 机器人服务中启用 websocket 选项?应用程序服务应用程序设置中有一个 websocket 选项可用,但在机器人服务中缺少它。

我正在运行一个带有示例模板并添加了 websocket 的 nodejs 机器人。

"use strict";
var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure");
var path = require('path');
var useEmulator = (process.env.NODE_ENV == 'development');
var WebSocket = require('ws');
var wss = new WebSocket.Server({ port: process.env.PORT || 8080 });

var connector = useEmulator ? new builder.ChatConnector() : new botbuilder_azure.BotServiceConnector({
    appId: process.env['MicrosoftAppId'],
    appPassword: process.env['MicrosoftAppPassword'],
    stateEndpoint: process.env['BotStateEndpoint'],
    openIdMetadata: process.env['BotOpenIdMetadata']
});

var bot = new builder.UniversalBot(connector);
bot.localePath(path.join(__dirname, './locale'));

bot.dialog('/', function (session) {
    session.send('You said ' + session.message.text);
});

if (useEmulator) {
    var restify = require('restify');
    var server = restify.createServer();
    server.listen(3978, function() {
        console.log('test bot endpont at http://localhost:3978/api/messages');
    });
    server.post('/api/messages', connector.listen());    
} else {
    module.exports = { default: connector.listen() }
}

这是客户端代码

var ws = new WebSocket('ws://localhost:8080');
ws.onopen = function() {
   console.log('connected');
};
ws.onclose = function() {
   console.log('disconnected');
};
ws.send('test message from websocket client')

这在本地模拟器中运行良好,但是当我尝试连接天蓝色服务器时收到 503 响应代码

var ws = new WebSocket('ws://mybotname.azurewebsites.net');

我也尝试使用端口 8080,然后出现连接超时错误。

4

0 回答 0