Reputation: 590
Trying to make my first telegram bot, in all examples and instructions it looks very simple and easy to repeat. However, my bot doesn't work at all. Firstly, I am from Russia and telegram api is blocked, so I need to use proxy. Took one from https://www.socks-proxy.net/. Got token from BotFather. Now when I run my script telegraf.js
:
const Telegraf = require('telegraf');
const SocksAgent = require('socks5-https-client/lib/Agent');
const socksAgent = new SocksAgent({
socksHost: '103.206.97.70',
socksPort: 4145,
});
const bot = new Telegraf(MY_TOKEN, {
telegram: {
agent: socksAgent,
}
});
bot.hears('hi', ctx => {
return ctx.reply('Hey!');
});
bot.startPolling();
nothing happens and program finished.
I understand that problem is in my proxy configuration, but can't understand what exactly wrong.
Upvotes: 1
Views: 733
Reputation: 1
const { Telegraf } = require('telegraf')
const { SocksProxyAgent } = require('socks-proxy-agent');
const bot = new Telegraf('YOUR BOT API', {
telegram: {
agent: new SocksProxyAgent('socks5h://127.0.0.1:9050')
},
});
bot.hears('hi', ctx => {
return ctx.reply("HEY!");
});
bot.startPolling();
Upvotes: 0
Reputation: 590
The problem was in proxy. I used https-proxy-agent
instead of socks5-https-client
import Telegraf from 'telegraf';
import config from 'config';
import HttpsProxyAgent from 'https-proxy-agent';
const TOKEN = config.get('token');
const proxy = config.get('proxy');
const bot = new Telegraf(TOKEN, {
telegram: {
agent: new HttpsProxyAgent({
host: proxy.host,
port: proxy.port
})
},
});
bot.hears('hi', ctx => {
return ctx.reply('Hey!');
});
bot.startPolling();
Upvotes: 1