Node.js 网络错误:错误:连接ETIMEDOUT 149.154.167.220:443

Node.js 网络错误:错误:连接ETIMEDOUT 149.154.167.220:443,node.js,telegram-bot,Node.js,Telegram Bot,我在server.js文件中有以下代码块: const Telegram = require('telegram-node-bot') const tg = new Telegram.Telegram('***********token**************',{ workers:1 }); const pingController = require('./controllers/ping') ,otherwiseController = require('./con

我在server.js文件中有以下代码块:

const Telegram = require('telegram-node-bot')

const tg = new Telegram.Telegram('***********token**************',{
    workers:1
});

const pingController = require('./controllers/ping')
    ,otherwiseController = require('./controllers/otherwise')

tg.router.when(new Telegram.TextCommand('/ping','pingCommand'), new pingController())
    .otherwise(new otherwiseController());
ping.js文件中的代码块:

const Telegram = require('telegram-node-bot');
class pingController extends Telegram.TelegramBaseController{
    pingHandler($){
        $.sendMessage('pong');
    }

    get routes() {
        return{
            'pingCommand': 'pingHandler'
        };
    }
}

module.exports = pingController;
最后,此代码块位于文件中:

const Telegram = require('telegram-node-bot');
class otherwiseController extends Telegram.TelegramBaseController{
    handler($){
        $.sendMessage('Sorry!!!')
}
}

module.exports = otherwiseController;
当我运行node server.js时,我得到如下错误: [错误]

网络错误:错误:连接ETIMEDOUT 149.154.167.220:443 at Object.\u errnoException(util.js:1031:13) at_例外WithHostPort(util.js:1052:20) 在TCPConnectWrap.afterConnect[as oncomplete](net.js:1195:14)请求电报APIRESQUEST{u方法:“setWebhook”,参数:{ url:''},\u多部分:未定义}


而且,电报在我国是经过过滤的!!!,我使用虹吸3代理。

这是因为您没有为终端/cmd设置代理

对于Linux:

export http_proxy='http://proxyserveraddress:3128'    
export https_proxy='https://proxyserveraddress:3128'
对于Wndows:

set HTTP_PROXY=http://proxyserveraddress:3128    
set HTTPS_PROXY=https://proxyserveraddress:3128

您可以将SOCKS5代理与库一起使用。例如:

const TelegramBot = require('node-telegram-bot-api')
const Agent = require('socks5-https-client/lib/Agent')

const bot = new TelegramBot(process.env.TELEGRAM_API_TOKEN, {
    polling: true,
    request: {
        agentClass: Agent,
        agentOptions: {
            socksHost: process.env.PROXY_SOCKS5_HOST,
            socksPort: parseInt(process.env.PROXY_SOCKS5_PORT),
            // If authorization is needed:
            // socksUsername: process.env.PROXY_SOCKS5_USERNAME,
            // socksPassword: process.env.PROXY_SOCKS5_PASSWORD
        }
    }
})
这个解决方案可以继续在您的本地PC上开发机器人(没有代理,您无法从伊朗和俄罗斯启动机器人),并且可以正常工作