As telegram. bot-based telegraf let through a proxy server?


write telegram bot through the library telegraf. Found a simple example in JS:
const telegraf = require('telegraf');
const SocksAgent = require('socks5-https-client/lib/Agent');
const socksAgent = new SocksAgent({
 socksHost: 'localhost',
 socksPort: 9050
const telegrammToken = 'token';
const bot = new telegraf(telegrammToken, {
 telegram: {
 agent: socksAgent
bot.start(ctx => ctx.reply('Welcome')); => ctx.reply('Send me a sticker'));
bot.on('sticker', ctx => ctx.reply("));
bot.hears('hi', ctx => ctx.reply('Hey there'));

It works.

But I write to TypeScript and trying to rewrite:
import SocksProxyAgent from 'socks-proxy-agent/dist/agent';
import { Telegraph } from 'telegraf';
import { telegramToken } from './config/botConfig';
const socksAgent = new SocksProxyAgent({
 host: 'localhost',
 port: 9050
const bot = new Telegraf(telegramToken, {
 telegram: {
 agent: socksAgent

at first swore that no types.
declared (as able)
declare module 'socks5-https-client/lib/Agent' {
 import * as tls from 'tls';
 import * as https from 'https';

 interface https extends IAgentOptions.AgentOptions, tls.ConnectionOptions {
 rejectUnauthorized?: boolean;
 maxCachedSessions?: number;

 // eslint-disable-next-line @typescript eslint no-unused-vars
 class Agent extends https.Agent {
 constructor(options?: IAgentOptions);
 options: IAgentOptions;
 private createConnection(options: {}): any;

and now on the line
const bot = new Telegraf(telegramToken, {
 telegram: {
 agent: socksAgent

No overload matches this call.

tell me what's wrong ...
maybe someone wrote a bot to TypeScript and Telegraf using proxies.

Thank you
April 7th 20 at 15:46
1 answer
April 7th 20 at 15:48
Most likely, because of the import destructurization (or whatever the {} hell that is). Try import instead of import Telegraph {Telegraph}
thanks for the direction )
const Telegraf = require('telegraf'); - willy_Reynol commented on April 7th 20 at 15:51

Find more questions by tags TelegramTypeScript