我想在这个repo的帮助下使用 typescript 创建一个简单的电报机器人。我需要设置一个代理,使用以下代码:
const bot = new TelegramBot(config.bot.token, {
polling: true,
request: {
agentClass: Agent,
agentOptions: {
socksHost: config.proxy.socksHost,
socksPort: config.proxy.socksPort,
// If authorization is needed:
socksUsername: config.proxy.socksUsername,
socksPassword: config.proxy.socksPassword
}
}
});
但得到一个编译时错误,上面写着:
Object literal may only specify known properties, and 'socksHost' does not exist in type 'AgentOptions | AgentOptions'
我阅读了其他相关问题,但似乎缺少类型定义。然后用了这个:
const bot = new TelegramBot(this._token, {
polling: true,
request: {
url: "api.telegram.org",
proxy: "127.0.0.1:1234",
},
});
当我运行它时,会出现此错误...
code:"EFATAL"
message:"EFATAL: Error: tunneling socket could not be established, cause=connect EINVAL 0.0.4.210:80 - Local (0.0.0.0:0)"
stack:"RequestError: Error: tunneling socket could not be established, cause=connect EINVAL 0.0.4.210:80 - Local (0.0.0.0:0)
谁能建议我如何使用打字稿设置代理?