Answer the question
In order to leave comments, you need to log in
How to release a telegraf-based telegram bot through a proxy server?
Hello!
I am writing a telegram bot using the telegraf library. I found a simple JS example:
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'));
bot.help(ctx => ctx.reply('Send me a sticker'));
bot.on('sticker', ctx => ctx.reply(''));
bot.hears('hi', ctx => ctx.reply('Hey there'));
bot.launch();
import SocksProxyAgent from 'socks-proxy-agent/dist/agent';
import { Telegraf } from 'telegraf';
import { telegramToken } from './config/botConfig';
const socksAgent = new SocksProxyAgent({
host: 'localhost',
port: 9050
});
const bot = new Telegraf(telegramToken, {
telegram: {
agent: socksAgent
}
});
...
declare module 'socks5-https-client/lib/Agent' {
import * as tls from 'tls';
import * as https from 'https';
interface IAgentOptions extends https.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;
}
}
const bot = new Telegraf(telegramToken, {
telegram: {
agent: socksAgent
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question