0

I want to create a simple telegram robot using typescript with the help of this repo. I need set a proxy, used following code:

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
        }
    }
});

but got a compile-time error which says:

Object literal may only specify known properties, and 'socksHost' does not exist in type 'AgentOptions | AgentOptions'

I read other related issues but it seems there is a lack of type definitions. Then used this one:

const bot = new TelegramBot(this._token, {
     polling: true,
     request: {
       url: "api.telegram.org",
       proxy: "127.0.0.1:1234",
     },
});

When i run it, gives this error...

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)

Can anyone suggest me how to set a proxy with typescript?

mostafa8026
  • 273
  • 2
  • 12
  • 25

0 Answers0